求帮忙看一下我这到C++程序哪里错了,谢谢诶

2024-12-10 02:00:20
推荐回答(3个)
回答(1):

#include
#include
class student
{
public://如果你想用私有,可以在public里用函数返回值:类型 get**{return ***;}
char name[20];
long sid;
float score;

void set()
{
cout<<"please input the student's sid:";cin>>sid;
cout<<"please input the student's score:";cin>>score;
cout<<"please input the student's name:";cin>>name;
}
friend int order(int n,float &ave);
};
int order(int n,float &ave,student stu[])
{

int i,max=0;
long maxid;
char maxn[20];
float maxs;
for(i=0;i {
maxs=stu[i].score;
ave+=stu[i].score;
if(maxs {
maxs=stu[i].score;
strcpy(maxn,stu[i].name);
maxid=stu[i].sid;
max = i;
}
}
ave/=n;
return max;
}
void main()
{

student stu[20];
int i,n,max;
float ave=0;
cout<<"please input n=:";
cin>>n;
for(i=0;i {
cout<<"the"< stu[i].set();
}
max = order(n,ave,stu);
cout<<"the highest score goes to:"< cout< cout<<"the average score is:"<}
//你可以拿去参考下这个程序,我帮你修改的

回答(2):

29行的分号你写成中文输入法写的了。
另外,你那些都定义的私有成员啊。知道私有成员干嘛的吗?就是不能从类外访问。就不能用stu.score,stu.name这种形式。你可以设置成public的。方法二:可以提供函数去获得score。比如你在类里面定义一个 float getScore(){return score;}然后,这个是public。你用 stu.getScore()可以获得.

回答(3):

错太多了!没办法给你改 要实现什么功能啊!类中的私有成员不能直接访问啊 要用公又成员去访问才行! 而公有成员要用类定义的变量访问啊 而且 你程序中还有中文的分号 汗!公有成员函数你怎么写到 主函数里面去了!要在类里面直接定义功能啊!