Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. #include <sstream>
  7.  
  8.  
  9. using namespace std;
  10.  
  11.  
  12.  
  13.  
  14. class Section {
  15. private:
  16. string name;
  17. string day;
  18. int hour;
  19.  
  20. vector<string> students;
  21. vector<vector<int>> grades;
  22. public:
  23. Section(string _name, string _day, int _hour) {
  24. name = _name;
  25. day = _day;
  26. hour = _hour;
  27. }
  28.  
  29. void set_name(string _name){
  30. name = _name;
  31. }
  32.  
  33.  
  34. void set_day(string _day){
  35. day = _day;
  36. }
  37.  
  38.  
  39. void set_hour(int _hour){
  40. hour = _hour;
  41. }
  42.  
  43.  
  44. void addStudent(string _name){
  45. students.push_back(_name);
  46. //also push back an array of 13 -1 ints
  47. vector<int> default_grades;
  48. for (int x = 0; x < 13; x++){
  49. default_grades.push_back(-1);
  50. }
  51. grades.push_back(default_grades);
  52. }
  53.  
  54.  
  55. string get_day(){
  56. return day;
  57. }
  58.  
  59. int get_hour(){
  60. return hour;
  61. }
  62.  
  63. string get_name(){
  64. return name;
  65. }
  66.  
  67.  
  68. string print(){
  69. return name + " " + day;
  70. }
  71.  
  72.  
  73. vector<string> get_students(){
  74. return students;
  75. }
  76.  
  77.  
  78. vector<int> get_grades(int index){
  79. return grades[index];
  80. }
  81.  
  82.  
  83. void reset(){
  84. students.clear();
  85. grades.clear();
  86.  
  87. }
  88.  
  89.  
  90. void insert_grade(int _index, int _grade, int _week){
  91. grades[_index][_week] = _index;
  92. }
  93.  
  94.  
  95. void addStudent(string _name, int _grade, int _week){
  96. //find the index of the user with this name
  97.  
  98. }
  99.  
  100.  
  101.  
  102. void display(){
  103. string am_pm = "am";
  104. if (hour > 12){
  105. hour -= 12;
  106. am_pm = "pm";
  107. }
  108. cout << "Section: " + name + "; " + day + " " + to_string(hour) + am_pm << endl;
  109. }
  110.  
  111.  
  112.  
  113. };
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. class LabWorker {
  124. private:
  125. string name;
  126. Section *section;
  127. public:
  128.  
  129. LabWorker(string _name){
  130. name = _name;
  131. }
  132.  
  133. void set_name(string _name){
  134. name = _name;
  135. }
  136.  
  137.  
  138. string get_name(){
  139. return name;
  140. }
  141.  
  142.  
  143. void addSection(Section *_section){
  144. section = _section;
  145. }
  146.  
  147.  
  148. bool addGrade(string _name, int _grade, int _week){
  149. vector<string> students = section->get_students();
  150. for (int x = 0; x < section->get_students().size(); x++){
  151. string student_name = students[x];
  152. if (student_name == _name){
  153. section->insert_grade(x, _grade, _week);
  154. return true;
  155. }
  156. }
  157. //If code gets here, user is not in list
  158. return false;
  159. }
  160.  
  161.  
  162.  
  163.  
  164. void displayGrades(){
  165.  
  166. //Student: John; Grades: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
  167. vector<string> students = section->get_students();
  168. for (int y = 0; y < students.size(); y++){
  169. string student = students[y];
  170. vector<int> grades = section->get_grades(y);
  171. string grade_string = "";
  172. //convert int vector to string
  173. for (int i = 0; i < grades.size(); i++){
  174. grade_string += to_string(grades[i]) + " ";
  175. }
  176.  
  177. cout << "Student: " + student + " Grades: " + grade_string << endl;
  178.  
  179. }
  180. }
  181. };
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189. int main() {
  190.  
  191. // lab workers
  192. LabWorker moe("Moe");
  193. LabWorker jane("Jane");
  194.  
  195.  
  196. //cout << moe.to_string() << endl;
  197.  
  198. //// sections and setup and testing
  199. Section secA2("A2", "Tuesday", 16);
  200. //secA2.loadStudentsFromFile( "A2.txt" );
  201. secA2.addStudent("John");
  202. secA2.addStudent("George");
  203. secA2.addStudent("Paul");
  204. secA2.addStudent("Ringo");
  205.  
  206. cout << "\ntest A2\n"; // here the modeler-programmer checks that load worked
  207. secA2.display(); // YOU'll DO THIS LATER AS: cout << secA2 << endl;
  208. moe.addSection(&secA2);
  209. moe.displayGrades(); // here the modeler-programmer checks that adding the Section worked
  210.  
  211. Section secB3("B3", "Thursday", 11);
  212. //secB3.loadStudentsFromFile( "B3.txt" );
  213. secB3.addStudent("Thorin");
  214. secB3.addStudent("Dwalin");
  215. secB3.addStudent("Balin");
  216. secB3.addStudent("Kili");
  217. secB3.addStudent("Fili");
  218. secB3.addStudent("Dori");
  219. secB3.addStudent("Nori");
  220. secB3.addStudent("Ori");
  221. secB3.addStudent("Oin");
  222. secB3.addStudent("Gloin");
  223. secB3.addStudent("Bifur");
  224. secB3.addStudent("Bofur");
  225. secB3.addStudent("Bombur");
  226.  
  227. cout << "\ntest B3\n"; // here the modeler-programmer checks that load worked
  228. secB3.display(); // YOU'll DO THIS LATER AS: cout << secB3 << endl;
  229. jane.addSection(&secB3);
  230. jane.displayGrades(); // here the modeler-programmer checks that adding Instructor worked
  231.  
  232.  
  233. // setup is complete, now a real world scenario can be written in the code
  234. // [NOTE: the modeler-programmer is only modeling joe's actions for the rest of the program]
  235.  
  236. // week one activities
  237. cout << "\nModeling week: 1\n";
  238. moe.addGrade("John", 7, 1);
  239. moe.addGrade("Paul", 9, 1);
  240. moe.addGrade("George", 7, 1);
  241. moe.addGrade("Ringo", 7, 1);
  242. cout << "End of week one\n";
  243. moe.displayGrades();
  244.  
  245. // week two activities
  246. cout << "\nModeling week: 2\n";
  247. moe.addGrade("John", 5, 2);
  248. moe.addGrade("Paul", 10, 2);
  249. moe.addGrade("Ringo", 0, 2);
  250. cout << "End of week two\n";
  251. moe.displayGrades();
  252.  
  253. //test that reset works // NOTE: can we check that the heap data was dealt with?
  254. cout << "\ntesting reset()\n";
  255. secA2.reset();
  256. secA2.display();
  257. moe.displayGrades();
  258.  
  259.  
  260. system("pause");
  261.  
  262. } // main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement