Home > Back-end >  Bosses, please help me have a look at why the second student grade point average
Bosses, please help me have a look at why the second student grade point average

Time:10-10

#include
using namespace std;
Struct student {
Char id [10];
Char name [20].
Int score [4];
Double business;
};
Void input (student *, int);
Void sort (student *, int);
Void show (student *, int);
Int main ()
{int n;
Cout<" Please enter the number of students: ";
Cin> n;
Struct student * p=new struct student [n].
if(! P) {
Cout<" Allocation error! \ n ";
return 0;
}
Input (p, n);
Sort (p, n);
Show (p, n);
The delete [] p;
return 0;
}
Void input (student * s, int n)
{int I, j, sum=0;
For (I=0; i{cout<" Please enter the first "& lt; Cin> S [I]. Id;
Cout<" Please enter the first "& lt; Cin> S [I]. Name;
Cout<" Please enter the enter the first & lt;" for(int j=0; j<4. J++)
Cin> S [I] score [j];
for(j=0; j<4. J++)
The sum +=s [I] score [j];
S [I] business=sum/4;
Cout<" The first "& lt; }
}
Void sort (student * s, int n)
{int I, j;
Student temp.
for(j=0; jfor(i=0; iIf (s [I] average[I] {temp=s;
S=s [I] [I + 1);
S=\ [I + 1];
}
}
Void show (student * s, int n)
{
Cout<" The average score sorting result to "& lt; for(int i=0; i{coutCout

}

CodePudding user response:

for(j=0; j<4. J++)
The sum +=s [I] score [j];
S [I] business=sum/4;
Cout<" The first "& lt;
Sum=0;//add it here, put the sum to zero, because a few students to statistics with the sum total, no return 0, the value of the sum of a student will be taken to the next student
//, in this case, the sum of the first students=10 + 10 + 10 + 10=40, then to receive the second student of 20 + 20 + 20 + 20=120, so the second
//a student's grade point average is 120/4=30
}
  • Related