Advertisement
Guest User

hw

a guest
Feb 19th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. //HW3
  2. //Due: 11:59PM, February 21 (Friday)
  3.  
  4. #include <iostream>
  5. #include <list>
  6. #include <map>
  7. #include <string>
  8. using namespace std;
  9.  
  10. class course {
  11. public:
  12. string name;
  13. int section;
  14. int credits;
  15. string grade;
  16. course() {}
  17. course(string n, int s, int c, string g) { name = n; section = s; credits = c; grade = g; }
  18.  
  19. //You might need to implement some overloaded operators here.
  20.  
  21. };
  22. //Implement the following functions.
  23. //When adding a student, if the student is already in DB, then ignore the operation.
  24. //When adding a course, if the course is already in DB, then ignore the operation.
  25. //When dropping a course, if the course does not exist, then ignore the operation.
  26. //When removing a student, if the student does not exist, then ignore the operation.
  27. //All courses in a semester need to be sorted.
  28. //When dropping or adding a course, overall GPA, semester GPA, overall credits and semester credits all need to be updated.
  29.  
  30. //Semeser numbers: Spring 2019: 20191; Fall 2019: 20192, etc.
  31.  
  32. void add_student(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int id);
  33. void remove_student(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int id);
  34. void add_course(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int semester, int id, course c); //20171 Spring semester of 2017; 20172: Fall semester of 2017
  35. //All courses in the list should be sorted according to name (increasing order)
  36. void drop_course(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int semester, int id, course c);
  37. void print_student_semester_courses(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int semester, int id);
  38. void print_student_all_courses(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int id);
  39.  
  40. //Implement additional functions such that you can do
  41. //cout << DB << endl;
  42.  
  43. //You might need to implement some overloaded operators in the course class.
  44.  
  45. int main() {
  46. map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*> DB;
  47.  
  48. add_student(DB, 11111);
  49. course C1("CIS554", 1, 3, "A-"), C2("CSE674", 1, 3, "B+"), C3("MAT296", 8, 4, "A"), C4("WRT205", 5, 3, "A");
  50.  
  51. add_course(DB, 20171, 11111, C1);
  52. add_course(DB, 20171, 11111, C4);
  53. add_course(DB, 20171, 11111, C3);
  54. add_course(DB, 20171, 11111, C2);
  55. print_student_semester_courses(DB, 20171, 11111);
  56.  
  57. drop_course(DB, 20171, 11111, C1);
  58. print_student_semester_courses(DB, 20171, 11111); //sorted according to course name
  59.  
  60. course C5("CIS351", 2, 3, "A-"), C6("PSY205", 5, 3, "B+"), C7("MAT331", 2, 3, "A"), C8("ECN203", 4, 3, "A");
  61. add_course(DB, 20172, 11111, C5);
  62. add_course(DB, 20172, 11111, C6);
  63. add_course(DB, 20172, 11111, C7);
  64. add_course(DB, 20172, 11111, C8);
  65. add_course(DB, 20172, 11111, C3);
  66. print_student_all_courses(DB, 11111);//ID GPA
  67.  
  68. add_student(DB, 11112);
  69. add_course(DB, 20171, 11112, C2);
  70. add_course(DB, 20171, 11112, C5);
  71. add_course(DB, 20171, 11112, C7);
  72. add_course(DB, 20171, 11112, C4);
  73. print_student_semester_courses(DB, 20171, 11112);
  74.  
  75. add_course(DB, 20172, 11112, C8);
  76. add_course(DB, 20172, 11112, C3);
  77. add_course(DB, 20172, 11112, C5);
  78. add_course(DB, 20172, 11112, C1);
  79. print_student_semester_courses(DB, 20172, 11112);
  80.  
  81. print_student_all_courses(DB, 11112);
  82.  
  83. cout << DB << endl;
  84. remove_student(DB, 11111);
  85. cout << DB << endl;
  86. getchar();
  87. getchar();
  88. return 0;
  89. }
  90. //map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>
  91. //
  92. void add_student(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int id) {
  93. if (DB.find(id) != DB.end())return;
  94. tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>* overall = new tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>;
  95. map<int, tuple<int, float, list<course*>*>>* semesterCollection = new map<int, tuple<int, float, list<course*>*>>;
  96. get<2>(*overall) = semesterCollection;
  97. DB[id] = overall;
  98. }
  99. void remove_student(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int id) {
  100. if (DB.find(id) != DB.end()) {
  101.  
  102.  
  103.  
  104. }
  105.  
  106. return;
  107. }
  108.  
  109. void add_course(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int semester, int id, course c) {
  110. if (DB.find(id) != DB.end()) {
  111. auto overall = DB.find(id);
  112. tuple<int, float, list<course*>*> classes = new tuple<int, float, list<course*>*>;
  113. get<2>(*semesterCollection) = classes;
  114. list<course*> eachClass = new list<course*>*;
  115. }return;
  116. //comparator sort overload the course
  117. }
  118.  
  119. void drop_course(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int semester, int id, course c) {
  120. if (DB.find(id) != DB.end()) {
  121. map<int, tuple<int, float, list<course*>*>>* semester = new map<int, tuple<int, float, list<course*>*>>;
  122. tuple<int, float, list<course*>*> classes = new tuple<int, float, list<course*>*>;
  123. list<course*>* eachClass = new list<course*>*;
  124. }return;
  125. }
  126.  
  127. void print_student_semester_courses(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int semester, int id) {
  128.  
  129. }
  130. void print_student_all_courses(map<int, tuple<int, float, map<int, tuple<int, float, list<course*>*> >*>*>& DB, int id) {
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement