本人软工学生一枚,学艺不精。有不足之处请谅解 ^ _ ^
有什么问题还希望您能多批评指正,不吝指教。
蟹蟹你来看鸭~~
1.问题描述
某班有最多不超过30人(具体人数由键盘输入)参加数学、语文、英语考试,编程实现如下菜单驱动的学生成绩管理系统:
1)录入学生信息,包括学号、姓名、数学分数、语文分数、英语分数;
2)计算3门课程的总分以及平均分;
3)按学生成绩排序(需要2级子菜单:按什么成绩排升序还是降序);
4)按学号升序排列;
5)按姓名字典序排列;
6)按学号查询学生信息;
7)按姓名查询学生信息;
8)按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5个类别,统计每个类别的人数以及所占的百分比(需要子菜单:按什么成绩统计);
9)输出所有学生的学号、姓名、数学分数、语文分数、英语分数、总分、平均分。
涉及到的知识
计数控制的循环、条件控制的循环以及循环嵌套。
一维数组、二维数组作为函数参数。
字符串处理函数、字符串处理操作。
2.上代码
#include "string.h"
#include "stdio.h"
void rank(long long STU_ID[], char name[][10], float score[][4], int n)
{
int i, j, k;
float temp1;
long long temp2;
char temp[10];
for (i = 0; i < n - 1; i++)
{
k = i;
for (j = i + 1; j < n; j++)
{
if (score[j][3] > score[k][3])
k = j;
}
if (k != i)
{
for (int t = 0; t <= 3; t++)
{
temp1 = score[k][t];
score[k][t] = score[i][t];
score[i][t] = temp1;
}
temp2 = STU_ID[k];
STU_ID[k] = STU_ID[i];
STU_ID[i] = temp2;
strcpy(temp, name[k]);
strcpy(name[k], name[i]);
strcpy(name[i], temp);
}
}
}
void fun1(long long STU_ID[], char name[][10], float score[][4], int n)
{
float a;
printf("Input student's ID and name ,math,chinese,english score:\n");
for (int i = 0; i < n; i++)
{
score[i][3] = 0;
scanf("%lld", &STU_ID[i]);
scanf("%s", name[i]);
for (int j = 0; j < 3; j++)
{
scanf("%f", &a);
while (a < 0 || a>100)
{
printf("输入错误!请输入正确的分数0-100\n");
scanf("%f", &a);
}
score[i][j] = a;
score[i][3] = score[i][3] + score[i][j];
}
}
}
void fun2(float score[][4], float sum[], float aver[], int n)
{
for (int j = 0; j < 3; j++)
{
sum[j] = 0;
for (int i = 0; i < n; i++)
{
sum[j] = sum[j] + score[i][j];
}
aver[j] = sum[j] / n;
printf("course%d:sum=%.0f,aver=%.0f\n", j + 1, sum[j], aver[j]);
}
}
void fun3(long long STU_ID[], char name[][10], float score[][4], int n)
{
int i, j, k;
float temp1;
long long temp2;
char temp[10];
for (i = 0; i < n - 1; i++)
{
k = i;
for (j = i + 1; j < n; j++)
{
if (score[j][3] > score[k][3])
k = j;
}
if (k != i)
{
for (int t = 0; t <= 3; t++)
{
temp1 = score[k][t];
score[k][t] = score[i][t];
score[i][t] = temp1;
}
temp2 = STU_ID[k];
STU_ID[k] = STU_ID[i];
STU_ID[i] = temp2;
strcpy(temp, name[k]);
strcpy(name[k], name[i]);
strcpy(name[i], temp);
}
}
printf("总分排名\n\n");
printf("学号 \t姓名\t数学\t语文\t英语\t总分\t平均分\t排名\n");
for (i = 0; i < n; i++)
{
printf("%lld\t", STU_ID[i]);
printf("%s\t", name[i]);
for (int t = 0; t <= 3; t++)
{
printf("%.0f\t", score[i][t]);
}
printf("%.0f\t", score[i][3] / 3);
printf("%d\n", i + 1);
}
}
void fun_3(long long STU_ID[], char name[][10], float score[][4], int n)
{
int i, j, k;
float temp1;
long long temp2;
char temp[10];
for (i = 0; i < n - 1; i++)
{
k = i;
for (j = i + 1; j < n; j++)
{
if (score[j][3] < score[k][3])
k = j;
}
if (k != i)
{
for (int t = 0; t <= 3; t++)
{
temp1 = score[k][t];
score[k][t] = score[i][t];
score[i][t] = temp1;
}
temp2 = STU_ID[k];
STU_ID[k] = STU_ID[i];
STU_ID[i] = temp2;
strcpy(temp, name[k]);
strcpy(name[k], name[i]);
strcpy(name[i], temp);
}
}
printf("总分逆向排名\n\n");
printf("学号 \t姓名\t数学\t语文\t英语\t总分\t平均分\t排名\n");
for (i = 0; i < n; i++)
{
printf("%lld\t", STU_ID[i]);
printf("%s\t", name[i]);
for (int t = 0; t <= 3; t++)
{
printf("%.0f\t", score[i][t]);
}
printf("%.0f\t", score[i][3] / 3);
printf("%d\n",n-i);
}
}
void fun4(long long STU_ID[], char name[][10], float score[][4], int n)
{
int i, j, k;
float temp1;
long long temp2;
char temp[10];
for (i = 0; i < n - 1; i++)
{
k = i;
for (j = i + 1; j < n; j++)
{
if (STU_ID[j] < STU_ID[k])
k = j;
}
if (k != i)
{
for (int t = 0; t <= 3; t++)
{
temp1 = score[k][t];
score[k][t] = score[i][t];
score[i][t] = temp1;
}
temp2 = STU_ID[k];
STU_ID[k] = STU_ID[i];
STU_ID[i] = temp2;
strcpy(temp, name[k]);
strcpy(name[k], name[i]);
strcpy(name[i], temp);
}
}
printf("学号排名\n\n");
printf("学号 \t姓名\t数学\t语文\t英语\t总分\t平均分\n");
for (i = 0; i < n; i++)
{
printf("%lld\t", STU_ID[i]);
printf("%s\t", name[i]);
for (int t = 0; t <= 3; t++)
{
printf("%.0f\t", score[i][t]);
}
printf("%.0f\t", score[i][3] / 3);
printf("\n");
}
}
void fun_4(long long STU_ID[], char name[][10], float score[][4], int n)
{
int i, j;
float temp1;
long long temp2;
char temp[10];
for (i = 0; i < n - 1; i++)
{
for (j = i + 1; j < n; j++)
{
if (strcmp(name[j], name[i]) < 0)
{
for (int t = 0; t <= 3; t++)
{
temp1 = score[j][t];
score[j][t] = score[i][t];
score[i][t] = temp1;
}
temp2 = STU_ID[j];
STU_ID[j] = STU_ID[i];
STU_ID[i] = temp2;
strcpy(temp, name[j]);
strcpy(name[j], name[i]);
strcpy(name[i], temp);
}
}
}
printf("姓名排名\n\n");
printf("学号 \t姓名\t数学\t语文\t英语\t总分\t平均分\n");
for (i = 0; i < n; i++)
{
printf("%lld\t", STU_ID[i]);
printf("%s\t", name[i]);
for (int t = 0; t <= 3; t++)
{
printf("%.0f\t", score[i][t]);
}
printf("%.0f\t", score[i][3] / 3);
printf("\n");
}
}
void fun5(long long STU_ID[], char name[][10], float score[][4], int n)
{
long long number;
rank(STU_ID, name, score, n);
printf("Input the number you want to scarch:");
scanf("%lld", &number);
int flag = 0;
for (int i = 0; i < n; i++)
{
if (STU_ID[i] == number)
{
printf("学号 \t姓名\t数学\t语文\t英语\t总分\t平均分\t排名\n");
printf("%lld\t", STU_ID[i]);
printf("%s\t", name[i]);
for (int t = 0; t <= 3; t++)
{
printf("%.0f\t", score[i][t]);
}
printf("%.0f\t", score[i][3] / 3);
printf("%d\n", i + 1);
flag = 1;
}
}
if (flag == 0)
printf("\nNot found!\n");
}
void fun_5(long long STU_ID[], char name[][10], float score[][4], int n)
{
char temp[10];
int i;
rank(STU_ID, name, score, n);
printf("Input the name you want to scarch:");
scanf("%s", temp);
int flag = 0;
for (i = 0; i < n; i++)
{
if (strcmp(name[i], temp) == 0)
{
printf("学号 \t姓名\t数学\t语文\t英语\t总分\t平均分\t排名\n");
printf("%lld\t", STU_ID[i]);
printf("%s\t", name[i]);
for (int t = 0; t <= 3; t++)
{
printf("%.0f\t", score[i][t]);
}
printf("%.0f\t", score[i][3] / 3);
printf("%d\n", i + 1);
flag = 1;
}
}
if (flag == 0)
printf("\nNot found!\n");
}
void fun6(float score[][4], int n)
{
int t[5];
int i, j, total;
for (j = 0; j < 3; j++)
{
printf("course:%d\n", j + 1);
for (int k = 0; k < 5; k++)
{
t[k] = 0;
}
for (i = 0; i < n; i++)
{
if (score[i][j] >= 0 && score[i][j] < 60) t[0]++;
else if (score[i][j] < 70) t[1]++;
else if (score[i][j] < 80) t[2]++;
else if (score[i][j] < 90) t[3]++;
else if (score[i][j] < 100) t[4]++;
}
printf("<60\t%d\t%.2f%%\n", t[0], (float)t[0] / n * 100);
printf("60-69\t%d\t%.2f%%\n", t[1], (float)t[1] / n * 100);
printf("70-79\t%d\t%.2f%%\n", t[2], (float)t[2] / n * 100);
printf("80-89\t%d\t%.2f%%\n", t[3], (float)t[3] / n * 100);
printf("90-100\t%d\t%.2f%%\n", t[4], (float)t[4] / n * 100);
}
}
void fun7(long long STU_ID[], char name[][10], float score[][4], int n)
{
int i, j, k;
float temp1;
long long temp2;
char temp[10];
for (i = 0; i < n - 1; i++)
{
k = i;
for (j = i + 1; j < n; j++)
{
if (STU_ID[j] > STU_ID[k])
k = j;
}
if (k != i)
{
for (int t = 0; t <= 3; t++)
{
temp1 = score[k][t];
score[k][t] = score[i][t];
score[i][t] = temp1;
}
temp2 = STU_ID[k];
STU_ID[k] = STU_ID[i];
STU_ID[i] = temp2;
strcpy(temp, name[k]);
strcpy(name[k], name[i]);
strcpy(name[i], temp);
}
}
printf("成绩单\n\n");
printf("学号 \t姓名\t数学\t语文\t英语\t总分\t平均分\n");
for (i = 0; i < n; i++)
{
printf("%lld\t", STU_ID[i]);
printf("%s\t", name[i]);
for (int t = 0; t <= 3; t++)
{
printf("%.0f\t", score[i][t]);
}
printf("%.0f\t", score[i][3] / 3);
printf("\n");
}
}
int main()
{
long long STU_ID[30];
char name[30][10];
float score[30][4];
float sum[4];
float aver[4];
int n = 0;
int a = -1;
int ha;
printf("Please input student number.\n\n");
scanf("%d", &n);
while (a != 0)
{
printf("\n*************************\n");
printf("1.Input record\n");
printf("2.Caculate total and average score of course\n");
printf("3.Sort in order by score\n");
printf("4.Sort in ascending order by unmber\n");
printf("5.Sort in dictionary order by name\n");
printf("6.search by number\n");
printf("7.search by name\n");
printf("8.Statistic analysis\n");
printf("9.List record\n");
printf("0.Exit\n");
printf("*************************\n");
printf("请输入功能号0-9:");
scanf("%d", &a);
while (a < 0 || a>9)
{
printf("\n输入错误!请输入正确的功能号0-9:");
scanf("%d", &a);
}
if (a == 1)
fun1(STU_ID, name, score, n);
else if (a == 2)
fun2(score, sum, aver, n);
else if (a == 3)
{
ha = -1;
while (ha != 0)
{
printf("1.Sort in descending order by score\n");
printf("2.Sort in ascending order by score\n");
printf("请输入功能号1,2:");
scanf("%d", &ha);
while (ha < 0 || ha>2)
{
printf("\n输入错误!请输入正确的功能号1,2:");
scanf("%d", &ha);
}
if (ha == 1)
{
fun3(STU_ID, name, score, n);
break;
}
else if (ha == 2)
{
fun_3(STU_ID, name, score, n);
break;
}
}
}
else if (a == 4)
fun4(STU_ID, name, score, n);
else if (a == 5)
fun_4(STU_ID, name, score, n);
else if (a == 6)
fun5(STU_ID, name, score, n);
else if (a == 7)
fun_5(STU_ID, name, score, n);
else if (a == 8)
fun6(score, n);
else if (a == 9)
fun7(STU_ID, name, score, n);
}
return 0;
}
3.运行结果部分截图