#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();}哪里错了
2 回答
RockenRoll
TA贡献35条经验 获得超13个赞
float student::average()
{
aver=(s1+s2+s3+s4)/4;
}你这个方法定义的是有返回值的的,后面应该return aver;
- 2 回答
- 0 关注
- 1406 浏览
添加回答
举报
0/150
提交
取消