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; }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section: Chapter Questions
Problem 1PP
icon
Related questions
Question

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;

}

 

1
Q#include <string>
#include <iostream>
3
4.
5
using namespace std;
7
Estruct Student {
string firstName, lastName;
int pointTotal;
[};
8.
9
10
11
12
Evoid printstudent (const Student& s) {
cout <« s.pointTotal << "\t" <« s.lastName <« ",
« s.firstName « endl;
13
14
15
Evoid printAl1(Student students[], int numStudents) {
for (int i = 0; i < numStudents; i++)
printStudent(students[i]);
cout << endl;
16
17
18
19
20
e sortByPointTotal() {
21
22
23
24
Bint main() {
25
const int NUMSTUDENTS = 8;
Student students[NUMSTUDENTS] = {
26
{"Brian", "Jones", 45},{"Edith", "Piaf", 45},
{"Jacques", "Brel", 64},{"Anna", "Brel", 64},
{"Carmen", "Jones", 45} , {"Carmen", "Brel", 64},
{"Antoine", "Piaf", 45}, {"Pascal", "Piaf", 64} };
27
28
29
30
printAll(students, NUMSTUDENTS);
sortByPointTotal(students, NUMSTUDENTS);
printAll(students, NUMSTUDENTS);
31
32
33
34
35
return 0;
36
37
38
39
Transcribed Image Text:1 Q#include <string> #include <iostream> 3 4. 5 using namespace std; 7 Estruct Student { string firstName, lastName; int pointTotal; [}; 8. 9 10 11 12 Evoid printstudent (const Student& s) { cout <« s.pointTotal << "\t" <« s.lastName <« ", « s.firstName « endl; 13 14 15 Evoid printAl1(Student students[], int numStudents) { for (int i = 0; i < numStudents; i++) printStudent(students[i]); cout << endl; 16 17 18 19 20 e sortByPointTotal() { 21 22 23 24 Bint main() { 25 const int NUMSTUDENTS = 8; Student students[NUMSTUDENTS] = { 26 {"Brian", "Jones", 45},{"Edith", "Piaf", 45}, {"Jacques", "Brel", 64},{"Anna", "Brel", 64}, {"Carmen", "Jones", 45} , {"Carmen", "Brel", 64}, {"Antoine", "Piaf", 45}, {"Pascal", "Piaf", 64} }; 27 28 29 30 printAll(students, NUMSTUDENTS); sortByPointTotal(students, NUMSTUDENTS); printAll(students, NUMSTUDENTS); 31 32 33 34 35 return 0; 36 37 38 39
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr