Current location - Training Enrollment Network - Mathematics courses - Find a C++ program (enter the student numbers and names of 30 students and the scores of three courses [Chinese, Mathematics and English].
Find a C++ program (enter the student numbers and names of 30 students and the scores of three courses [Chinese, Mathematics and English].
Use class objects and containers to see if you can do it!

# include & ltiostream & gt

# include & ltvector & gt

# include & lt string & gt

# include & lt map>

# include & lt iterator & gt

# include & ltiomanip & gt

Use namespace std

Class students {

Private:

Bilingual;

Double mathematics;

Double English;

Even number;

Double sumo;

Double avesocos

int place

String name;

Public:

Student(double language value = 0, double mathvalue=0, double englishvalue=0, double numbervalue=0, double sumsocosvalue=0, double avescos = 0, int placevalue=0, string namevalue= "Li Lei");

Double get language(){ returns the language; };

double get math(){ return math; };

double get English(){ return English; };

double get number(){ return number; };

double getsumsocos(){ return sumsocos; };

double get place(){ return place; };

double getavesocos(){ return avesocos; };

string getname(){ return name; };

Void setsumsocos (two digits) {sumsocos = digit};

Void setave (two digits) {avescocos = digit};

void set place(int place value){ place = place value; };

Double sum(){ return language+math+English; };

double average(){ return sum()/3; };

};

student::student(double language value、double mathvalue、double englishvalue、double numbervalue、double sumsocosvalue、double avesocosvalue、 int placevalue、string name value):language value、mathvalue、englishvalue、number(numbervalue)、sumsocos(sumsocosvalue)、avesocos(avesocosvalue)、place(placevalue){

name = namevalue

};

Void searchstudent (vector & lt student & gt* iterator beg, end of vector & lt student & gt* iterator, even number)

{

bool isfind = false

for(size _ t I = 0; I < = number; )

{

If ((* asks). getnumber()! = number)

{

beg++;

if(beg==end)

{

Break;

}

}

other

{

Cout & lt& lt "The student information you inquired is:"

Cout & lt& lt "Name:"

isfind = true

Break;

}

}

if(isfind==false)

{

Cout & lt& lt "Sorry, I didn't find the student information you needed!" & lt& ltendl

Return;

}

};

Double sumavesoco (vector <: Student & gt* iterator beg, vector & lt student & gt* end of iterator) (

Vector & lt student & gt* iterator begin = beg

Vector & lt Student & gt* Iterator End = End;

While (start! = ended)

{

int sum = 0;

int ave = 0;

sum+=(*begin)。 get English();

sum+=(*begin)。 get language();

sum+=(*begin)。 get math();

ave = sum/3;

(*begin)。 Setsumsocos (sum);

(*begin)。 setave(ave);

begin++;

}

Vector & lt student & gt* iterator begin1= beg;

Vector & lt student & gt* iterator Ended1= end;

int sumave = 0;

int sum soco = 0;

int count = 0;

while(begin 1! =ended 1)

{

sumsoco+=(*begin 1)。 getsumsocos();

count++;

begin 1++;

}

sumave = sumsoco/count;

Cout & lt& lt "The total score and average score of students are:"

And (beg! = End)

{

Cout & lt& lt "Name:"

beg++;

}

Return to sumave

};

Empty position (vector & lt student & gt* iterator beg, end of vector & lt student & gt* iterator) {

Vector & lt student & gta (seeking, end);

Vector & lt student & gt* iterator begin = a.begin ();

for(int I = 0; I & lta.size (); i++)

{

for(int j = I+ 1; j & lta . size(); j++)

{

If (a[i]. getsumsocos()& lt; a[j]。 getsumsocos())

{

Student days;

a student = a[I];

a[I]= a[j];

Students;

}

}

}

After the cout & lt& lt ranking is completed, the ranking order according to the total score is as follows

Vector & lt student & gt* iterator begin1= a.begin ();

while(begin 1! =a.end())

{

cout & lt& ltsetw(5)& lt; & lt "Name:"

begin 1++;

}

};

void search up student(vector & lt; Student & gt* iterator beg, vector & lt Student & gt* Iterator ends, double avescos) (

Cout & lt& lt "The information of students whose total score is higher than the class average is:"

And (beg! = End)

{

If ((* asks). getsumsocos()& gt; =avesocos)

{

Cout & lt& lt "Name:"

}

beg++;

}

};

Structure

int main()

{

Vector & lt student & gtstuarray

loop:cout & lt; & lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *”& lt; & lt endel

& lt& lt" 1. Enter information 2. Calculate the total score and average score of 3. Inquire about student information 4. Ranked 5 according to the total score. The average query score is "< < endel"

& lt& lt“* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *”& lt; & ltendl

int choose = 0;

Cout & lt& lt "Please enter your choice!" & lt& ltendl

CIN . clear();

CIN . sync();

CIN & gt; & gt chose;

If (< = 0 || Choose > 5)

{

Cout & lt& lt "Wrong input, please re-enter!" & lt& ltendl

Go to loop;

}

char ch = 0;

int count = 0;

Shuangsumave

Switch (selection)

{

Case 1:

{

Do {

Cout & lt& lt "Please enter student information!" & lt& ltendl

Double orchid, mathematics, English, numbers, socos, avesocos, place.

String name, gender;

Cout < < "language:";

CIN & gt; & gt orchid;

Cout & lt& ltendl & lt& lt Mathematics;

CIN & gt; & gt Mathematics;

Cout & lt& ltendl & lt& lt "English:";

CIN & gt; & gt English;

Cout & lt& ltendl & lt& lt "student number:";

CIN & gt; & gt number;

CIN . sync();

Cout & lt& ltendl & lt& lt Name: ";

Getline(cin, name);

cout & lt& ltendl

Student * astudent = new student (lan, math, English, numbers, socos=0, AVES SOCOS = 0, place=0, name);

stu array . push _ back(* a student);

Cout & lt& lt "Do you want to continue typing?" & lt& ltendl

CIN . clear();

CIN . sync();

CIN & gt; & gtch;

} while(to lower(ch)= = ' y ');

cout & lt& ltendl

Go to loop;

}

Case 2:

{

Vector & lt student & gt* iterator beg = stuarray.begin ();

Vector < student > * iterator end = stuarray. end ();

sumave=sumavesoco(beg,end);

Cout & lt& lt "The average grade of the whole class is:"

Go to loop;

}

Case 3:

{cout & lt& lt "Please enter the student number to query!" & lt& ltendl

int number 2 = 0;

CIN & gt; & gt number 2;

searchstudent(stuarray.begin()、stuarray.end()、number 2);

Go to loop;

}

Case 4:

{

Vector & lt student & gt* iterator beg = stuarray.begin ();

Vector < student > * iterator end = stuarray. end ();

Place (seeking, end);

Go to loop;

}

Case 5:

{

Vector & lt student & gt* iterator beg = stuarray.begin ();

Vector < student > * iterator end = stuarray. end ();

searchupstudent(beg,end,sumave);

Go to loop;

}

}

Returns 0;

}