永发信息网

创建C++学生信息类和成绩管理类

答案:2  悬赏:30  手机版
解决时间 2021-02-16 10:28
  • 提问者网友:你独家记忆
  • 2021-02-15 13:32
创建C++学生信息类和成绩管理类
最佳答案
  • 五星知识达人网友:野味小生
  • 2021-02-15 15:07
const int MAX = 20;
struct Student
{
int number; //学号
int grade; //成绩
};

class StudentGroup
{
private:
Student m_stu[MAX];
int index;
int maxGrade;
int minGrade;
int sumGrade;
public:
StudentGroup():
index(0),
maxGrade(-1),
minGrade(101),
sumGrade(0)
{
memset(m_stu, 0, sizeof(Student)*MAX);
}
void input()
{
if (index>=MAX)
{
cout << "error: can't add any student info" << endl;
}
else
{
cout << "please input student number:";
cin >> m_stu[index].number;
cout << "
please input student C++ grade:";
cin >> m_stu[index].grade;
if (m_stu[index].grade > maxGrade)
maxGrade = m_stu[index].grade;
else if(m_stu[index].grade < minGrade)
minGrade = m_stu[index].grade;
sumGrade += m_stu[index].grade;
++index;
}
}
void displayAverage()
{
if (index == 0)
cout << "No record. " << endl;
else
cout << "Average C++ grade : " << sumGrade / index << endl;
}
void displayMaxGrade()
{
if (index == 0)
cout << "No record. " << endl;
else
{
cout << "Max C++ grade : " << endl;
for (int i=0; i {
if (m_stu[i].grade == maxGrade)
{
cout << m_stu[i].number << ":  " << m_stu[i].grade << endl;
}
}
}
}
void displayMinGrade()
{
if (index == 0)
cout << "No record. " << endl;
else
{
cout << "Min C++ grade : " << endl;
for (int i=0; i {
if (m_stu[i].grade == minGrade)
{
cout << m_stu[i].number << ":  " << m_stu[i].grade << endl;
}
}
}
}
};
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