有谁能帮我改一下错吗? 谢了!!!
#include<iostream.h>
#include<string.h>
class student{
int No;
char name;
float en,ch,ma;
public:
void setvalue1(int a) {No=a;}
void setvalue2(char b[20]) {name=b[20];}
void setvalue3(float c,float d,float e) {en=c;ch=d;ma=e;}
void ave() {float ave=en+ch+ma/3;}
void display() {cout<<No <<name <<en <<ch <<ma <<ave<<endl;}
}
void main()
{
int a;
char b[20];
float c,d,e;
student obj1;
student obj2;
cout<<"Enter No:"<<endl;
cin>>a;
cout<<"Enter name:"<<endl;
cin.getline(b,20);
cout<<"Enter English score:"<<endl;
cin>>c;
cout<<"Enter Chinese score:"<<endl;
cin>>d;
cout<<"Enter math score:"<<endl;
cin>>e;
obj1.setvalue1(a);
obj1.setvalue2(b);
obj1.setvalue3(c,d,e);
obj1.ave();
obj1.display();
cout<<"Enter No:"<<endl;
cin>>a;
cout<<"Enter name:"<<endl;
cin.getline(b,20);
cout<<"Enter English score:"<<endl;
cin>>c;
cout<<"Enter Chinese score:"<<endl;
cin>>d;
cout<<"Enter math score:"<<endl;
cin>>e;
obj2.setvalue1(a);
obj2.setvalue2(b);
obj2.setvalue3(c,d,e);
obj2.ave();
obj2.display();
}
能用构造法修改这题吗?怎么做啊?