C++定义一个学生类,急急急!!!

2024年11月17日 12:26
有2个网友回答
网友(1):

class student
{
public:
double scorea;
double scoreb;
double scorec;
double scored;
int num;
string name;
double total(){return scorea+scoreb+scorec+scored;};
};
void main()
{
student str[5];
double avr[5]={0};
int i=0;
for(;i<5;i++)
{
cout << "输入学号和成绩";
cin >> str[i].num >> str[i].scorea >> str[i].scoreb >> str[i].scorec >> str[i].scored ;
}
cout << "总成绩:"< for( i=0;i<5;i++)
{
cout << str[i].num <<":"< }
for ( i=0;i<5;i++)
{
avr[0]+=str[i].scorea;
avr[1]+=str[i].scorea;
avr[2]+=str[i].scorea;
avr[3]+=str[i].scorea;
avr[4]+=str[i].scorea;
}
cout << "每科平均成绩:"< cout<< avr[0]/5 << " "<< avr[1]/5 << " "<< avr[2]/5 << " "<< avr[3]/5 << " "<< avr[4]/5 << " " ;
//
int topnun=0;
for ( i=1;i<5;i++)
{
if(str[topnun].total topnun=i;
}
cout<< "最高分:"< //
int topnun[5]={0};
for ( i=1;i<5;i++)
{
if(str[topnun[0]].scorea topnun[0]=i;
if(str[topnun[1]].scorea topnun[1]=i;
if(str[topnun[2]].scorea topnun[2]=i;
if(str[topnun[3]].scorea topnun[3]=i;
if(str[topnun[4]].scorea topnun[4]=i;
}
cout<< "scorea最高分:"< cout<< "scorea最高分:"< cout<< "scorea最高分:"< cout<< "scorea最高分:"< cout<< "scorea最高分:"<}

网友(2):

是帮你写??还是你写了帮你完善?