answersLogoWhite

0

Create a class to represent a student:

struct student {

string fname;

string lname;

unsigned age;

unsigned id;

};

Overload operator< to compare two student objects:

bool operator< (const student& a, const student& b) {

return a.lname<b.lname;

}

Overload std::ostream::operator<< to print a student:

std::ostream& operator<< (std::ostream& os, const student& s) {

return os << s.fname << ' ' << s.lname << ' ' << s.age << ' ' << s.id;

}

Now you can write your program:

int main() {

std::vector<student> v;

for (unsigned count=0; count<100;) {

student s;

std::cout << "Enter details for student #" << ++count;

std::cout << "First name: ";

std::cin >> s.fname; std::cout << "Last name: ";

std::cin >> s.lname;

std::cout << "Age: ";

std::cin >> s.age;

std::cout << "ID: ";

std::cin >> s.id;

v.push_back (s);

}

std::cout << "Sorting..."

std::sort (v.begin(), v.end());

std::cout << "\n\n";

// Print students...

for (auto s : v) std::cout << s << std::endl;

}

User Avatar

Wiki User

9y ago

What else can I help you with?

Related Questions

How do you start the display program in Linux from the command line?

the command "display" brings up the ImageMagick program.


What is the average masters GPA of students in your program?

The average GPA of students in our program is 3.5.


When was Victorian Students' Aid Program created?

Victorian Students' Aid Program was created in 2005.


What is the average cumulative GPA of students in the program?

The average cumulative GPA of students in the program is 3.5.


What is the average graduate GPA of students in the program?

The average graduate GPA of students in the program is 3.5.


How do you get a Java program to display a backslash in output without it interpreting it as a program command?

Follow the backslash with another backslash: System.out.println("\\ " \"); will display \ " \ on the screen.


Why do people like the pathways program at John Abbott College it is such a bad program?

It's a bad program for good students, it's a good program for evil students


Program that interprets and display webpages?

browser


What is the name of the application that lets you arrange musical notes and play it?

A notation program.


7 of the 20 students attend an after school art program what percent of the students attend the program?

7 divided by 20


What grants are available for startup program for tutuoring students after school?

what grants are available for startup program for tutoring students after school?


What is the average age of doctoral students in your program?

The average age of doctoral students in our program is approximately 30 years old.