Browse Source

adding cs142 code

Derek McQuay 3 years ago
parent
commit
8e52ce1982
100 changed files with 10983 additions and 0 deletions
  1. 31
    0
      cs142/final/Makefile
  2. 14
    0
      cs142/final/administrator.cpp
  3. 15
    0
      cs142/final/administrator.h
  4. 263
    0
      cs142/final/campus.cpp
  5. 27
    0
      cs142/final/campus.h
  6. 35
    0
      cs142/final/employee.cpp
  7. 27
    0
      cs142/final/employee.h
  8. 32
    0
      cs142/final/faculty.cpp
  9. 19
    0
      cs142/final/faculty.h
  10. 19
    0
      cs142/final/hourly.cpp
  11. 15
    0
      cs142/final/hourly.h
  12. 48
    0
      cs142/final/main.cpp
  13. 13
    0
      cs142/final/salaried.cpp
  14. 15
    0
      cs142/final/salaried.h
  15. 46
    0
      cs142/final/tags
  16. 4
    0
      cs142/final/test.txt
  17. 46
    0
      cs142/final/util.cpp
  18. 14
    0
      cs142/final/util.h
  19. 6
    0
      cs142/lab00/Makefile
  20. 10
    0
      cs142/lab00/hello_world.cpp
  21. 17
    0
      cs142/lab01/byu.cpp
  22. 22
    0
      cs142/lab01/quiz.txt
  23. 10
    0
      cs142/lab02/Makefile
  24. 57
    0
      cs142/lab02/binary.cpp
  25. 20
    0
      cs142/lab02/temperature.cpp
  26. 30
    0
      cs142/lab02/timer.cpp
  27. 4
    0
      cs142/lab03/Makefile
  28. 13
    0
      cs142/lab03/class/main.cpp
  29. 60
    0
      cs142/lab03/class/person.cpp
  30. 24
    0
      cs142/lab03/class/person.h
  31. 304
    0
      cs142/lab03/grade.cpp
  32. 16
    0
      cs142/lab03/quick.cpp
  33. 59
    0
      cs142/lab03/test.txt
  34. 7
    0
      cs142/lab04/Makefile
  35. 53
    0
      cs142/lab04/loops.py
  36. 111
    0
      cs142/lab04/number.cpp
  37. 17
    0
      cs142/lab04/quick.cpp
  38. 10
    0
      cs142/lab05/Makefile
  39. 10
    0
      cs142/lab05/game/Makefile
  40. 18
    0
      cs142/lab05/game/game.cpp
  41. 175
    0
      cs142/lab05/game/monopoly.cpp
  42. 40
    0
      cs142/lab05/game/properties/properties_in_order.txt
  43. 182
    0
      cs142/lab05/monopoly.cpp
  44. 6
    0
      cs142/lab06/Makefile
  45. 211
    0
      cs142/lab06/add-display.cpp
  46. 42
    0
      cs142/lab06/array.cpp
  47. 10
    0
      cs142/lab06/test.txt
  48. 29
    0
      cs142/lab07/Makefile
  49. 250
    0
      cs142/lab07/cookies.cpp
  50. 18
    0
      cs142/lab07/test.txt
  51. 18
    0
      cs142/lab08/Makefile
  52. 106
    0
      cs142/lab08/main.cpp
  53. 47
    0
      cs142/lab08/person.cpp
  54. 24
    0
      cs142/lab08/person.h
  55. 43
    0
      cs142/lab08/test.cc
  56. 21
    0
      cs142/lab08/test.txt
  57. 29
    0
      cs142/lab09/Makefile
  58. 30
    0
      cs142/lab09/io.cpp
  59. 11
    0
      cs142/lab09/io.h
  60. 27
    0
      cs142/lab09/iotest.cpp
  61. 249
    0
      cs142/lab09/jsoncpp/json/json-forwards.h
  62. 1855
    0
      cs142/lab09/jsoncpp/json/json.h
  63. 4230
    0
      cs142/lab09/jsoncpp/jsoncpp.cpp
  64. 75
    0
      cs142/lab09/main.cpp
  65. 8
    0
      cs142/lab09/restaurant.cpp
  66. 16
    0
      cs142/lab09/restaurant.h
  67. 5
    0
      cs142/lab09/test.json
  68. 196
    0
      cs142/lab09/tournament.cpp
  69. 25
    0
      cs142/lab09/tournament.h
  70. 56
    0
      cs142/lab10/ArenaInterface.h
  71. 176
    0
      cs142/lab10/Battle.h
  72. 7
    0
      cs142/lab10/Factory.cpp
  73. 21
    0
      cs142/lab10/Factory.h
  74. 200
    0
      cs142/lab10/FighterInterface.h
  75. 33
    0
      cs142/lab10/Makefile
  76. 21
    0
      cs142/lab10/archer.cpp
  77. 21
    0
      cs142/lab10/archer.h
  78. 111
    0
      cs142/lab10/arena.cpp
  79. 23
    0
      cs142/lab10/arena.h
  80. 59
    0
      cs142/lab10/cleric.cpp
  81. 24
    0
      cs142/lab10/cleric.h
  82. 72
    0
      cs142/lab10/fighter.cpp
  83. 44
    0
      cs142/lab10/fighter.h
  84. 205
    0
      cs142/lab10/main.cpp
  85. 30
    0
      cs142/lab10/robot.cpp
  86. 23
    0
      cs142/lab10/robot.h
  87. 60
    0
      cs142/lab10/util.cpp
  88. 14
    0
      cs142/lab10/util.h
  89. 14
    0
      cs142/smcquay/cootie/Makefile
  90. 42
    0
      cs142/smcquay/cootie/cootie.cc
  91. 25
    0
      cs142/smcquay/cootie/dice.cc
  92. 8
    0
      cs142/smcquay/cootie/dice.h
  93. 67
    0
      cs142/smcquay/cootie/player.cc
  94. 24
    0
      cs142/smcquay/cootie/player.h
  95. 9
    0
      cs142/smcquay/fun_with_formatting/Makefile
  96. 34
    0
      cs142/smcquay/fun_with_formatting/main.cc
  97. 7
    0
      cs142/smcquay/go/lab00/Makefile
  98. 7
    0
      cs142/smcquay/go/lab00/hello.go
  99. 7
    0
      cs142/smcquay/go/lab01/Makefile
  100. 0
    0
      cs142/smcquay/go/lab01/trivia.go

+ 31
- 0
cs142/final/Makefile View File

@@ -0,0 +1,31 @@
1
+CXXFLAGS= -Wall -g
2
+OBJECTS=main.o employee.o hourly.o salaried.o administrator.o faculty.o util.o campus.o
3
+EXE=main
4
+
5
+all: $(EXE)
6
+
7
+
8
+$(EXE): main.o
9
+	$(CXX) $(CXXFLAGS) $(OBJECTS) -o $@
10
+
11
+main.o: main.cpp employee.o hourly.o salaried.o administrator.o faculty.o util.o campus.o
12
+employee.o: employee.h employee.cpp
13
+hourly.o: hourly.cpp hourly.h employee.h
14
+salaried.o: salaried.h salaried.cpp employee.h
15
+administrator.o: administrator.cpp administrator.h employee.h
16
+faculty.o: faculty.cpp faculty.h employee.h
17
+util.o: util.h util.cpp
18
+campus.o: campus.cpp campus.h
19
+
20
+run: $(EXE)
21
+	@./$(EXE)
22
+
23
+clean:
24
+	@rm -vf *.o
25
+	@rm -vf $(EXE)
26
+
27
+debug: $(EXE)
28
+	gdb ./$(EXE)
29
+
30
+valgrind: $(EXE)
31
+	valgrind --tool=memcheck --leak-check=yes ./$(EXE)

+ 14
- 0
cs142/final/administrator.cpp View File

@@ -0,0 +1,14 @@
1
+#include "administrator.h"
2
+#include "employee.h"
3
+
4
+using namespace std;
5
+
6
+administrator::administrator(string name, double pay_rate, int hours, string type) :
7
+     employee(name, pay_rate, hours, type) {}
8
+
9
+int administrator::get_salary() {
10
+    if(hours > 170) {
11
+        pay_rate += pay_rate * .1;
12
+    }
13
+    return pay_rate;
14
+}

+ 15
- 0
cs142/final/administrator.h View File

@@ -0,0 +1,15 @@
1
+#ifndef __ADMINISTRATOR_H__
2
+#define __ADMINISTRATOR_H__
3
+
4
+#include <iostream>
5
+#include "employee.h"
6
+
7
+using namespace std;
8
+
9
+class administrator : public employee {
10
+    public:
11
+        administrator(string name, double pay_rate, int hours, string type);
12
+        int get_salary();
13
+};
14
+
15
+#endif

+ 263
- 0
cs142/final/campus.cpp View File

