Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include<list>
  4. #include<algorithm>
  5. using namespace std;
  6. class Student {
  7. private:
  8. int note;
  9. string name;
  10. public:
  11. Student(int note = 0, string name = "Joe Doe") {
  12. this->note = note;
  13. this->name = name;
  14. }
  15. void setNote(int n) {
  16. this->note = n;
  17. }
  18. int getNote() {
  19. return this->note;
  20. }
  21. string getName() {
  22. return this->name;
  23. }
  24. void setName(string name) {
  25. this->name = name;
  26. }
  27. bool operator<(const Student &other) {
  28. return (name<other.name);
  29. }
  30.  
  31. };
  32. class StudentsGroup {
  33. private:
  34. list<Student>StudentList;
  35. public:
  36. void showStudentsInGroup() {
  37. for (auto current_student : StudentList)
  38. cout << "Name: " << current_student.getName() << " Grade:" << current_student.getNote() << endl;
  39. }
  40. void readStudentGroup() {
  41. int note;
  42. string studentName;
  43. cin >> studentName;
  44. cin >> note;
  45. Student current_student(note, studentName);
  46. StudentList.push_back(current_student);
  47. }
  48. void sort_list() {
  49. cout << "The list of students after sorting:" << endl;
  50. //sort(StudentList.begin(), StudentList.end());
  51. StudentList.sort();
  52. }
  53.  
  54. };
  55. int main()
  56. {
  57. StudentsGroup *studentsGroup = new StudentsGroup;
  58. int user_choice;
  59. while (1) {
  60. cin >> user_choice;
  61. if (user_choice == 1) {
  62. studentsGroup->readStudentGroup();
  63. studentsGroup->sort_list();
  64. studentsGroup->showStudentsInGroup();
  65. }
  66. else
  67. break;
  68. }
  69. system("pause");
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement