注释行总是有错误#include using namespace std;class student{char name[10];double No;float maths,eng,ave,sum;public:student (student *p,int n){for(int i=0;i>(*p).name>>(*p).No>>(*p).maths>>(*p).eng;}float Sum(student *p,int n){for(int i = 0; is
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/18 05:30:06
注释行总是有错误#include using namespace std;class student{char name[10];double No;float maths,eng,ave,sum;public:student (student *p,int n){for(int i=0;i>(*p).name>>(*p).No>>(*p).maths>>(*p).eng;}float Sum(student *p,int n){for(int i = 0; is
注释行总是有错误
#include
using namespace std;
class student
{
char name[10];
double No;
float maths,eng,ave,sum;
public:
student (student *p,int n)
{
for(int i=0;i>(*p).name>>(*p).No>>(*p).maths>>(*p).eng;
}
float Sum(student *p,int n)
{
for(int i = 0; isum = p->maths + p->eng;
}
float Ave(student *p,int n)
{
for(int i = 0; iave= p->maths + p->eng;
}
void output(student *p,int n)
{
float ave1=0,ave2=0,sum1=0;
for(int i=0;i
注释行总是有错误#include using namespace std;class student{char name[10];double No;float maths,eng,ave,sum;public:student (student *p,int n){for(int i=0;i>(*p).name>>(*p).No>>(*p).maths>>(*p).eng;}float Sum(student *p,int n){for(int i = 0; is
那个错误是说你没有匹配的构造函数.你类的用法完全不对呀.
给你写了一个,你可以参考一下,一个类就是抽象出来的一个事物,不要揉合一大堆乱七八糟的东西在里面.
#include <iostream>using namespace std;
class Student
{
private:
char name[10];
int No;
double maths, eng, avg, sum;
public:
Student(){
cout << "Name, No, Maths, Eng: ";
cin >> name >> No >> maths >> eng;
sum = maths + eng;
avg = sum / 2.0;
}
char* getName(){return name;}
int getNo() {return No;}
double getSum() {return sum;}
double getAvg() {return avg;}
double getMaths() {return maths;}
double getEng() {return eng;}
};
class Students
{
private:
Student *stu;
int size;
public:
Students(int sz)
{
stu = NULL;
size = sz;
stu = new Student[size];
if(!stu)
{
cout << "内存分配失败!" << endl;
}
}
~Students()
{
delete stu;
stu = NULL;
}
public:
double getSum()
{
double sum = 0;
for(int i=0; i<size; i++) sum += stu[i].getSum();
return sum;
}
double getAvg()
{
double avg = 0;
for(int i=0; i<size; i++) avg += stu[i].getAvg();
return avg / size;
}
double getAvgEng()
{
double sum = 0;
for(int i=0; i<size; i++) sum += stu[i].getEng();
return sum / size;
}
double getAvgMaths()
{
double sum = 0;
for(int i=0; i<size; i++) sum += stu[i].getMaths();
return sum / size;
}
void output()
{
cout << "the average score of maths: " << getAvgMaths() << endl;
cout << "the average score of english: " << getAvgEng() << endl;
cout << "the last 20% of the students: " << endl;
showLastStudents();
}
private:
void sortBySumScore()
{
for(int i=0; i<size-1; i++)
{
for(int j=0; j<size-i-1; j++)
{
if(stu[j].getSum() > stu[j+1].getSum())
{
Student t = stu[j];
stu[j] = stu[j+1];
stu[j+1] = t;
}
}
}
}
void showLastStudents()
{
sortBySumScore();
cout << "Name\tNumber\tMaths\tEnglish\n";
for(int i=0; i <= (size * 0.2 - 1); i++)
{
cout << stu[i].getName() << "\t" << stu[i].getNo() << "\t" << stu[i].getMaths() << "\t" << stu[i].getEng() << endl;
}
}
};
int main()
{
int num;
cout<<"Please input the number of the students:";
cin>>num;
Students s(num);
s.output();
return 0;
}