@@ -0,0 +1,263 @@
1
+#include "campus.h"
2
+#include "salaried.h"
3
+#include "hourly.h"
4
+#include "faculty.h"
5
+#include "administrator.h"
6
+#include "util.h"
7
+#include <iostream>
8
+#include <vector>
9
+#include <cstdlib>
10
+#include <fstream>
11
+
12
+bool campus::contains(string name) {  //function used to verify if the string is already included
13
+    employee * f = NULL;
14
+    for(unsigned int i = 0; i < workers.size(); i++) {
15
+        f = dynamic_cast<employee *>(workers[i]);
16
+        if(f->get_name() == name) {
17
+            return true;
18
+        }
19
+    }
20
+    return false;
21
+}
22
+
23
+void campus::add_worker_from_parse(string name, string type, double pay_rate) { //add worker for parsed input
24
+    bool passed = false;
25
+    employee * h = NULL;
26
+    int hours = 0;
27
+    if(type == "H") {
28
+        h = new hourly(name, pay_rate, hours, type);
29
+        passed = true;
30
+    }
31
+    else if(type == "S") {
32
+        h = new salaried(name, pay_rate, hours, type);
33
+        passed = true;
34
+    }
35
+    else if(type == "F") {
36
+        h = new faculty(name, pay_rate, hours, type);
37
+        passed = true;
38
+    }
39
+    else if(type == "A") {
40
+        h = new administrator(name, pay_rate, hours, type);
41
+        passed = true;
42
+    }
43
+    if(passed == true) {
44
+        workers.push_back(h);
45
+    }
46
+}
47
+
48
+void campus::add_worker() {  //general add worker function which it gets the input
49
+    employee * h = NULL;
50
+    bool passed;
51
+    string info;
52
+    string name, type;
53
+    int hours = 0;
54
+    double pay_rate = 0;
55
+    cout << "Enter info in following format" << endl;
56
+    cout << "type pay_rate name" << endl;;
57
+    getline(cin, info);
58
+    passed = parse_n_load(info, name, type, pay_rate); 
59
+    if(contains(name) == true) {
60
+        cout << "already exists" << endl;
61
+        return;
62
+    }
63
+    if(passed == false) {
64
+        cout << "incorrect entry" << endl;
65
+    }
66
+    if(info[0] == ' ') {
67
+        cout << "incorrect entry" << endl;
68
+        passed = false;
69
+    }
70
+    else if(type == "H") {
71
+        h = new hourly(name, pay_rate, hours, type);
72
+    }
73
+    else if(type == "S") {
74
+        h = new salaried(name, pay_rate, hours, type);
75
+    }
76
+    else if(type == "F") {
77
+        h = new faculty(name, pay_rate, hours, type);
78
+    }
79
+    else if(type == "A") {
80
+        h = new administrator(name, pay_rate, hours, type);
81
+    }
82
+    if(passed == true) {
83
+        workers.push_back(h);
84
+    }
85
+}
86
+void campus::delete_worker() {
87
+    string name;
88
+    employee * h = NULL;
89
+    cout << "Enter name of worker to delete" << endl;
90
+    getline(cin, name);
91
+    for(unsigned int i = 0; i < workers.size(); i++) {
92
+        h = dynamic_cast<employee *>(workers[i]);
93
+        if(h->get_name() == name) {
94
+            delete h;
95
+            workers.erase(workers.begin() + i);
96
+        }
97
+    }
98
+}
99
+
100
+void campus::display_worker() {  //allows for display of all employees or selected
101
+    string input;
102
+    employee * h = NULL;
103
+    cout << "(a)ll workers or (o)ne worker?" << endl;
104
+    cin >> input;
105
+    cin.ignore();
106
+    cout << "type // payrate // name // hours // salary" << endl;
107
+    if(input == "a") {
108
+        for(unsigned int i = 0; i < workers.size(); i++){
109
+            h = dynamic_cast<employee *>(workers[i]);
110
+            cout << *workers[i] << " $" << h->get_salary() << endl;
111
+        }
112
+    }
113
+    if(input == "o") {
114
+        cout << "name: ";
115
+        employee * h = NULL;
116
+        getline(cin, input);
117
+        for(unsigned int i = 0; i < workers.size(); i++) {
118
+            h = dynamic_cast<employee *>(workers[i]);
119
+            if(h->get_name() == input) {
120
+                cout << *h << " $" << h->get_salary() << endl;
121
+            }
122
+        }
123
+
124
+    }
125
+}
126
+
127
+void campus::sort_name() {
128
+    bool ready = true;
129
+    employee * h = NULL;
130
+    employee * j = NULL;
131
+    while(ready) {
132
+        for(unsigned int i = 0; i < workers.size() -1; i++) {
133
+            h = dynamic_cast<employee *>(workers[i]);
134
+            j = dynamic_cast<employee *>(workers[i+1]);
135
+            ready = false;
136
+            if(h->get_name() > j->get_name()) {
137
+                workers.push_back(workers[i]);
138
+                workers[i] = workers[i+1];
139
+                workers[i+1] = workers[workers.size()-1];
140
+                workers.pop_back();
141
+                ready = true;
142
+            }
143
+        }
144
+    }
145
+}
146
+
147
+void campus::sort_pay() {
148
+    bool ready = true;
149
+    employee * h = NULL;
150
+    employee * j = NULL;
151
+    while(ready) {
152
+        for(unsigned int i = 0; i < workers.size() -1; i++) {
153
+            h = dynamic_cast<employee *>(workers[i]);
154
+            j = dynamic_cast<employee *>(workers[i+1]);
155
+            ready = false;
156
+            if(h->get_payrate() > j->get_payrate()) {
157
+                workers.push_back(workers[i]);
158
+                workers[i] = workers[i+1];
159
+                workers[i+1] = workers[workers.size()-1];
160
+                workers.pop_back();
161
+                ready = true;
162
+            }
163
+        }
164
+    }
165
+}
166
+
167
+void campus::sort_worker() {  //allows for either sort by name or by pay
168
+    string input;
169
+    cout << "sort by (n)ame or by (p)ay?" << endl;
170
+    cin >> input;
171
+    if(input == "n") {
172
+        sort_name();
173
+    }
174
+    if(input == "p") {
175
+        sort_pay();
176
+    }
177
+}
178
+
179
+void campus::advance_month() {
180
+    employee * h = NULL;
181
+    for(unsigned int i = 0; i < workers.size(); i++) {
182
+        h = dynamic_cast<employee *>(workers[i]);
183
+        h->reset_hours();
184
+    }
185
+}
186
+
187
+void campus::set_hours() {
188
+    string name;
189
+    employee * h = NULL;
190
+    cout << "enter name of employee" << endl;
191
+    getline(cin, name);
192
+    for(unsigned int i = 0; i < workers.size(); i++) {
193
+        h = dynamic_cast<employee *>(workers[i]);
194
+        if(h->get_name() == name) {
195
+            int input;
196
+            cout << "enter hours" << endl;
197
+            cin >> input;
198
+            cin.ignore();
199
+            h->set_hours(input);
200
+        }
201
+    }
202
+}
203
+
204
+void campus::add_files(campus c) { //function for i/o.  can either write to a file or take a file in
205
+    string add_or_write;
206
+    cout << "(a)dd or (w)rite to file?" << endl;
207
+    cin >> add_or_write;
208
+    cin.ignore();
209
+    if(add_or_write == "a") {
210
+        bool file_correct = false;
211
+        string input, input_file_name;
212
+        while(!file_correct) {
213
+            cout << "please enter file name: ";
214
+            getline(cin, input);
215
+            ifstream inputs(input.c_str());
216
+            if(inputs.good()) {
217
+                input_file_name = input;
218
+                file_correct = true;
219
+                string lineread;
220
+                while(getline(inputs, lineread)) {
221
+                    bool worked;
222
+                    string name, type;
223
+                    double pay_rate;
224
+                    worked = parse_n_load(lineread, name, type, pay_rate);
225
+                    if(worked == true) {
226
+                        add_worker_from_parse(name, type, pay_rate);
227
+                    }
228
+                    lineread = "";
229
+                }
230
+            }
231
+            else {
232
+                cerr << "incorrect file name" << endl;
233
+            }
234
+        }
235
+    }
236
+    if(add_or_write == "w") {
237
+        bool file_correct = false;
238
+        string input, input_file_name;
239
+        string output_file_name;
240
+        file_correct = false;
241
+        while(!file_correct) {
242
+            cout << "please enter file name: ";
243
+            getline(cin, output_file_name);
244
+            ofstream out(output_file_name.c_str());
245
+            if(out.good()) {
246
+                out << c;
247
+                file_correct = true;
248
+            }
249
+            else {
250
+                cerr << "incorrect file name" << endl;
251
+            }
252
+        }
253
+    }
254
+}
255
+
256
+ostream & operator<<(ostream & os, campus & t) { //makes writing out to files much easier
257
+    employee * h = NULL;
258
+    for(unsigned int i = 0; i < t.workers.size(); i++) {
259
+        h = dynamic_cast<employee *>(t.workers[i]);
260
+        os << h->get_type() << " " << h->get_payrate() << " " << h->get_name() << "\n";
261
+    }
262
+    return os;
263
+}

+ 27
- 0
cs142/final/campus.h View File

@@ -0,0 +1,27 @@
1
+#ifndef __CAMPUS_H__
2
+#define __CAMPUS_H__
3
+
4
+#include "employee.h"
5
+#include <vector>
6
+
7
+using namespace std;
8
+
9
+class campus {
10
+    private:
11
+        vector<employee*> workers;
12
+    public:
13
+        void add_worker();
14
+        void add_worker_from_parse(string name, string type, double pay_rate);
15
+        void delete_worker();
16
+        void display_worker();
17
+        void sort_worker();
18
+        void advance_month();
19
+        void set_hours();
20
+        void add_files(campus c);
21
+        void sort_name();
22
+        void sort_pay();
23
+        bool contains(string name);
24
+        friend ostream & operator<<(ostream & os, campus & t);
25
+};
26
+
27
+#endif

+ 35
- 0
cs142/final/employee.cpp View File

@@ -0,0 +1,35 @@
1
+#include "employee.h"
2
+#include <iostream>
3
+using namespace std;
4
+
5
+employee::employee(string name, double pay_rate, int hours, string type) :
6
+        name(name), pay_rate(pay_rate), hours(hours), type(type) {}
7
+
8
+string employee::get_name(){
9
+    return name;
10
+}
11
+
12
+double employee::get_payrate() {
13
+    return pay_rate;
14
+}
15
+
16
+int employee::get_hours() {
17
+    return hours;
18
+}
19
+
20
+string employee::get_type() {
21
+    return type;
22
+}
23
+
24
+void employee::reset_hours() {
25
+    hours = 0;
26
+}
27
+
28
+void employee::set_hours(int input) {
29
+    hours += input;
30
+}
31
+
32
+ostream & operator<<(ostream & os, employee & t){ //makes printing out employee easy
33
+        os << t.type << " " << t.pay_rate << " " << t.name << " " << t.hours;
34
+    return os;
35
+}

+ 27
- 0
cs142/final/employee.h View File

@@ -0,0 +1,27 @@
1
+#ifndef __EMPLOYEE_H__
2
+#define __EMPLOYEE_H__
3
+
4
+#include <iostream>
5
+
6
+using namespace std;
7
+
8
+class employee {
9
+    private:
10
+        string name;
11
+    protected:
12
+        string type;
13
+        double pay_rate;
14
+        int hours;
15
+    public:
16
+        employee(string name, double pay_rate, int hours, string type);
17
+        string get_name();
18
+        double get_payrate();
19
+        string get_type();
20
+        int get_hours();
21
+        void set_hours(int input);
22
+        void reset_hours();
23
+        virtual int get_salary() = 0;
24
+        friend ostream & operator<<(ostream & os, employee & t);
25
+};
26
+
27
+#endif

+ 32
- 0
cs142/final/faculty.cpp View File

@@ -0,0 +1,32 @@
1
+#include "faculty.h"
2
+#include "employee.h"
3
+#include <cstdlib>
4
+#include <iostream>
5
+
6
+using namespace std;
7
+
8
+faculty::faculty(string name, double pay_rate, int hours, string type) : employee(name, pay_rate, hours, type),
9
+        grad_students(set_grad_students()) {}
10
+
11
+int faculty::get_salary() {
12
+    double pay_rate_return = 0;
13
+    if(grad_students > 0){
14
+        double percent;
15
+        pay_rate_return = pay_rate;
16
+        for(int i = 0; i < grad_students; i++){
17
+            percent +=  0.05;
18
+        }
19
+        pay_rate_return += pay_rate*percent;
20
+        return pay_rate_return;
21
+    }
22
+    return pay_rate;
23
+}
24
+
25
+int faculty::get_grad_students() {
26
+    return grad_students;
27
+}
28
+int faculty::set_grad_students() { //gets random number of grad students for faculty
29
+    srand(time(NULL));
30
+    int students = rand() % 5;
31
+    return students;
32
+}

+ 19
- 0
cs142/final/faculty.h View File

@@ -0,0 +1,19 @@
1
+#ifndef __FACULTY_H__
2
+#define __FACULTY_H__
3
+
4
+#include <iostream>
5
+#include "employee.h"
6
+
7
+using namespace std;
8
+
9
+class faculty : public employee {
10
+    private:
11
+        int grad_students;
12
+    public:
13
+        faculty(string name, double pay_rate, int hours, string type);
14
+        int get_grad_students();
15
+        int set_grad_students();
16
+        int get_salary();
17
+};
18
+
19
+#endif

+ 19
- 0
cs142/final/hourly.cpp View File

@@ -0,0 +1,19 @@
1
+#include "hourly.h"
2
+#include "employee.h"
3
+
4
+using namespace std;
5
+
6
+hourly::hourly(string name, double pay_rate, int hours, string type) : employee(name, pay_rate, hours, type) {}
7
+
8
+int hourly::get_salary() {
9
+    int salary;
10
+    int overtime;
11
+    if((hours - 170) > 0) {
12
+        overtime = (hours - 170);
13
+        salary = 170 * pay_rate;
14
+        salary += overtime * (pay_rate * 1.5);
15
+        return salary;
16
+    }
17
+    salary = hours * pay_rate;
18
+    return salary;
19
+}

