有关类的编程

#include <iostream.h>
class student
{
private:
 char name[20];
 char sex;
 int num;
 float aver;
 float s1,s2,s3,s4;
public:
 student(char n,char s,int u);
 float average(float s1,float s2,float s3,float s4);
 void show();
};
student::student(char n[20],char s,int u,float s_1,float s_2,float s_3,float s_4)
{
 name[20]=n[20];
 sex=s;
 num=u;
 s1=s_1;
 s2=s_2;
 s3=s_3;
 s4=s_4;
}
float student::average()
{
 aver=(s1+s2+s3+s4)/4;
}
void student::show()
{
 cout<<"姓名:"<<name<<"性别:"<<sex<<"学号:"<<num<<"平均分:"<<aver<<endl;
}
void main()
{
     student stu1("xiaoli",'M',1,80,90,70,60)

  stu1.average();
  stu1.show();
}

哪里错了

wendy0512
浏览 1407回答 2
2回答

RockenRoll

float student::average(){ aver=(s1+s2+s3+s4)/4;}你这个方法定义的是有返回值的的,后面应该return aver;
打开App,查看更多内容
随时随地看视频慕课网APP