how would i make a function that uses a modified bubble sort that the comparison for out-of-order elements takes into account all three fields: totalPoints, lastName and firstName, in decreasing order of importance.  In other words... sort by totalPoints as the primary criterion and put bigger point totals before smaller point totals.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

in c++

if i have a struct 

struct Student {
    string firstName, lastName;
    int pointTotal;
};

 

and the code in the first image

 

how would i make a function that uses a modified bubble sort that the comparison for out-of-order elements takes into account all three fields: totalPoints, lastName and firstName, in decreasing order of importance.  In other words... sort by totalPoints as the primary criterion and put bigger point totals before smaller point totals. Then among students with the same totalPoints, sort by lastName, putting students with an alphabetically smaller last name before students with an alphabetically bigger last name. Finally among students with the same totalPoints and lastName, sort by firstName, again in ascending order. and the output should look like the second image

void printStudent (const Student & s) {
cout <« s.pointTotal <« "\t" << s.lastName << ", " « s.firstName << endl;
}
void printAll(Student students[], int numStudents) {
for (int i = 0; i < numStudents; i++)
printStudent (students[i]);
cout <« endl;
}
int main() {
const int NUMSTUDENTS = 7;
Student students [NUMSTUDENTS] = {
{"Brian", "Jones", 45},{"Edith", "Piaf", 45},
{"Jacques", "Brel", 64}, {"Anna", "Brel", 64},
{"Carmen", "Jones", 45} , {"Carmen", "Brel", 64},
{"Antoine", "Piaf", 45}, {"Pascal", "Piaf", 64} };
printAll(students, NUMSTUDENTS);
sortByPointTotal(students, NUMSTUDENTS);
printAll(students, NUMSTUDENTS);
return 0;
Transcribed Image Text:void printStudent (const Student & s) { cout <« s.pointTotal <« "\t" << s.lastName << ", " « s.firstName << endl; } void printAll(Student students[], int numStudents) { for (int i = 0; i < numStudents; i++) printStudent (students[i]); cout <« endl; } int main() { const int NUMSTUDENTS = 7; Student students [NUMSTUDENTS] = { {"Brian", "Jones", 45},{"Edith", "Piaf", 45}, {"Jacques", "Brel", 64}, {"Anna", "Brel", 64}, {"Carmen", "Jones", 45} , {"Carmen", "Brel", 64}, {"Antoine", "Piaf", 45}, {"Pascal", "Piaf", 64} }; printAll(students, NUMSTUDENTS); sortByPointTotal(students, NUMSTUDENTS); printAll(students, NUMSTUDENTS); return 0;
Jones, Brian
Piaf, Edith
Brel, Jacques
Brel, Anna
Jones, Carmen
Brel, Carmen
Piaf, Antoine
Piaf, Pascal
45
45
64
64
45
64
45
64
Brel, Anna
Brel, Carmen
Brel, Jacques
Piaf, Pascal
Jones, Brian
Jones, Carmen
Piaf, Antoine
Piaf, Edith
64
64
64
64
45
45
45
45
Transcribed Image Text:Jones, Brian Piaf, Edith Brel, Jacques Brel, Anna Jones, Carmen Brel, Carmen Piaf, Antoine Piaf, Pascal 45 45 64 64 45 64 45 64 Brel, Anna Brel, Carmen Brel, Jacques Piaf, Pascal Jones, Brian Jones, Carmen Piaf, Antoine Piaf, Edith 64 64 64 64 45 45 45 45
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY