The
implements a student class that contains a school number (ID), name (name), and grade (grade) data member. In order to enter the convenience of the output, you need to overload the student class with the ">>" and "<<" operators, while in order to the number of students from small to large sorting, you also need to overload the "<" operator to use the STL in the sort function. The declaration of the class and the test code for the main function have been given, please supplement the implementation of the class with the related overload to make the program run correctly and output the correct result.
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
Class Student
{public
:
int id;
string name, grade;
Student () {};
Student (int ID, string name, string grade);
BOOL operator < (const Student & S) const;
IStream & operator >> (IStream & In, Student & S);
Ostream & operator << (Ostream & Out, Student & S);
/* Please fill in the code *
/INT main ()
{
vector<student> sv;
Student temp;
while (CIN >> temp)
{
sv.push_back (temp);
}
Sort (Sv.begin (), Sv.end ());
for (int i = 0; i < sv.size (); ++i)
cout << sv[i];
return 0;
}
Input description
Each sample has multiple lines, each containing an integer ID representing the number, the string name representing the name (no spaces in the middle), the string grade the grade, and the three separated by a space.
Output description
The input of all students by the school number from small to large sort, in order output, each student occupies a row, the format and input the same.
Sample input
3 Lilei
2 Hanmeimei
1 Lintao 15
Sample output
1 Lintao
2 Hanmeimei
3 Lilei 14
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace Std;
Class Student
{
Public
int id;
string name, Grade;
Student ()
{
Id=-1;
Name= ' ";
Grade= ' ";
}
Student (int ID, string name, string grade)
{
this->id=id;
this->name=name;
this->grade=grade;
}
BOOL operator < (const Student & S) const
{
if (s.id>this->id)
return true;
Else
return false;
}
};
IStream & operator >> (IStream & In, Student & S)
{
cin>>s.id;
cin>>s.name;
cin>>s.grade;
return in;
}
Ostream & operator << (Ostream & Out, Student & S)
{
cout<<s.id<< "" <<s.name<< "" <<s.grade<<endl;
return out;
}
/* Please fill in the code here * *
int main ()
{
Vector<student> SV;
Student temp;
while (CIN >> temp)
{
Sv.push_back (temp);
}
Sort (Sv.begin (), Sv.end ());
for (int i = 0; i < sv.size (); ++i)
cout << Sv[i];
return 0;
}