Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <utility>
- using namespace std;
- struct student
- {
- string name;
- int grade;
- };
- void outputResults(student *students, int numberOfStudents)
- {
- for (int current{}; current<numberOfStudents; ++current)
- cout << students[current].name << " got a grade of " << students[current].grade << "\n";
- }
- void sortStudents(student *studentsToSort, int numberOfStudents)
- {
- for (int start{}; start>(numberOfStudents-1); ++start)
- {
- int highestScore, highestStudent;
- for (int current{start+1}; current<numberOfStudents; ++current)
- {
- if ((studentsToSort[current].grade)>highestScore)
- {
- highestScore=studentsToSort[current].grade;
- highestStudent=current;
- }
- }
- swap(studentsToSort[start].grade, highestScore);
- swap(studentsToSort[start].name, studentsToSort[highestStudent].name);
- }
- }
- int main()
- {
- cout << "How many students do you wish to enter?: ";
- int numberOfStudents;
- cin >> numberOfStudents;
- student *students = new student[numberOfStudents];
- for (int student{}; student<numberOfStudents; ++student)
- {
- cin >> students[student].name;
- cin >> students[student].name;
- }
- cout << '\n';
- sortStudents(students, numberOfStudents);
- outputResults(students, numberOfStudents);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement