这个程序没有明显的错误,可以编译连接,也可以进行正常的工作。但是有一点:屏幕上出现很多“-858993460”
不知道从那里来的,请高手指点一下,谢谢
在这里顺便谢谢下everajax ,帮我解决了“发牌程序”,呵呵。
#include<iostream>
#include<string>
using namespace std;
class students
{
private:
string name;
int number;
public:
void getdata()
{
cout<<"Input the student's NO:";
cin>>number;
cout<<"Input the student's name:";
cin>>name;
}
void showdata()
{
cout<<number<<" "<<name<<" ";
}
};
class mark:public students
{
public:
int English,Maths,Chinese,Total;
public:
void getdata()
{
students::getdata();
cout<<"Input the student's English score:";
cin>>English;
cout<<"Input the student's Chinese score:";
cin>>Chinese;
cout<<"Input the student's Maths score:";
cin>>Maths;
}
void sumdata()
{
Total=English+Maths+Chinese;
}
void showdata()
{
students::showdata();
cout<<English<<" "<<Chinese<<" "<<Maths<<" "<<Total<<endl;
}
};
int main()
{
int n=0;
int sumMaths=0;
int sumEnglish=0;
int sumChinese=0;
float Eaverage,Maverage,Caverage;
char choice;
const MAX=50;
mark stu[MAX];
do
{
stu[n].getdata();
sumMaths+=stu[n].Maths;
sumChinese+=stu[n].Chinese;
sumEnglish+=stu[n].English;
stu[n].sumdata();
n++;
done:
cout<<"Enter another?(y/n):";
cin>>choice;
if(choice!='y'&&choice!='n')
{
cout<<"Please choice y or n:"<<endl;
goto done;
}
}
while(choice!='n');
Eaverage=sumEnglish/n;
Maverage=sumMaths/n;
Caverage=sumChinese/n;
cout<<"number"<<" "<<"name"<<" "<<"English"<<" "<<"Chinese"<<" "<<"Maths"<<" "<<"Total"<<endl;
for(n=0;n<MAX;n++)
{
stu[n].showdata();
stu[n].sumdata();
}
cout<<"The average score of English is:"<<Eaverage<<endl;
cout<<"The average score of Maths is:"<<Maverage<<endl;
cout<<"The average score of Chinese is:"<<Caverage<<endl;
return 0;
}