应用二维数组,实现简单的学生成绩查询系统的设计。具体要求如下:
(1)根据用户输入的学号,能够给出该生各科成绩及平均分。
(2)根据用户输入的课程代号,能够给出该课程中每位学生的成绩及课程平均分。
(3)能够查询出某个学生某一门的考试成绩。
#include<iostream>
using namespace std;
int main()
{
int a, score[4][5], i, j, aver = 0, num;
cout << "****************************************" << endl;
cout << "***1.据学生学号查询学生成绩及平时成绩***" << endl;
cout << "*2.据课程代号查询学生课程成绩及平均成绩*" << endl;
cout << "**3.据学生学号和课程代号查询学生成绩 ***" << endl;
cout << "*********4.学生原始数据的依次输入 ******" << endl;
cout << "**********5.谢谢使用,退出本系统!******" << endl;
cout << "****************************************" << endl;
cout << "请选择1-5" << endl;
while (1)
{
flag:
cin >> a;
if (a == 5)
{
cout << "谢谢使用";
break;
}
if (a >= 6 || a <= 0)
{
cout << "请输入正确号码" << endl;
goto flag;
}
switch (a)
{
case 1:
cout << "请输入学号";
cin >> num;
for (i = 0;i < 4;i++)
{
if (num == score[i][0])
{
for (j = 1;j < 5;j++)
{
cout << j << "号课程成绩为" << score[i][j] << endl;
aver += score[i][j];
}
}
cout << num << "号学生平均成绩为" << aver / 4;
break;
}
case 2:
cout << "请输入查询课号" << endl;
cin >> j;
for (int i = 0;i < 4;i++)
{
cout << i + 1 << "号学生此课成绩为" << score[i][j] << endl;
aver = score[i][j];
}
cout << "此课程平均成绩为" << aver / 4 << endl;;
break;
case 3:
cout << "请输入学生学号和课号";
cin >> num;cin >> j;
for (i = 0;i < 4;i++)
{
if (num == score[i][j])
cout << num << "号学生" << j << "号课程分数为" << score[i][j] << endl;
}
case 4:
cout << "请输入4个同学4门科目成绩" << endl;
for (i = 0;i < 4;i++)
{
for (j = 0;j < 5;j++)
{
cin >> score[i][j];
}
}
break;
default:
break;
}
}
}