in c++ i have some code how should i pass the the struct Students to the function sortByPointTotal so that i can access that struct and edit it and sort the struct #include #include using namespace std; struct Student { string firstName, lastName; int pointTotal; }; 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; } sortByPointTotal() { } int main() { const int NUMSTUDENTS = 8; 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; }
in c++
i have some code how should i pass the the struct Students to the function sortByPointTotal so that i can access that struct and edit it and sort the struct
#include <string>
#include <iostream>
using namespace std;
struct Student {
string firstName, lastName;
int pointTotal;
};
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;
}
sortByPointTotal() {
}
int main() {
const int NUMSTUDENTS = 8;
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;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps