有大神会做这道C语言题目吗?
#include <vector>
using namespace std;
enum Subject
{
C_LanguageProgramming, //C语言程序设计 clp
MatlabProgramming, //Matlab程序设计 mp
AdvancedMathematics, //高等数学 am
CollegeEnglish, //大学英语 ce
All_Subject, //所有学科
};
class Student
{
float _scores[All_Subject]; //分数集合
public:
Student()
{
_scores[C_LanguageProgramming] = 0;
_scores[MatlabProgramming] = 0;
_scores[AdvancedMathematics] =0;
_scores[CollegeEnglish] = 0;
}
Student(float clp, float mp, float am, float ce)
{
_scores[C_LanguageProgramming] = clp;
_scores[MatlabProgramming] = mp;
_scores[AdvancedMathematics] = am;
_scores[CollegeEnglish] = ce;
}
Student(const Student& other)
{
for (int i = 0; i < All_Subject; ++i)
{
_scores[i] = other._scores[i];
}
}
void operator=(const Student& other)
{
for (int i = 0; i < All_Subject; ++i)
{
_scores[i] = other._scores[i];
}
}
float& SingleSubjectScore(Subject subject)
{
return _scores[subject];
}
float GetTotalPersonalScore()
{
float sum = 0;
for (int i = 0; i < All_Subject; ++i)
{
sum += _scores[i];
}
return sum;
}
float GetIndividualAverageScore()
{
return GetTotalPersonalScore() / All_Subject;
}
};
直接发在这里吧
class School
{
vector _students; //所有学生
public:
void add_student(Student student)
{
_students.push_back(student);
}
Student GetStudent(int number)
{
if (number = _students.size())return Student();
return _students[number];
}
float AllStudentScores()
{
float sum = 0;
for (auto iter = _students.begin(); iter != _students.end(); ++iter)
{
sum += (*iter).GetTotalPersonalScore();
}
return sum;
}
int Headcount()
{
return _students.size();
}
float SingleSubjectScore(Subject subject)
{
float sum = 0;
for (auto iter = _students.begin(); iter != _students.end(); ++iter)
{
sum += (*iter).SingleSubjectScore(subject);
}
return sum;
}
float SingleSubjectYIELD(Subject subject)
{
int qualified = 0; //合格
int noQualified = 0; //不合格
for (auto iter = _students.begin(); iter != _students.end(); ++iter)
{
float value = (*iter).SingleSubjectScore(subject);
if (value >= 60.0f)
qualified++;
else
noQualified++;
}
return (float)qualified / (qualified + noQualified);
}
void PrintAverageScoreandPassRateOfEachSubject()
{
for (int i = 0; i < All_Subject; ++i)
{
switch (i)
{
case C_LanguageProgramming:cout << "C语言程序设计的平均成绩:"; break;
case MatlabProgramming:cout << "Matlab程序设计的平均成绩:"; break;
case AdvancedMathematics:cout << "高等数学的平均成绩:"; break;
case CollegeEnglish:cout << "大学英语的平均成绩:"; break;
}
cout << SingleSubjectScore((Subject)i) /_students.size() <<
"分,合格率:" << SingleSubjectYIELD((Subject)i) * 100 << "%\n";
}
}
void PrintAverageScorePerStudent()
{
int i = 0;
for (auto iter = _students.begin(); iter != _students.end(); ++iter)
{
i++;
cout << "学生" << i << "的平均分是:" <<
(*iter).GetIndividualAverageScore() << "分\n";
}
}
};