+ 15
- 0
cs142/final/hourly.h View File

@@ -0,0 +1,15 @@
1
+#ifndef __HOURLY_H__
2
+#define __HOURLY_H__
3
+
4
+#include <iostream>
5
+#include "employee.h"
6
+
7
+using namespace std;
8
+
9
+class hourly : public employee {
10
+    public:
11
+        hourly(string name, double pay_rate, int hours, string type);
12
+        int get_salary();
13
+};
14
+
15
+#endif

+ 48
- 0
cs142/final/main.cpp View File

@@ -0,0 +1,48 @@
1
+#include <iostream>
2
+#include <fstream>
3
+#include "employee.h"
4
+#include "salaried.h"
5
+#include "hourly.h"
6
+#include "faculty.h"
7
+#include "administrator.h"
8
+#include "util.h"
9
+#include "campus.h"
10
+
11
+using namespace std;
12
+
13
+
14
+int main() {  //driver for program
15
+    campus c = campus();
16
+    bool keep_going = true;
17
+    while(keep_going) {
18
+        string input;
19
+        cout << "(a)dd worker, (r)emove worker, (d)isplay worker, add (h)ours, \n";
20
+        cout << " (s)ort workers, advance (m)onth, add (f)ile, (q)uit" << endl;
21
+        cin >> input;
22
+        cin.ignore();
23
+        if(input == "a") {
24
+            c.add_worker();
25
+        }
26
+        if(input == "r") {
27
+            c.delete_worker();
28
+        }
29
+        if(input == "h") {
30
+            c.set_hours();
31
+        }
32
+        if(input == "d") {
33
+            c.display_worker();
34
+        }
35
+        if(input == "s") {
36
+            c.sort_worker();
37
+        }
38
+        if(input == "m") {
39
+            c.advance_month();
40
+        }
41
+        if(input == "f") {
42
+            c.add_files(c); //will either take in a file or write out to one
43
+        }
44
+        if(input == "q") {
45
+            keep_going = false;
46
+        }
47
+    }
48
+}

+ 13
- 0
cs142/final/salaried.cpp View File

@@ -0,0 +1,13 @@
1
+#include "salaried.h"
2
+#include "employee.h"
3
+
4
+using namespace std;
5
+
6
+salaried::salaried(string name, double pay_rate, int hours, string type) : employee(name, pay_rate, hours, type) {}
7
+
8
+int salaried::get_salary() {
9
+    if(hours > 170/2) {
10
+        return pay_rate;
11
+    }
12
+    return 0;
13
+}

+ 15
- 0
cs142/final/salaried.h View File

@@ -0,0 +1,15 @@
1
+#ifndef __SALARIED_H__
2
+#define __SALARIED_H__
3
+
4
+#include <iostream>
5
+#include "employee.h"
6
+
7
+using namespace std;
8
+
9
+class salaried : public employee {
10
+    public:
11
+        salaried(string name, double pay_rate, int hours, string type);
12
+        int get_salary();
13
+};
14
+
15
+#endif

+ 46
- 0
cs142/final/tags View File

