Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include<list>
- #include<algorithm>
- using namespace std;
- class Student {
- private:
- int note;
- string name;
- public:
- Student(int note = 0, string name = "Joe Doe") {
- this->note = note;
- this->name = name;
- }
- void setNote(int n) {
- this->note = n;
- }
- int getNote() {
- return this->note;
- }
- string getName() {
- return this->name;
- }
- void setName(string name) {
- this->name = name;
- }
- bool operator<(const Student &other) {
- return (name<other.name);
- }
- };
- class StudentsGroup {
- private:
- list<Student>StudentList;
- public:
- void showStudentsInGroup() {
- for (auto current_student : StudentList)
- cout << "Name: " << current_student.getName() << " Grade:" << current_student.getNote() << endl;
- }
- void readStudentGroup() {
- int note;
- string studentName;
- cin >> studentName;
- cin >> note;
- Student current_student(note, studentName);
- StudentList.push_back(current_student);
- }
- void sort_list() {
- cout << "The list of students after sorting:" << endl;
- //sort(StudentList.begin(), StudentList.end());
- StudentList.sort();
- }
- };
- int main()
- {
- StudentsGroup *studentsGroup = new StudentsGroup;
- int user_choice;
- while (1) {
- cin >> user_choice;
- if (user_choice == 1) {
- studentsGroup->readStudentGroup();
- studentsGroup->sort_list();
- studentsGroup->showStudentsInGroup();
- }
- else
- break;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement