Skip to content

Commit a7f7584

Browse files
author
whuber
committed
Sync with csc220summer19 repo
1 parent 5680fc5 commit a7f7584

21 files changed

Lines changed: 511 additions & 65 deletions

bash/bash1/example.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# Parameter 1 is a name, parameter 2 is a number
4+
5+
echo "Example\t\tshell\t\tscript"
6+
echo -e "Example\t\tshell\t\tscript"
7+
8+
# run command
9+
echo
10+
echo "Your files: "
11+
ls
12+
13+
# run a command inside a string
14+
echo "Date: `date`"
15+
16+
# run a different shell script
17+
./hello.sh $1
18+
19+
20+
ii=1
21+
while [ $ii -le $2 ]
22+
do
23+
echo $ii
24+
ii=$((ii+1))
25+
done

bash/bash1/hello.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# No space around = in an assignment
4+
greeting="Hello"
5+
person="World"
6+
7+
if [ $# -ne 0 ]
8+
then
9+
person=$1
10+
fi
11+
12+
if [ $person = "Wade" ]
13+
then
14+
echo "$greeting, professor"
15+
else
16+
echo "$greeting, $person"
17+
fi

bash/bash1/nd.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Create a new directory with a README file inside
4+
5+
if [ $# -eq 0 ]
6+
then
7+
echo "No directory name specified."
8+
else
9+
mkdir $1
10+
cd $1
11+
cat > README.TXT << EOL
12+
This directory was created automatically.
13+
Use it wisely!
14+
EOL
15+
16+
fi

bash/bash1/simple.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
echo "Files:"
2+
ls
3+
echo
4+
echo "Counts:"
5+
wc *
6+
echo "DATE: `date`"

bash/bash2/forloop.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
STOP=5
4+
5+
echo "Running a for loop"
6+
for ((ii=1;ii<$STOP;ii++))
7+
do
8+
echo $ii
9+
done
10+
11+
echo
12+
13+
echo "Files in the current directory"
14+
allfiles=(*)
15+
cfiles=(*.c)
16+
17+
echo $allfiles[0]
18+
echo ${allfiles[0]}
19+
echo ${allfiles[1]}
20+
echo
21+
22+
echo "List of C files"
23+
for cfile in ${cfiles[@]}
24+
do
25+
echo " $cfile"
26+
done
27+
echo "Number of C files = ${#cfiles[@]}"
28+
echo
29+
30+
echo "Loop over results of a command"
31+
cppfiles=($(find . -name "*.cpp"))
32+
for filename in ${cppfiles[@])}
33+
do
34+
echo " $filename"
35+
done
36+
37+
filetocheck=${cfiles[0]}
38+
wordtocheck=printf
39+
echo "Does $wordtocheck appear in $filetocheck?"
40+
if grep -q $wordtocheck $filetocheck
41+
then
42+
echo "$wordtocheck appears in $filetocheck"
43+
else
44+
echo "$wordtocheck does not appear in $filetocheck"
45+
fi

c/c6/structnamespace.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
#include<stdio.h>
22

3-
/* Create type "struct my_struct" */
3+
/* Create type struct my_struct */
44
struct my_struct {
55
int num;
66
char name[10];
77
};
88

9-
/* Create type "my_struct" */
9+
/* Create type my_struct */
1010
typedef struct {
1111
int count;
1212
float average;
1313
} my_struct;
1414

1515
int main () {
16-
1716
struct my_struct struct1 = {3, "my_struct"};
18-
my_struct struct2 = {2, 3.14};
17+
my_struct struct2 = {2, 1.234};
1918

20-
printf("num=%d, name=%s\n", struct1.num, struct1.name);
21-
printf("count=%d, average=%f\n", struct2.count, struct2.average);
19+
printf("struct mystruct: num=%d, name=%s\n", struct1.num, struct1.name);
20+
printf(" mystruct: count=%d, average=%s\n", struct2.count, struct2.average);
2221

2322
return 0;
24-
}
23+
}

cpp/cpp1/staff/employee.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include<iostream>
2+
#include"employee.hpp"
3+
4+
using namespace std;
5+
6+
void Employee::print() {
7+
StaffMember::print();
8+
cout << " SSN: " << ssn << endl;
9+
cout << " Pay rate: " << payrate << endl;
10+
}

cpp/cpp1/staff/employee.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Employee class
2+
#ifndef EMPLOYEE_HPP
3+
#define EMPLOYEE_HPP
4+
#include"staffmember.hpp"
5+
6+
class Employee : public StaffMember{
7+
private:
8+
std::string ssn;
9+
protected:
10+
int payrate;
11+
public :
12+
Employee(std::string n, std::string a, std::string p,
13+
std::string s, int r) :
14+
StaffMember(n, a, p)
15+
{
16+
ssn = s;
17+
payrate = r;
18+
}
19+
void print();
20+
};
21+
#endif

cpp/cpp1/staff/hourly.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include<iostream>
2+
#include"hourly.hpp"
3+
4+
int Hourly::pay() {
5+
return (payrate * hours);
6+
}

cpp/cpp1/staff/hourly.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Staff member - base class
2+
#ifndef HOURLY_HPP
3+
#define HOURLY_HPP
4+
#include"employee.hpp"
5+
6+
class Hourly : public Employee {
7+
private:
8+
int hours;
9+
public:
10+
Hourly(std::string n, std::string a, std::string p,
11+
std::string s, int r, int h) :
12+
Employee(n, a, p, s, r)
13+
{
14+
hours = h;
15+
}
16+
17+
int pay();
18+
};
19+
#endif

0 commit comments

Comments
 (0)