@@ -0,0 +1,46 @@
1
+!_TAG_FILE_FORMAT	2	/extended format; --format=1 will not append ;" to lines/
2
+!_TAG_FILE_SORTED	1	/0=unsorted, 1=sorted, 2=foldcase/
3
+!_TAG_PROGRAM_AUTHOR	Darren Hiebert	/dhiebert@users.sourceforge.net/
4
+!_TAG_PROGRAM_NAME	Exuberant Ctags	//
5
+!_TAG_PROGRAM_URL	http://ctags.sourceforge.net	/official site/
6
+!_TAG_PROGRAM_VERSION	5.9~svn20110310	//
7
+CXXFLAGS	Makefile	/^CXXFLAGS= -Wall -g$/;"	m
8
+EXE	Makefile	/^EXE=main$/;"	m
9
+OBJECTS	Makefile	/^OBJECTS=main.o employee.o hourly.o salaried.o administrator.o faculty.o util.o$/;"	m
10
+__ADMINISTRATOR_H__	administrator.h	2;"	d
11
+__EMPLOYEE_H__	employee.h	2;"	d
12
+__FACULTY_H__	faculty.h	2;"	d
13
+__HOURLY_H__	hourly.h	2;"	d
14
+__SALARIED_H__	salaried.h	2;"	d
15
+__UTIL_H__	util.h	2;"	d
16
+administrator	administrator.cpp	/^administrator::administrator(string name, double pay_rate, int hours) : employee(name, pay_rate, hours) {}$/;"	f	class:administrator
17
+administrator	administrator.h	/^class administrator : public employee {$/;"	c
18
+employee	employee.cpp	/^employee::employee(string name, double pay_rate, int hours) :$/;"	f	class:employee
19
+employee	employee.h	/^class employee {$/;"	c
20
+faculty	faculty.cpp	/^faculty::faculty(string name, double pay_rate, int hours) : employee(name, pay_rate, hours),$/;"	f	class:faculty
21
+faculty	faculty.h	/^class faculty : public employee {$/;"	c
22
+get_grad_students	faculty.cpp	/^int faculty::get_grad_students() {$/;"	f	class:faculty
23
+get_hours	employee.cpp	/^int employee::get_hours() {$/;"	f	class:employee
24
+get_name	employee.cpp	/^string employee::get_name(){$/;"	f	class:employee
25
+get_payrate	employee.cpp	/^double employee::get_payrate() {$/;"	f	class:employee
26
+get_salary	administrator.cpp	/^int administrator::get_salary() {$/;"	f	class:administrator
27
+get_salary	faculty.cpp	/^int faculty::get_salary() {$/;"	f	class:faculty
28
+get_salary	hourly.cpp	/^int hourly::get_salary() {$/;"	f	class:hourly
29
+get_salary	salaried.cpp	/^int salaried::get_salary() {$/;"	f	class:salaried
30
+grad_students	faculty.h	/^        int grad_students;$/;"	m	class:faculty
31
+hourly	hourly.cpp	/^hourly::hourly(string name, double pay_rate, int hours) : employee(name, pay_rate, hours) {}$/;"	f	class:hourly
32
+hourly	hourly.h	/^class hourly : public employee {$/;"	c
33
+hours	employee.h	/^        int hours;$/;"	m	class:employee
34
+main	main.cpp	/^int main() {$/;"	f
35
+name	employee.h	/^        string name;$/;"	m	class:employee
36
+parse_n_load	util.cpp	/^bool parse_n_load(const string & input, string & name, string & type,$/;"	f
37
+pay_rate	employee.h	/^        double pay_rate;$/;"	m	class:employee
38
+salaried	salaried.cpp	/^salaried::salaried(string name, double pay_rate, int hours) : employee(name, pay_rate, hours) {}$/;"	f	class:salaried
39
+salaried	salaried.h	/^class salaried : public employee {$/;"	c
40
+set_grad_students	faculty.cpp	/^int faculty::set_grad_students() {$/;"	f	class:faculty
41
+test_admin	main.cpp	/^void test_admin() {$/;"	f
42
+test_faculty	main.cpp	/^void test_faculty() {$/;"	f
43
+test_hourly	main.cpp	/^void test_hourly() {$/;"	f
44
+test_salaried	main.cpp	/^void test_salaried() {$/;"	f
45
+test_util	main.cpp	/^void test_util() {$/;"	f
46
+tokenize	util.cpp	/^vector<string> tokenize(const string & str, const string & delimiters) {$/;"	f

+ 4
- 0
cs142/final/test.txt View File

@@ -0,0 +1,4 @@
1
+A 10.5 zombie
2
+alka alkjsa
3
+F 152 stephen is awesome
4
+H 15.243 cremeballs. creame

+ 46
- 0
cs142/final/util.cpp View File

@@ -0,0 +1,46 @@
1
+#include <vector>
2
+#include <string>
3
+using namespace std;
4
+#include <cstdlib>
5
+#include "util.h"
6
+#include <iostream>
7
+
8
+vector<string> tokenize(const string & str, const string & delimiters) {
9
+    //tokenizes a string by the delimiter passed in
10
+    vector<string> tokens;
11
+    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
12
+    string::size_type pos  = str.find_first_of(delimiters, lastPos);
13
+    while (string::npos != pos or string::npos != lastPos)
14
+    {
15
+        tokens.push_back(str.substr(lastPos, pos - lastPos));
16
+        lastPos = str.find_first_not_of(delimiters, pos);
17
+        pos = str.find_first_of(delimiters, lastPos);
18
+    }
19
+    return tokens;
20
+}
21
+
22
+bool parse_n_load(const string & input, string & name, string & type,
23
+        double & pay_rate) {
24
+    vector<string> tokens = tokenize(input);
25
+    if(tokens.size() == 0) {
26
+        return false;
27
+    }
28
+    type = tokens[0];
29
+    if (not (   type == "A"
30
+             or type == "F"
31
+             or type == "H"
32
+             or type == "S")) {
33
+        return false;
34
+    }
35
+    pay_rate = atof(tokens[1].c_str());
36
+    if(pay_rate == 0) {
37
+        return false;
38
+    }
39
+    for(unsigned int i = 2; i < tokens.size(); i++) {
40
+        name += tokens[i];
41
+        if(i < tokens.size() - 1) {
42
+            name += " ";
43
+        }
44
+    }
45
+    return true;
46
+}

+ 14
- 0
cs142/final/util.h View File

@@ -0,0 +1,14 @@
1
+#ifndef __UTIL_H__
2
+#define __UTIL_H__
3
+
4
+#include <string>
5
+#include <vector>
6
+
7
+using namespace std;
8
+
9
+void print(const string & in);
10
+vector<string> tokenize(const string & str, const string & delimiters=" ");
11
+bool parse_n_load(const string & input, string & name, string & type,
12
+        double & pay_rate);
13
+
14
+#endif

+ 6
- 0
cs142/lab00/Makefile View File

@@ -0,0 +1,6 @@
1
+CPPFLAGS=-Wall -g -std=c++0x
2
+
3
+all: hello_world
4
+
5
+clean:
6
+	rm -rv hello_world

+ 10
- 0
cs142/lab00/hello_world.cpp View File

@@ -0,0 +1,10 @@
1
+#include <iostream>
2
+
3
+using namespace std;
4
+
5
+int main() {
6
+
7
+    cout << "Hello, world! My name is Derek McQuay."<< endl;
8
+    cin.get();
9
+    return 0;
10
+}

+ 17
- 0
cs142/lab01/byu.cpp View File

@@ -0,0 +1,17 @@
1
+#include <iostream>
2
+
3
+using namespace std;
4
+
5
+int main() {
6
+
7
+
8
+    cout << "                                Basic BYU Trivia\n" << endl;
9
+    cout << "                Questions                                 Answers \n" << endl;
10
+    cout << "What was the original name of BYU?                Brigham Young Academy" << endl;
11
+    cout << "When was BYA established?                         1875" << endl;
12
+    cout << "Who was the first \"permanent\" principal of BYA?   Karl G. Maeser" << endl;
13
+    cout << "When did BYA become BYU?                          1903" << endl;
14
+    cout << "To what sports conference do we belong?           Mountain West Conference(MWC)" << endl;
15
+    cout << "When did BYU win the national football title?     1984" << endl;
16
+    cout << "Who won the Heisman Trophy in 1990?               Ty Detmer" << endl;
17
+}

+ 22
- 0
cs142/lab01/quiz.txt View File

@@ -0,0 +1,22 @@
1
+A
2
+D
3
+B
4
+A
5
+B
6
+C
7
+B
8
+B
9
+B
10
+B
11
+D
12
+B
13
+B
14
+C
15
+A
16
+C
17
+D
18
+A,C
19
+B
20
+B
21
+A,B,C,D
22
+so we can learn by doing rather than let someone else learn.

+ 10
- 0
cs142/lab02/Makefile View File

@@ -0,0 +1,10 @@
1
+CPPFLAGS=-Wall -g -std=c++0x
2
+
3
+all: timer temperature binary
4
+
5
+binary: binary.cpp
6
+temperature: temperature.cpp
7
+timer: timer.cpp
8
+
9
+clean:
10
+	rm -rv timer temperature binary

+ 57
- 0
cs142/lab02/binary.cpp View File

@@ -0,0 +1,57 @@
1
+#include <iostream>
2
+#include <vector>
3
+
4
+using namespace std;
5
+
6
+int main() {
7
+
8
+    int value;
9
+    int first, second, third, fourth, fifth;
10
+    vector<int> final;
11
+
12
+    cout << "please insert your number between 0 and 31" << endl;
13
+    cin >> value;
14
+    int prin = value%2;
15
+    value = value/2;
16
+    if(prin >=1)
17
+        first = 1;
18
+    else
19
+       first = 0; 
20
+    final.push_back(first);
21
+    prin = value%2;
22
+    value = value/2;
23
+    if(prin >=1)
24
+        second = 1;
25
+    else
26
+        second = 0;
27
+    final.push_back(second);
28
+    prin = value%2;
29
+    value = value/2;
30
+    if(prin >= 1)
31
+        third = 1;
32
+    else
33
+        third = 0;
34
+    final.push_back(third);
35
+    prin = value%2;
36
+    value = value/2;
37
+    if(prin >= 1)
38
+        fourth = 1;
39
+    else
40
+        fourth = 0;
41
+    final.push_back(fourth);
42
+    prin = value%2;
43
+    value = value/2;
44
+    if(prin >= 1)
45
+        fifth = 1;
46
+    else
47
+        fifth = 0;
48
+    final.push_back(fifth);
49
+
50
+    cout <<fifth<<fourth<<third<<second<<first << endl;
51
+  //  for(unsigned int i = 0 ; i<final.size();i++) {
52
+
53
+   //     cout << final[i];
54
+  //  }
55
+    cout << "\n";
56
+
57
+}

+ 20
- 0
cs142/lab02/temperature.cpp View File

@@ -0,0 +1,20 @@
1
+#include <iostream>
2
+
3
+using namespace std;
4
+
5
+int main() {
6
+
7
+    double temperature;
8
+    cout << "please enter a temperature in degress Fahrenheit:" << endl;
9
+    cin >> temperature;
10
+    double celsius = (temperature-32) * 5/9;
11
+    cout << "This is Fahrenheit as an int:" << endl;
12
+    cout << (int) temperature << endl;
13
+    cout << "This is Celsius as a double:" << endl;
14
+    cout << celsius << endl;
15
+    cout << "This is Celsius as an int:" << endl;
16
+    cout << (int) celsius << endl;
17
+
18
+
19
+
20
+}

+ 30
- 0
cs142/lab02/timer.cpp View File

@@ -0,0 +1,30 @@
1
+#include <iostream>
2
+#include <cmath>
3
+
4
+using namespace std;
5
+    
6
+void calculate (int a) {
7
+
8
+    int hours, minutes, seconds;
9
+
10
+    hours = (a / 3600);
11
+    minutes = (a / 60) - (hours * 60);
12
+    seconds = a % 60;
13
+
14
+    cout << "hours: " << hours << " minutes: " << minutes << " seconds: " << seconds << endl;
15
+
16
+};
17
+
18
+
19
+int main() {
20
+
21
+    int time;
22
+    cout << "please enter a number of seconds" << endl;
23
+    cin >> time;
24
+    cout << time << endl;
25
+    cout << "absolute value of input " << abs (time) << endl;
26
+    calculate(time);
27
+    cout << "now with sqrt: " << endl;
28
+    calculate(sqrt(time));
29
+}
30
+

+ 4
- 0
cs142/lab03/Makefile View File

@@ -0,0 +1,4 @@
1
+CXXFLAGS=-Wall -g -std=c++0x
2
+all: grade
3
+clean:
4
+	rm -vf grade

+ 13
- 0
cs142/lab03/class/main.cpp View File

@@ -0,0 +1,13 @@
1
+#include <iostream>
2
+
3
+using namespace std;
4
+
5
+#include "person.h"
6
+
7
+#pragma once
8
+
9
+int main(int argc, char * argv[]) {
10
+
11
+    person p;
12
+    p.get_grades();
13
+}

+ 60
- 0
cs142/lab03/class/person.cpp View File

@@ -0,0 +1,60 @@
1
+using namespace std;
2
+
3
+#include "person.h"
4
+
5
+#pragma once
6
+
7
+void person::get_latedays() {
8
+
9
+    cout << "Please enter if it was turned in earlier or late (earlier with a negative number): " << endl;
10
+    cin >> late_days;
11
+    total_latedays = total_latedays + late_days;
12
+}
13
+
14
+void person::get_exam_latedays(){
15
+    cout << "Please enter if it was turned in in late (number of late days): " << endl;
16
+    cin >> late_days_exam;
17
+    late_days_exam = abs(late_days_exam);
18
+    total_latedays_exam = total_latedays_exam + late_days_exam;
19
+}
20
+
21
+void person::calculate_grade() {
22
+
23
+    grade = lab1 + lab2 + lab3 + lab4 + lab5 + lab6 + lab7 + lab8 + lab9 + lab10 + lab11 + exam1 + exam2 + final;
24
+}
25
+
26
+
27
+void person::get_grades(){
28
+
29
+    cout << "please enter the name of the student: " << endl;
30
+    cout << "now we are going to enter the following grades for the student: " << endl;
31
+    cout << "Grade for lab 01: " << endl;
32
+    cin >> lab1;
33
+    cout << "Grade for lab 02; " << endl;
34
+    cin >> lab2;
35
+    cout << "Grade for lab 03; " << endl;
36
+    cin >> lab3;
37
+    cout << "Grade for lab 04; " << endl;
38
+    cin >> lab4;
39
+    cout << "Grade for lab 05; " << endl;
40
+    cin >> lab5;
41
+    cout << "Grade for lab 06; " << endl;
42
+    cin >> lab6;
43
+    cout << "Grade for lab 07; " << endl;
44
+    cin >> lab7;
45
+    cout << "Grade for lab 08; " << endl;
46
+    cin >> lab8;
47
+    cout << "Grade for lab 09; " << endl;
48
+    cin >> lab9;
49
+    cout << "Grade for lab 10; " << endl;
50
+    cin >> lab10;
51
+    cout << "Grade for lab 11; " << endl;
52
+    cin >> lab11;
53
+    cout << "Grade for exam 1: " << endl;
54
+    cin >> exam1;
55
+    cout << "Grade for exam 2: " << endl;
56
+    cin >> exam2;
57
+    cout << "Grade for final: " << endl;
58
+    cin >> final;
59
+    cout << "Please enter how many days late the final was: " << endl;
60
+}

+ 24
- 0
cs142/lab03/class/person.h View File

@@ -0,0 +1,24 @@
1
+#include <iostream>
2
+#include <cmath>
3
+
4
+using namespace std;
5
+
6
+class person
7
+{
8
+
9
+    
10
+    private:
11
+        string person_name;
12
+        int lab1, lab2, lab3, lab4, lab5, lab6, lab7, lab8, lab9, lab10, lab11, exam1, exam2, final;
13
+        int late_days, total_latedays, late_days_exam, total_latedays_exam;
14
+        int grade;
15
+
16
+    public:
17
+
18
+        person(){};
19
+        void get_latedays(); 
20
+        void get_exam_latedays();
21
+        void calculate_grade();
22
+        void get_grades();
23
+
24
+};

+ 304
- 0
cs142/lab03/grade.cpp View File

@@ -0,0 +1,304 @@
1
+#include <iostream>
2
+#include <cmath>
3
+#include <vector>
4
+
5
+using namespace std;
6
+
7
+struct student {
8
+    string name;
9
+    int grade;
10
+    string letter_grade;
11
+
12
+};
13
+
14
+int main() {
15
+    // this is incorrect: typedef struct student1;
16
+    struct student student1;
17
+    struct student student2;
18
+    int lab1, lab2, lab3, lab4, lab5, lab6, lab7, lab8, lab9, lab10, lab11;
19
+    int exam1, exam2, final;
20
+    int late_days;
21
+    int late_daytotal = 0;
22
+    int exam_late_days;
23
+    int exam_late_days_total = 0;
24
+    string name;
25
+
26
+    for(int i = 1; i<3; i++){
27
+        cout << "Please enter name of student: " << endl;
28
+        cin >> name;
29
+        cout << "Please enter grade for lab 1: " << endl;
30
+        cin >> lab1;
31
+        if(lab1 >20 or lab1 < 0){
32
+            cout << "This is not in the range!" << endl;
33
+            return 0;
34
+        }
35
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
36
+        cin >> late_days;
37
+        if(late_days <-2 or late_days > 2){
38
+            cout << "This is not in the range!" << endl;
39
+            return 0;
40
+        }
41
+        late_daytotal = late_daytotal + late_days;
42
+        cout << "Please enter grade for lab 2: " << endl;
43
+        cin >> lab2;
44
+        if(lab2 >20 or lab2 < 0){
45
+            cout << "This is not in the range!" << endl;
46
+            return 0;
47
+        }
48
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
49
+        cin >> late_days;
50
+        if(late_days <-2 or late_days > 2){
51
+            cout << "This is not in the range!" << endl;
52
+            return 0;
53
+        }
54
+        late_daytotal = late_daytotal + late_days;
55
+        cout << "Please enter grade for lab 3: " << endl;
56
+        cin >> lab3;
57
+        if(lab3 >30 or lab3 < 0){
58
+            cout << "This is not in the range!" << endl;
59
+            return 0;
60
+        }
61
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
62
+        cin >> late_days;
63
+        if(late_days <-3 or late_days > 3){
64
+            cout << "This is not in the range!" << endl;
65
+            return 0;
66
+        }
67
+        late_daytotal = late_daytotal + late_days;
68
+        cout << "Please enter grade for lab 4: " << endl;
69
+        cin >> lab4;
70
+        if(lab4 >30 or lab4 < 0){
71
+            cout << "This is not in the range!" << endl;
72
+            return 0;
73
+        }
74
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
75
+        cin >> late_days;
76
+        if(late_days <-3 or late_days > 3){
77
+            cout << "This is not in the range!" << endl;
78
+            return 0;
79
+        }
80
+        late_daytotal = late_daytotal + late_days;
81
+        cout << "Please enter grade for lab 5: " << endl;
82
+        cin >> lab5;
83
+        if(lab5 >30 or lab5 < 0){
84
+            cout << "This is not in the range!" << endl;
85
+            return 0;
86
+        }
87
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
88
+        cin >> late_days;
89
+        if(late_days <-3 or late_days > 3){
90
+            cout << "This is not in the range!" << endl;
91
+            return 0;
92
+        }
93
+        late_daytotal = late_daytotal + late_days;
94
+        cout << "Please enter grade for lab 6: " << endl;
95
+        cin >> lab6;
96
+        if(lab6 >30 or lab6 < 0){
97
+            cout << "This is not in the range!" << endl;
98
+            return 0;
99
+        }
100
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
101
+        cin >> late_days;
102
+        if(late_days <-3 or late_days > 3){
103
+            cout << "This is not in the range!" << endl;
104
+            return 0;
105
+        }
106
+        late_daytotal = late_daytotal + late_days;
107
+        cout << "Please enter grade for lab 7: " << endl;
108
+        cin >> lab7;
109
+        if(lab7 >30 or lab7 < 0){
110
+            cout << "This is not in the range!" << endl;
111
+            return 0;
112
+        }
113
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
114
+        cin >> late_days;
115
+        if(late_days <-3 or late_days > 3){
116
+            cout << "This is not in the range!" << endl;
117
+            return 0;
118
+        }
119
+        late_daytotal = late_daytotal + late_days;
120
+        cout << "Please enter grade for lab 8: " << endl;
121
+        cin >> lab8;
122
+        if(lab8 >30 or lab8 < 0){
123
+            cout << "This is not in the range!" << endl;
124
+            return 0;
125
+        }
126
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
127
+        cin >> late_days;
128
+        if(late_days <-3 or late_days > 3){
129
+            cout << "This is not in the range!" << endl;
130
+            return 0;
131
+        }
132
+        late_daytotal = late_daytotal + late_days;
133
+        cout << "Please enter grade for lab 9: " << endl;
134
+        cin >> lab9;
135
+        if(lab9 >20 or lab9 < 0){
136
+            cout << "This is not in the range!" << endl;
137
+            return 0;
138
+        }
139
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
140
+        cin >> late_days;
141
+        if(late_days <-2 or late_days > 2){
142
+            cout << "This is not in the range!" << endl;
143
+            return 0;
144
+        }
145
+        late_daytotal = late_daytotal + late_days;
146
+        cout << "Please enter grade for lab 10: " << endl;
147
+        cin >> lab10;
148
+        if(lab10 >20 or lab10 < 0){
149
+            cout << "This is not in the range!" << endl;
150
+            return 0;
151
+        }
152
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
153
+        cin >> late_days;
154
+        if(late_days <-2 or late_days > 2){
155
+            cout << "This is not in the range!" << endl;
156
+            return 0;
157
+        }
158
+        late_daytotal = late_daytotal + late_days;
159
+        cout << "Please enter grade for lab 11: " << endl;
160
+        cin >> lab11;
161
+        if(lab11 >40 or lab11 < 0){
162
+            cout << "This is not in the range!" << endl;
163
+            return 0;
164
+        }
165
+        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
166
+        cin >> late_days;
167
+        if(late_days <-4 or late_days > 4){
168
+            cout << "This is not in the range!" << endl;
169
+            return 0;
170
+        }
171
+        late_daytotal = late_daytotal + late_days;
172
+        cout << "Please enter exam 1 score: " << endl;
173
+        cin >> exam1;
174
+        if(exam1 < 0 or exam1 > 100){
175
+            cout << "This is not in the range!" << endl;
176
+            return 0;
177
+        }
178
+        cout << "Were there late days/early days?"  << endl;
179
+        cin >> exam_late_days;
180
+        if(exam_late_days < 0 or exam_late_days > 3){
181
+            cout << "This is not in the range!" << endl;
182
+            return 0;
183
+        }
184
+        exam_late_days_total = exam_late_days_total + exam_late_days;
185
+        cout << "Please enter exam 2 score: " << endl;
186
+        cin >> exam2;
187
+        if(exam2 < 0 or exam2 > 100){
188
+            cout << "This is not in the range!" << endl;
189
+            return 0;
190
+        }
191
+        cout << "Were there late days/early days?"  << endl;
192
+        cin >> exam_late_days;
193
+        if(exam_late_days < 0 or exam_late_days > 3){
194
+            cout << "This is not in the range!" << endl;
195
+            return 0;
196
+        }
197
+        exam_late_days_total = exam_late_days_total + exam_late_days;
198
+        cout << "Please enter final score: " << endl;
199
+        cin >> final;
200
+        if(final < 0 or final > 100){
201
+            cout << "This is not in the range!" << endl;
202
+            return 0;
203
+        }
204
+        cout << "Were there late days/early days?"  << endl;
205
+        cin >> exam_late_days;
206
+        if(exam_late_days < 0 or exam_late_days > 3){
207
+            cout << "This is not in the range!" << endl;
208
+            return 0;
209
+        }
210
+        exam_late_days_total = exam_late_days_total + exam_late_days;
211
+
212
+        int total_labs = lab1+lab2+lab3+lab4+lab5+lab6+lab7+lab8+lab9+lab10+lab11;
213
+        int total_exam = exam1 + exam2 + final;
214
+        int final_grade = total_labs + total_exam;
215
+        if(late_daytotal < 0){
216
+            final_grade = final_grade + abs(late_daytotal);
217
+        }
218
+        else{
219
+            final_grade = final_grade - late_daytotal;
220
+        }
221
+        final_grade = final_grade - exam_late_days_total*20;
222
+        string letter_grade;
223
+        if(final_grade >= 570)
224
+            letter_grade = "A";
225
+        if(final_grade <570 && final_grade >=540)
226
+            letter_grade = "A-";
227
+        if(final_grade < 540 && final_grade >= 522)
228
+            letter_grade = "B+";
229
+        if(final_grade < 522 && final_grade >= 498)
230
+            letter_grade = "B";
231
+        if(final_grade < 498 && final_grade >= 480)
232
+            letter_grade = "B-";
233
+        if(final_grade < 480 && final_grade >= 462)
234
+            letter_grade = "C+";
235
+        if(final_grade < 462 && final_grade >= 438)
236
+            letter_grade = "C";
237
+        if(final_grade < 438 && final_grade >= 420)
238
+            letter_grade = "C-";
239
+        if(final_grade < 420 && final_grade >= 402)
240
+            letter_grade = "D+";
241
+        if(final_grade < 402 && final_grade >= 378)
242
+            letter_grade = "D";
243
+        if(final_grade < 378 && final_grade >= 360)
244
+            letter_grade = "D-";
245
+        if(final_grade < 360)
246
+            letter_grade = "E";
247
+
248
+        // something looks iffy here: (check your warnings (read all the words (even 'assignment')))
249
+        if (i == 1) {
250
+            student1.name = name;
251
+            student1.grade = final_grade;
252
+            student1.letter_grade = letter_grade;
253
+        }
254
+        else {
255
+            student2.name = name;
256
+            student2.grade = final_grade;
257
+            student2.letter_grade = letter_grade;
258
+        }
259
+    }
260
+    int order = 0;
261
+    cout << "Please enter what order you want to see the students: " << endl;
262
+    cout << "enter 1 for alphabetical or 2 for highest score first: " << endl;
263
+    cin >> order;
264
+    if(order > 2 or order < 1) {
265
+        cout << "out of range" <<endl;
266
+        return 0;
267
+    }
268
+    if(order == 1){
269
+        if(student1.name < student2.name) {
270
+            cout << "name " <<  student1.name << endl;
271
+            cout << "points " <<  student1.grade << endl;
272
+            cout << "letter grade " << student1.letter_grade << endl;
273
+            cout << "name " << student2.name << endl;
274
+            cout << "points " << student2.grade << endl;
275
+            cout << "letter grade " << student2.letter_grade << endl;
276
+        }
277
+        else {
278
+            cout << "name " << student2.name << endl;
279
+            cout << "points " << student2.grade << endl;
280
+            cout << "letter grade " << student2.letter_grade << endl;
281
+            cout << "name " <<  student1.name << endl;
282
+            cout << "points " <<  student1.grade << endl;
283
+            cout << "letter grade " << student1.letter_grade << endl;
284
+        }
285
+    }
286
+    if(order == 2){
287
+        if(student1.grade > student2.grade){
288
+            cout << "name " <<  student1.name << endl;
289
+            cout << "points " <<  student1.grade << endl;
290
+            cout << "letter grade " << student1.letter_grade << endl;
291
+            cout << "name " << student2.name << endl;
292
+            cout << "points " << student2.grade << endl;
293
+            cout << "letter grade " << student2.letter_grade << endl;
294
+        }
295
+        else {
296
+            cout << "name " << student2.name << endl;
297
+            cout << "points " << student2.grade << endl;
298
+            cout << "letter grade " << student2.letter_grade << endl;
299
+            cout << "name " <<  student1.name << endl;
300
+            cout << "points " <<  student1.grade << endl;
301
+            cout << "letter grade " << student1.letter_grade << endl;
302
+        }
303
+    }
304
+}

+ 16
- 0
cs142/lab03/quick.cpp View File

@@ -0,0 +1,16 @@
1
+#include <iostream>
2
+#include <string>
3
+
4
+using namespace std;
5
+
6
+int main () {
7
+
8
+    string a, b;
9
+    cin >> a;
10
+    cin >> b;
11
+
12
+    if(a<b)
13
+        cout << "first is before last" << endl;
14
+    else
15
+        cout << "Second is before first" << endl;
16
+}

+ 59
- 0
cs142/lab03/test.txt View File

@@ -0,0 +1,59 @@
1
+derek
2
+20
3
+-2
4
+20
5
+-2
6
+30
7
+-2
8
+30
9
+-2
10
+30
11
+-2
12
+30
13
+-2
14
+30
15
+-2
16
+30
17
+0
18
+20
19
+0
20
+20
21
+0
22
+40
23
+0
24
+100
25
+2
26
+0
27
+0
28
+100
29
+0
30
+alex
31
+20
32
+-2
33
+20
34
+1
35
+30
36
+1
37
+30
38
+1
39
+30
40
+1
41
+30
42
+1
43
+30
44
+0
45
+30
46
+0
47
+20
48
+0
49
+20
50
+0
51
+40
52
+0
53
+100
54
+0
55
+100
56
+0
57
+100
58
+1
59
+1

+ 7
- 0
cs142/lab04/Makefile View File

@@ -0,0 +1,7 @@
1
+CXXFLAGS=-Wall -g -std=c++0x
2
+all: number
3
+clean:
4
+	rm -vf number
5
+
6
+test: all
7
+	./number

+ 53
- 0
cs142/lab04/loops.py View File

@@ -0,0 +1,53 @@
1
+import random
2
+import time
3
+
4
+
5
+def get_numbers(pow2, compliment):
6
+    numbers = []
7
+    constant = compliment
8
+    for i in (0, 1):
9
+        for j in (0, 1):
10
+            for k in (0, 1):
11
+                for l in (0, 1):
12
+                    if pow2 == 0:
13
+                        cur_digits = (i, j, k, l, constant)
14
+                    if pow2 == 1:
15
+                        cur_digits = (i, j, k, constant, l)
16
+                    if pow2 == 2:
17
+                        cur_digits = (i, j, constant, k, l)
18
+                    if pow2 == 3:
19
+                        cur_digits = (i, constant, j, k, l)
20
+                    if pow2 == 4:
21
+                        cur_digits = (constant, i, j, k, l)
22
+                    numbers.append(cur_digits)
23
+    return numbers
24
+
25
+print "example of how to use randomness to determine compliment"
26
+a_few_tries = xrange(3)
27
+for i in a_few_tries:
28
+    compliment = random.randint(0, 3026) % 2
29
+    for i in get_numbers(pow2=0, compliment=compliment):
30
+        print i
31
+
32
+print "for loop to print out all numbers from 2^0 to 2^5"
33
+for i in (0, 1):
34
+    for j in (0, 1):
35
+        for k in (0, 1):
36
+            for l in (0, 1):
37
+                for m in (0, 1):
38
+                    for n in (0, 1):
39
+                        print i, j, k, l, m
40
+
41
+print "example function to convert a string in binary to integers: (see source)"
42
+def bin2int(s):
43
+    total = 0
44
+    for i in xrange(len(s)):
45
+        if s[i] == '1':
46
+            total += 2**(len(s) - i - 1)
47
+    return total
48
+
49
+
50
+print "here I test out the bin2int func defined above:"
51
+test_cases = ('1010', '1011', '0100', '1000', '0111')
52
+for test in test_cases:
53
+    print test, bin2int(test), int(test, 2)

+ 111
- 0
cs142/lab04/number.cpp View File

@@ -0,0 +1,111 @@
1
+#include <iostream>
2
+#include <vector>
3
+#include <cstdlib>
4
+#include <time.h>
5
+#include <sstream>
6
+#include <cmath>
7
+#include <algorithm>
8
+
9
+using namespace std;
10
+
11
+int bit2dec(string s); 
12
+
13
+vector<int> get_numbers(int pow, int compliment) {
14
+    string store;
15
+    vector<int> numbers;
16
+    int constant = compliment;
17
+    for(int i = 0; i < 2; i++){
18
+        for(int j = 0; j < 2; j++){
19
+            for(int k = 0; k < 2; k++){
20
+                for(int l = 0; l < 2; l++){
21
+                    ostringstream stream;
22
+                    if(pow == 0){
23
+                        stream << i << j << k << l << constant;
24
+                    }
25
+                    else if(pow == 1){
26
+                        stream << i << j << k << constant << l;
27
+                    }
28
+                    else if(pow == 2){
29
+                        stream << i << j << constant << k << l;
30
+                    }
31
+                    else if(pow == 3){
32
+                        stream << i << constant << j << k << l;
33
+                    }
34
+                    else if(pow == 4){
35
+                        stream << constant << i << j << k << l;
36
+                    }
37
+                    store = stream.str();
38
+                    numbers.push_back(bit2dec(store));
39
+                }
40
+            }
41
+        }
42
+    }
43
+    return numbers;
44
+}
45
+
46
+
47
+ostream & operator<<(ostream & os, const vector<int> & nums) {
48
+    for(unsigned int i = 0; i < nums.size(); i++){
49
+        if(i % 4 == 0){
50
+        os << endl;
51
+        }
52
+        os << nums[i] << " ";
53
+    }
54
+    return os;
55
+}
56
+
57
+int bit2dec(string s) {
58
+
59
+    int total = 0;
60
+    int power = 0;
61
+    for(int i = s.size() - 1; i >= 0; i--) {
62
+        if(s[i] == '1') {
63
+           total += pow(2,power);
64
+        }
65
+        power++;
66
+    }
67
+    return total;
68
+}
69
+
70
+
71
+int main() {
72
+
73
+    srand (time(NULL));
74
+    int keep_playing = 0;
75
+    while(keep_playing == 0){
76
+        ostringstream answer;
77
+        for(unsigned int i = 0; i < 5 ; i++) {
78
+            int switcher = rand() % 2;
79
+            string check;
80
+            cout << "Is your number in this list? enter y for yes n for no" << endl;
81
+            cout << get_numbers(i, switcher) << endl;
82
+            cin >> check;
83
+            if(switcher == 0){
84
+                if(check == "y") {
85
+                    answer << '0';
86
+                }
87
+                else {
88
+                    answer << '1';
89
+                }
90
+            }
91
+            if(switcher == 1) {
92
+                if(check == "y") {
93
+                    answer << '1';
94
+                }
95
+                else {
96
+                    answer << '0';
97
+                }
98
+            }
99
+        }
100
+        string final = answer.str();
101
+        reverse (final.begin(), final.end());
102
+        cout << bit2dec(final) << endl;
103
+        cout << "Do you want to keep playing? enter y for yes, n for no" << endl;
104
+        string check;
105
+        cin >> check;
106
+        if(check == "n"){
107
+            keep_playing++;
108
+        }
109
+    }
110
+    return 0;
111
+}

+ 17
- 0
cs142/lab04/quick.cpp View File

@@ -0,0 +1,17 @@
1
+#include <iostream>
2
+#include <vector>
3
+
4
+using namespace std;
5
+
6
+int main() {
7
+
8
+    vector<int> numbers;
9
+
10
+    numbers.push_back(0);
11
+    numbers.push_back(1);
12
+    numbers.push_back(0);
13
+    numbers.push_back(1);
14
+    numbers.push_back(0);
15
+
16
+        cout << numbers[0] << numbers[1]<< numbers[2]<<numbers[3] << numbers[4] <<endl;
17
+}

+ 10
- 0
cs142/lab05/Makefile View File

@@ -0,0 +1,10 @@
1
+CXXFLAGS=-Wall -g -std=c++0x
2
+all: monopoly
3
+clean:
4
+	rm -vf monopoly
5
+
6
+test: all
7
+	./monopoly
8
+
9
+debug: all
10
+	gdb monopoly

+ 10
- 0
cs142/lab05/game/Makefile View File

@@ -0,0 +1,10 @@
1
+CXXFLAGS=-Wall -g -std=c++0x
2
+all: monopoly
3
+clean:
4
+	rm -vf monopoly
5
+
6
+test: all
7
+	./monopoly
8
+
9
+debug: all
10
+	gdb monopoly

+ 18
- 0
cs142/lab05/game/game.cpp View File

@@ -0,0 +1,18 @@
1
+#include <iostream>
2
+#include <vector>
3
+
4
+using namespace std;
5
+
6
+struct property {
7
+    string name;
8
+    int value;
9
+}
10
+void create_board(vector<property> & board) {
11
+    board.push_back(property{"mediterranean Avenue", 60}
12
+}
13
+
14
+int main() {
15
+    vector<property> board;
16
+    cout << board.name << endl;
17
+
18
+}

+ 175
- 0
cs142/lab05/game/monopoly.cpp View File

@@ -0,0 +1,175 @@
1
+#include <iostream>
2
+#include <cstdlib>
3
+#include <time.h>
4
+#include <vector>
5
+
6
+using namespace std;
7
+
8
+
9
+struct property{
10
+    string name;
11
+    int value;
12
+};
13
+
14
+void roll_the_dice() {
15
+    srand(time(NULL));
16
+    int roll = rand() % 6 +1;
17
+    int roll2 = rand() % 6 +1;
18
+    cout << roll << " + "<< roll2 << " equals " << roll +roll2 << endl;
19
+}
20
+
21
+void report_current_money(int & current_money) {
22
+    cout << "this is your current money" << endl;
23
+    cout << current_money << endl;
24
+}
25
+
26
+void add_money(int & current_money) {
27
+    cout << "how much money would you like to add? " << endl;
28
+    int add;
29
+    cin >> add;
30
+    if(add < 0){
31
+        cout << "please enter a positive number" << endl;
32
+        add_money(current_money);
33
+    }
34
+    else {
35
+        current_money += add;
36
+        cout << current_money << endl;
37
+    }
38
+}
39
+
40
+void spend_money(int & current_money) {
41
+    cout << "how much money would you like to spend? " << endl;
42
+    int minus;
43
+    cin >> minus;
44
+    if(current_money - minus < 0) {
45
+        cout << "This would result in a negative number!" << endl;
46
+    }
47
+    else {
48
+        current_money -= minus;
49
+        cout << current_money << endl;
50
+    }
51
+}
52
+
53
+void pass_go(int & current_money) {
54
+    cout << "you passed go, collect 200 dollars!" << endl;
55
+    current_money += 200;
56
+}
57
+
58
+bool has_property(vector<property> & props, string name) {
59
+    bool has_prop = false;
60
+    for(unsigned int i = 0; i < props.size(); i++) {
61
+        if(name == props[i].name) {
62
+            has_prop = true;
63
+        }
64
+    }
65
+    return has_prop;
66
+}
67
+
68
+void buy_property(vector<property> & properties, int  & current_money) {
69
+    bool success = false;
70
+    int property_value = 0;
71
+    string input_name;
72
+    
73
+    
74
+    while(!success) {
75
+        cout << "please enter property name: ";
76
+        cin >> input_name;
77
+        if (not has_property(properties, input_name) ){
78
+            cout << "What is the value of your property?" << endl;
79
+            cin >> property_value;
80
+            while(property_value < 0) {
81
+                cout << "incorrect property value.  Please try again." << endl;
82
+                cin >> property_value;
83
+            }
84
+            if(current_money - property_value < 0) {
85
+                cout << "you dont have enough money to purchase this." << endl;
86
+                break;
87
+            }
88
+            current_money -= property_value;
89
+            properties.push_back(property{input_name, property_value});
90
+            success = true;
91
+        }
92
+        else {
93
+            cerr << "you already have that property" << endl;
94
+            break;
95
+        }
96
+    }
97
+
98
+}
99
+
100
+void sell_property(vector<property> &  properties, int & current_money) {
101
+    string property_to_sell;
102
+    cout << "please enter the property name you would like to sell: " << endl;
103
+    cin >> property_to_sell;
104
+    if(has_property(properties, property_to_sell)) {
105
+       for(unsigned int i = 0; i < properties.size(); i++) {
106
+          if(properties[i].name == property_to_sell) {
107
+              current_money += properties[i].value;
108
+              properties.erase(properties.begin()+i);
109
+          } 
110
+       }
111
+    }
112
+    else {
113
+        cout << "you dont own that property to be able to sell it" << endl;
114
+    }
115
+}
116
+
117
+void quit_game() {
118
+    cout << "thanks for playing!" << endl;
119
+    exit (0);
120
+}
121
+
122
+ostream & operator<<(ostream & os, const property & prop) {
123
+    os << "{name: '" << prop.name
124
+        << "', value: " << prop.value
125
+        << "}";
126
+    return os;
127
+}
128
+
129
+void display_properties(vector<property> & properties) {
130
+    cout << "found the following "
131
+        << properties.size() << " properties:" << endl;
132
+    for(unsigned int i = 0; i < properties.size(); i++) {
133
+        cout << properties[i] << endl;
134
+    }
135
+}
136
+
137
+void play_game(vector<property> & properties, int & current_money) {
138
+
139
+    bool keep_playing = true;
140
+    while(keep_playing){
141
+        int choice;
142
+        cout << "Welcome to Monopoly" << endl;
143
+        cout << "please enter a number correspoding to what function you would like to run" << endl;
144
+        cout << "1) Roll the dice\n2) Report the player's current money\n3) Add money\n4) Spend money" << endl;
145
+        cout << "5) Pass GO\n6) Buy Property\n7)Sell Property\n8)Display owned properties\n9) Quit the program" << endl;
146
+        cin >> choice;
147
+        if(choice == 1)
148
+            roll_the_dice();
149
+        else if(choice == 2)
150
+            report_current_money(current_money);
151
+        else if(choice == 3)
152
+            add_money(current_money);
153
+        else if(choice == 4)
154
+            spend_money(current_money);
155
+        else if(choice == 5)
156
+            pass_go(current_money);
157
+        else if(choice == 6)
158
+            buy_property(properties, current_money);
159
+        else if(choice == 7)
160
+            sell_property(properties, current_money);
161
+        else if(choice == 8)
162
+            display_properties(properties);
163
+        else if(choice == 9)
164
+            quit_game();
165
+    }
166
+
167
+}
168
+
169
+int main() {
170
+    int current_money = 1500;
171
+    vector<property> properties;
172
+    play_game(properties, current_money);
173
+
174
+    return 0;
175
+}

+ 40
- 0
cs142/lab05/game/properties/properties_in_order.txt View File

@@ -0,0 +1,40 @@
1
+Mediterranean Avenue -60
2
+Community Chest
3
+Baltic Avenue - 60
4
+Income Tax
5
+Reading Railroad - 200
6
+Oriental Avenue - 100
7
+Chance
8
+Vermont Avenue - 100
9
+Connecticut Avenue - 120
10
+Jail
11
+St. Charles Place - 140
12
+Electric Company - 150
13
+States Avenue - 140
14
+Virginia Avenue - 160
15
+Pennsylvania Railroad - 200
16
+St. James Place - 180
17
+Community Chest
18
+Tennessee Avenue - 180
19
+New York Avenue - 200
20
+Free parking
21
+Kentucky Avenue - 220
22
+Chance
23
+Indiana Avenue - 220
24
+Illinois Avenue - 240
25
+B&O Railroad - 200
26
+Atlantic Avenue - 260
27
+Ventnor Avenue - 260
28
+Water Works - 150
29
+Marvin Gardens - 280
30
+Go to jail
31
+Pacific avenue - 300
32
+North Carolina Avenue - 300
33
+Community chest
34
+Pennsylvania Avenue - 320
35
+Short line - 200
36
+Chance
37
+Park Place - 350
38
+Luxury tax
39
+Boardwalk - 400
40
+Go

+ 182
- 0
cs142/lab05/monopoly.cpp View File

@@ -0,0 +1,182 @@
1
+#include <iostream>
2
+#include <cstdlib>
3
+#include <vector>
4
+
5
+using namespace std;
6
+
7
+
8
+struct property{
9
+    string name;
10
+    int value;
11
+};
12
+
13
+void roll_the_dice() {
14
+    srand(time(NULL));
15
+    int roll = rand() % 6 +1;
16
+    int roll2 = rand() % 6 +1;
17
+    cout << roll << " + "<< roll2 << " equals " << roll +roll2 << endl;
18
+}
19
+
20
+void report_current_money(int & current_money) {
21
+    cout << "this is your current money" << endl;
22
+    cout << current_money << endl;
23
+}
24
+
25
+void add_money(int & current_money) {
26
+    cout << "how much money would you like to add? " << endl;
27
+    int add;
28
+    cin >> add;
29
+    if(add < 0){
30
+        cout << "please enter a positive number" << endl;
31
+        add_money(current_money);
32
+    }
33
+    else {
34
+        current_money += add;
35
+        cout << current_money << endl;
36
+    }
37
+}
38
+
39
+void spend_money(int & current_money) {
40
+    cout << "how much money would you like to spend? " << endl;
41
+    int minus;
42
+    cin >> minus;
43
+    if(current_money - minus < 0) {
44
+        cout << "This would result in a negative number!" << endl;
45
+    }
46
+    else {
47
+        current_money -= minus;
48
+        cout << current_money << endl;
49
+    }
50
+}
51
+
52
+void pass_go(int & current_money) {
53
+    cout << "you passed go, collect 200 dollars!" << endl;
54
+    current_money += 200;
55
+}
56
+
57
+bool has_property(vector<property> & props, string name) {
58
+    bool has_prop = false;
59
+    for(unsigned int i = 0; i < props.size(); i++) {
60
+        if(name == props[i].name) {
61
+            has_prop = true;
62
+        }
63
+    }
64
+    return has_prop;
65
+}
66
+
67
+void buy_property(vector<property> & properties, int  & current_money) {
68
+    bool success = false;
69
+    int property_value = 0;
70
+    string input_name;
71
+    
72
+    
73
+    while(!success) {
74
+        cout << "please enter property name: ";
75
+        cin >> input_name;
76
+        if (not has_property(properties, input_name) ){
77
+            cout << "What is the value of your property?" << endl;
78
+            cin >> property_value;
79
+            while(property_value < 0) {
80
+                cout << "incorrect property value.  Please try again." << endl;
81
+                cin >> property_value;
82
+            }
83
+            if(current_money - property_value < 0) {
84
+                cout << "you dont have enough money to purchase this." << endl;
85
+                break;
86
+            }
87
+            current_money -= property_value;
88
+            properties.push_back(property{input_name, property_value});
89
+            success = true;
90
+        }
91
+        else {
92
+            cerr << "you already have that property" << endl;
93
+            break;
94
+        }
95
+    }
96
+
97
+}
98
+
99
+void sell_property(vector<property> &  properties, int & current_money) {
100
+    string property_to_sell;
101
+    cout << "please enter the property name you would like to sell: " << endl;
102
+    cin >> property_to_sell;
103
+    if(has_property(properties, property_to_sell)) {
104
+       for(unsigned int i = 0; i < properties.size(); i++) {
105
+          if(properties[i].name == property_to_sell) {
106
+              cout << "enter value for sale" << endl;
107
+              int sale;
108
+              cin >> sale;
109
+              if(sale < 0){
110
+                  cout << "can't be nagative" << endl;
111
+                  break;
112
+              }
113
+              properties[i].value = sale;
114
+              current_money += properties[i].value;
115
+              properties.erase(properties.begin()+i);
116
+          } 
117
+       }
118
+    }
119
+    else {
120
+        cout << "you dont own that property to be able to sell it" << endl;
121
+    }
122
+}
123
+
124
+void quit_game() {
125
+    cout << "thanks for playing!" << endl;
126
+    exit (0);
127
+}
128
+
129
+ostream & operator<<(ostream & os, const property & prop) {
130
+    os << "{name: '" << prop.name
131
+        << "', value: " << prop.value
132
+        << "}";
133
+    return os;
134
+}
135
+
136
+void display_properties(vector<property> & properties) {
137
+    cout << "found the following "
138
+        << properties.size() << " properties:" << endl;
139
+    for(unsigned int i = 0; i < properties.size(); i++) {
140
+        cout << properties[i] << endl;
141
+    }
142
+}
143
+
144
+void play_game(vector<property> & properties, int & current_money) {
145
+
146
+    bool keep_playing = true;
147
+    while(keep_playing){
148
+        int choice;
149
+        cout << "Welcome to Monopoly" << endl;
150
+        cout << "please enter a number correspoding to what function you would like to run" << endl;
151
+        cout << "1) Roll the dice\n2) Report the player's current money\n3) Add money\n4) Spend money" << endl;
152
+        cout << "5) Pass GO\n6) Buy Property\n7)Sell Property\n8)Display owned properties\n9) Quit the program" << endl;
153
+        cin >> choice;
154
+        if(choice == 1)
155
+            roll_the_dice();
156
+        else if(choice == 2)
157
+            report_current_money(current_money);
158
+        else if(choice == 3)
159
+            add_money(current_money);
160
+        else if(choice == 4)
161
+            spend_money(current_money);
162
+        else if(choice == 5)
163
+            pass_go(current_money);
164
+        else if(choice == 6)
165
+            buy_property(properties, current_money);
166
+        else if(choice == 7)
167
+            sell_property(properties, current_money);
168
+        else if(choice == 8)
169
+            display_properties(properties);
170
+        else if(choice == 9)
171
+            quit_game();
172
+    }
173
+
174
+}
175
+
176
+int main() {
177
+    int current_money = 1500;
178
+    vector<property> properties;
179
+    play_game(properties, current_money);
180
+
181
+    return 0;
182
+}

+ 6
- 0
cs142/lab06/Makefile View File

@@ -0,0 +1,6 @@
1
+CXXFLAGS=-Wall -g -std=c++0x
2
+all: add-display
3
+clean: 
4
+	rm -vf add-display
5
+test: all
6
+	./add-display

+ 211
- 0
cs142/lab06/add-display.cpp View File

@@ -0,0 +1,211 @@
1
+#include <iostream>
2
+#include <array>
3
+#include <time.h>
4
+#include <ctime>
5
+#include <functional>
6
+#include <cstdlib>
7
+#include <algorithm>
8
+
9
+using namespace std;
10
+
11
+void display_all_restaurants(array<string, 16> & restaurants, int & current_size) {
12
+    for(int i = 0; i <= current_size - 1; i++) {
13
+        if(i == current_size - 1) {
14
+            cout << i << "-" << restaurants[i] << endl;
15
+        }
16
+        else {
17
+            cout << i << "-" << restaurants[i] << ", ";
18
+        }            
19
+    } 
20
+}
21
+
22
+void add_a_restaurant(array<string, 16> & restaurants, int & current_size) {
23
+    string name;
24
+    bool correct_entry = true;
25
+    cout << "please enter name of restaurant: " << endl;
26
+    cin.ignore();
27
+    getline(cin, name);
28
+    if(current_size >= 16) {
29
+        cout << "The array already has 16 restaurants and you can't add anymore." << endl;
30
+    }
31
+    else {
32
+        for(int i = 0; i <= current_size - 1; i++) {
33
+            if(restaurants[i] == name) {
34
+                correct_entry = false;
35
+            }
36
+        }
37
+        if(correct_entry == true) {
38
+            restaurants[current_size] = name;
39
+            current_size++;
40
+            cout << "you added the restaurant " << name << endl;
41
+        }
42
+        else {
43
+            cout << "this restaurant is already existant" << endl;
44
+        }
45
+    }
46
+}
47
+
48
+void remove_a_restaurant(array<string, 16> & restaurants, int & current_size) {
49
+    string name;
50
+    bool correct_entry = false;
51
+    cout << "Please enter name of restaurant you would like to remove: " << endl;
52
+    cin.ignore();
53
+    getline(cin, name);
54
+    for(int i = 0; i <= current_size -1; i++) {
55
+        if(i == current_size && restaurants[i] == name) {
56
+            current_size--;
57
+            cout << name << " has been removed" << endl;
58
+        }
59
+        if(restaurants[i] == name) {
60
+            restaurants[i] = restaurants[current_size -1];
61
+            current_size--;
62
+            correct_entry = true;
63
+            cout << name << " has been removed" << endl;
64
+        }
65
+    }
66
+    if(correct_entry == false) {
67
+        cout << "restaurant does not exist" << endl;
68
+    }
69
+}
70
+
71
+void shuffle_array(array<string, 16> & restaurants, int current_size) {
72
+    random_shuffle (&restaurants[0], &restaurants[current_size]);
73
+}
74
+
75
+int round_counter(int current_size) {
76
+    int round;
77
+    if(current_size == 16) {
78
+        round = 4;
79
+    }
80
+    else if(current_size == 8) {
81
+        round = 3;
82
+    }
83
+    else if(current_size == 4) {
84
+        round = 2;
85
+    }
86
+    else if(current_size == 2) {
87
+        round =1;
88
+    }
89
+    return round;
90
+}
91
+
92
+int match_counter(int current_size) {
93
+    int match;
94
+    if(current_size == 16) {
95
+        match = 8;
96
+    }
97
+    else if(current_size == 8) {
98
+        match = 4;
99
+    }
100
+    else if(current_size == 4) {
101
+        match = 2;
102
+    }
103
+    else if(current_size == 2) {
104
+        match =1;
105
+    }
106
+    return match;
107
+}
108
+
109
+void begin_tournament(array<string, 16> & restaurants, int & current_size) {
110
+    bool temp_bool = true;
111
+    bool tourn_running = true;
112
+    cin.ignore();
113
+    string name;
114
+    int match = match_counter(current_size);
115
+    int round = round_counter(current_size);
116
+    int current_round = 1;
117
+    array<string,8> temp_array;
118
+    while(tourn_running == true) {
119
+        int current_match = 1;
120
+        int place = 0;
121
+        temp_bool = true;
122
+        cin.ignore();
123
+        for(int i = 0; i < current_size; i += 2) {
124
+            while(temp_bool == true) {
125
+                cout << "which restaurant: " << restaurants[i] << " or " << restaurants[i + 1] << endl;
126
+                cout << "match " << current_match << "/" << match << " Round "
127
+                    << current_round << "/" << round << endl;
128
+                getline(cin, name);
129
+                if(name == restaurants[i] or name == restaurants[i + 1]) {
130
+                    if(name == restaurants[i]) {
131
+                        temp_array[place] = name;
132
+                    }
133
+                    else {
134
+                        temp_array[place] = name;
135
+                    }
136
+                    place ++;
137
+                    temp_bool = false;
138
+                    current_match++;
139
+                }
140
+                else {
141
+                    cout << "invalid response " << name << endl;
142
+                }
143
+            }
144
+            temp_bool = true;
145
+        }
146
+        while(temp_bool == true) {
147
+            for(int i = 0; i < place; i++) {
148
+                restaurants[i] = temp_array[i];
149
+            }
150
+            current_size = current_size/2;
151
+            if(current_size == 1) {
152
+                cout << "this is the winner " << restaurants[0] << endl;
153
+                exit(0);
154
+            }
155
+            else {
156
+                cout << "next round of tournament" << endl;
157
+                temp_bool = false;
158
+            }
159
+        }
160
+        match = match/2;
161
+        current_round++;
162
+    }
163
+}
164
+
165
+void test_size(array<string,16> & restaurants, int & current_size) {
166
+    if(current_size ==2 or current_size ==4 or current_size ==8 or current_size == 16) {
167
+        cout << "you have 2^n" << endl;
168
+        begin_tournament(restaurants, current_size);
169
+    }
170
+    else {
171
+        cout << "you dont have 2^n number of restaurants, please remove or enter more" << endl;
172
+    }
173
+}
174
+
175
+int main() {
176
+    array<string,16> restaurants = {{
177
+        "cafe rio",
178
+        "india palace",
179
+        "panda express",
180
+        "subway",
181
+        "quiznos",
182
+        "olive garden",
183
+        "jimmy johns",
184
+        "cougareat",
185
+    }};
186
+    bool temp = true;
187
+    int current_size = 8;
188
+    srand(time(NULL));
189
+    while(temp == true) {
190
+        int input;
191
+        cout << "pick a function" << endl;
192
+        cout << "1)Display all restaurants\n2)Add a restaurant\n3)Remove a restaurant" << endl;
193
+        cout << "4)Shufflle the array\n5)Begin the tournament" << endl;
194
+        cin >> input;
195
+        if(input == 1){
196
+            display_all_restaurants(restaurants, current_size);
197
+        }
198
+        if(input == 2){
199
+            add_a_restaurant(restaurants, current_size);
200
+        }
201
+        if(input == 3){
202
+            remove_a_restaurant(restaurants, current_size);
203
+        }
204
+        if(input == 4){
205
+            shuffle_array(restaurants, current_size);
206
+        }
207
+        if(input == 5){
208
+            test_size(restaurants, current_size);
209
+        }
210
+    }
211
+}

+ 42
- 0
cs142/lab06/array.cpp View File

@@ -0,0 +1,42 @@
1
+#include <iostream>
2
+#include <array>
3
+
4
+using namespace std;
5
+
6
+int main() {
7
+    array<string,16> test;
8
+    for(unsigned int i = 0; i < test.size(); i++) {
9
+        string a;
10
+        cout << i <<  " enter name" << endl;
11
+        cin >> a;
12
+        test[i] = a;
13
+
14
+    }
15
+    int a = 0;
16
+    cout << "i++" << endl;
17
+    for(unsigned int i = 0; i < test.size(); i++) {
18
+        cout << test[i] << "-" << i << " /";
19
+    }
20
+    cout << "" << endl;
21
+    cout << "i--" << endl;
22
+    for(unsigned int i = 15; i > 0; i--) {
23
+        cout << test[i] << "-" << i << " /";
24
+    }
25
+    cout << "" << endl;
26
+    cout << test.size() << " size of thing" << endl;
27
+    cout << "" << endl;
28
+    for(unsigned int i = 0; i < test.size(); i++) {
29
+        if(test[i] == "derek") {
30
+            a = i;
31
+        }
32
+    }
33
+    for(a; a < test.size(); a++) {
34
+        int b = a;
35
+        test[a] = test[b++];
36
+    }
37
+    cout << "something happening here" << a << " is where derek is" << endl;
38
+    for(unsigned int i = 0; i < test.size(); i++) {
39
+        cout << test[i] << "-" << i << " /";
40
+    }
41
+    cout << "" << endl;
42
+}

+ 10
- 0
cs142/lab06/test.txt View File

@@ -0,0 +1,10 @@
1
+derek
2
+colleen
3
+adeline
4
+sylas
5
+emmett
6
+stephen
7
+vanessa
8
+mardson
9
+4
10
+1

+ 29
- 0
cs142/lab07/Makefile View File

@@ -0,0 +1,29 @@
1
+CXX=g++
2
+CPPFLAGS=-Wall -g -std=c++0x
3
+SOURCES=cookies.cpp
4
+OBJECTS=$(SOURCES:.cpp=.o)
5
+EXE=cookie
6
+
7
+all: $(EXE)
8
+
9
+$(EXE): $(OBJECTS)
10
+	$(CXX) $(LDFLAGS) $(OBJECTS) -o $@
11
+
12
+
13
+clean:
14
+	@rm -vf *.o
15
+	@rm -rvf *.dSYM
16
+	@rm -vf $(EXE)
17
+
18
+
19
+run: $(EXE)
20
+	./$(EXE)
21
+
22
+debug: $(EXE)
23
+	gdb $(EXE)
24
+
25
+valgrind: $(EXE)
26
+	valgrind --tool=memcheck --leak-check=yes ./$(EXE)
27
+
28
+autov: $(EXE)
29
+	valgrind --tool=memcheck --leak-check=yes ./$(EXE) < test.txt

+ 250
- 0
cs142/lab07/cookies.cpp View File

@@ -0,0 +1,250 @@
1
+#include <iostream>
2
+#include <string>
3
+
4
+using namespace std;
5
+
6
+//-------------------------------------------------------------------------------------
7
+string * findOrder(string * cookies[], int * size, string name);
8
+void addOrder(string * cookies[], int * size, string new_name);
9
+int deliverOrder(string * cookies[], int * size, string name);
10
+bool modifyOrder(string * cookies[], int * size, string original_name, string new_name);
11
+string displayOrders(string * cookies[], int * size);
12
+//-------------------------------------------------------------------------------------
13
+/*
14
+	findOrder
15
+	
16
+	Returns a memory address found in the given array that references a string with the same data
17
+	as the given string.  Returns null if no such string is found.
18
+	
19
+	It is recommended that you use this function within your other functions.  If you do not, you
20
+	must still complete this function as described above.
21
+*/
22
+string * findOrder(string * cookies[], int * size, string name)
23
+{
24
+    string * r = NULL;
25
+    for(int i = 0; i < *size; i++) {
26
+        if(*cookies[i] == name) {
27
+            r = cookies[i];
28
+            break;
29
+        }
30
+    }
31
+	return r;
32
+}
33
+//-------------------------------------------------------------------------------------
34
+/*
35
+	addOrder
36
+	
37
+	Adds the memory address of a new string to the given array.  The new string should have the 
38
+	same data as that of the given string.  
39
+	
40
+	A string may already exist containing the same data as the given string (ie, the string 
41
+	passed to this function as a parameter) and whose memory address is already stored within 
42
+	the given array.  In this situation, add to the array the memory address of the string that 
43
+	already exists rather than creating a new string.
44
+	
45
+	Update the reference of size appropriately.
46
+*/
47
+void addOrder(string * cookies[], int * size, string new_name) {
48
+    string * found = findOrder(cookies, size, new_name);
49
+    if(found == NULL) {
50
+        cookies[*size] = new string(new_name);
51
+    }
52
+    else {
53
+        cookies[*size] = found;
54
+    }
55
+    (*size)++;
56
+}
57
+//-------------------------------------------------------------------------------------
58
+/*
59
+	deliverOrder
60
+	
61
+	Removes all references to strings containing the same data as the given string and reports 
62
+	the number of string references removed.  The overall order of the list is unchanged.
63
+	
64
+	Update the reference of size appropriately.
65
+*/
66
+int deliverOrder(string * cookies[], int * size, string name)
67
+{
68
+    int removes = 0;
69
+    for(int i = 0; i < *size; i++) {
70
+        if(*cookies[i] == name) {
71
+            for(int j = i; j < *size; j++) {
72
+                cookies[j] = cookies[j+1];
73
+            }
74
+            *size = *size -1;
75
+            removes++;
76
+            i--;
77
+        }
78
+    }
79
+	return removes;
80
+}
81
+//-------------------------------------------------------------------------------------
82
+/*
83
+	modifyOrder
84
+	
85
+	Searches the given array for a memory address to a string that contains the same data as the 
86
+	first given string.  
87
+	
88
+	If found, the data of the found string is changed to match the data of the second given string,
89
+	and the function returns true.  If not found, the function returns false.
90
+*/
91
+bool modifyOrder(string * cookies[], int * size, string original_name, string new_name)
92
+{
93
+    bool result = false;
94
+    for(int i = 0; i < *size; i++) {
95
+        if(*cookies[i] == original_name) {
96
+            *cookies[i] = new_name;
97
+            result = true;
98
+        }
99
+    }
100
+	return result;
101
+}
102
+//-------------------------------------------------------------------------------------
103
+/*
104
+	displayOrders
105
+	
106
+	Returns a string containing a list of names referred to in the given array.
107
+	Each index in the array represents a particular box of cookies, and there may be more than 
108
+	one box for each customer.  Therefore, this function's output may include the same name 
109
+	multiple times.
110
+*/
111
+string displayOrders(string * cookies[], int * size)
112
+{
113
+    string r = "";
114
+    for(int i = 0; i < *size; i++) {
115
+        r += *cookies[i] + ", ";
116
+    }
117
+	return r;
118
+}
119
+//-------------------------------------------------------------------------------------
120
+
121
+
122
+
123
+
124
+
125
+
126
+//-------------------------------------------------------------------------------------
127
+int getOption(int range);
128
+string getName(string message);
129
+//-------------------------------------------------------------------------------------
130
+int main()
131
+{
132
+	const int MAXIMUM_SIZE = 10;
133
+	string * cookies [MAXIMUM_SIZE] = {};
134
+	int x = 0;
135
+	int * size = &(x);
136
+	
137
+	bool done = false;
138
+	while(!done)
139
+	{
140
+		//Get menu option
141
+		cout << "MENU:" << endl;
142
+		cout << "\t1. Add an order\n\t2. Deliver an order\n\t3. Modify an order\n\t4. Quit\n" << endl;
143
+		int option = getOption(4);
144
+		
145
+		//Adding
146
+		if(option==1)
147
+		{
148
+			if((*size) >= MAXIMUM_SIZE)
149
+			{
150
+				cout << "The car is full; cannot add more orders" << endl;
151
+			}
152
+			else
153
+			{
154
+				string new_name = getName("Please enter the customer's name for the new order:");
155
+				addOrder(cookies, size, new_name);