#define _CRT_SECURE_NO_WARNINGS 1//vs2019scanf的识别问题
#include
#include
#include
#include
#include
#include
int count = 0;//计算学生人数
struct information//结构体数组
{
int ID;
char name[20];
int score;
};
int main()
{
struct information a[99] = {0};
int z, i;
A:
system("cls");
printf("+++++++++++|----------------|+++++++++++\n");
printf("+++++++++++|| 学生数据系统 ||+++++++++++\n");
printf("+++++++++++|----------------|+++++++++++\n");
printf("+++++++++++| 学生成绩输入 1|+++++++++++\n");
printf("+++++++++++| 学生成绩查询 2|+++++++++++\n");
printf("+++++++++++| 学生成绩添加 3|+++++++++++\n");
printf("+++++++++++| 删除学生信息 4|+++++++++++\n");
printf("+++++++++++| 排名 5|+++++++++++\n");
printf("+++++++++++| 退出 6|+++++++++++\n");
printf("+++++++++++|----------------|+++++++++++\n");
printf("+++++++++++<请输入数字以继续>+++++++++++\n");
scanf("%d", &z);
switch (z)//判断进行哪个程序
{
case 1:
system("cls");//清屏
int k;
for (i = 0; i < 99; i++)
{
printf("+++++++++++||请输入学生姓名||+++++++++++\n");
scanf("%s", a[i].name);
printf("+++++++++++||请输入学生学号||+++++++++++\n");
scanf("%d", &a[i].ID);
printf("+++++++++++||请输入学生成绩||+++++++++++\n");
scanf("%d", &a[i].score);
count++;
printf("继续请按1,返回请按2\n");
scanf("%d", &k);
if (k == 2)
{
break;
}
}
goto A;//返回主界面
case 2:
system("cls");
int f;
int q;
printf("您想通过什么查询 1——学号 2——成绩 3——姓名\n");
scanf("%d", &f);
if (f == 1)
{
printf("请输入学号:");
scanf("%d", &q);
for (i = 0; i < 99; i++)
{
if (q == a[i].ID)
{
printf("学号:%d 姓名:%s 成绩:%d\n", a[i].ID, a[i].name, a[i].score);
system("pause");
break;
}
else
continue;
}
}
else if (f == 2)
{
int d;
int j;
printf("请输入成绩:");
scanf("%d", &d);
for (j = 0; j < 99; j++)
{
if (d == a[j].score)
{
printf("学号:%d 姓名:%s 成绩:%d", a[j].ID, a[j].name, a[j].score);
system("pause");
break;
}
else
continue;
}
}
else if (f == 3)
{
int i2;
char name1[20];
printf("请输入姓名:");
scanf("%s", name1);
for (i2 = 0; i2 < 999; i2++)
{
if (!strcmp(a[i2].name, name1))
{
printf("学号: %d 姓名: %s 成绩: %d\n", a[i2].ID, a[i2].name, a[i2].score);
system("pause");
break;
}
}
}
goto A;
case 3:
system("cls");
int g;
for (i =count+1 ; i < 99; i++)//在输入的最后一个人的后一位开始重新计算
{
count++;
printf("+++++++++++||请输入学生姓名||+++++++++++\n");
scanf("%s", a[i].name);
printf("+++++++++++||请输入学生学号||+++++++++++\n");
scanf("%d", &a[i].ID);
printf("+++++++++++||请输入学生成绩||+++++++++++\n");
scanf("%d", &a[i].score);
printf("添加成功\n");
count++;
printf("继续请按1,返回请按2\n");
scanf("%d", &g);
if (g == 2)
{
break;
}
}
goto A;
case 4:
int f2,i3,j2;
system("cls");
printf("请输入要删除的学生学号:");
scanf("%d", &f2);
for (i3 = 0; i3 < count; i3++)
{
if (f2 == a[i3].ID)//用后一个人覆盖删除信息的空位
{
for (j2 = i3; j2 < count-1; j2++)
{
a[j2] = a[j2 + 1];
}
}
}
count--;//减少一个学生
printf("删除成功");
system("pause");
goto A;
case 5:
system("cls");
int i4, j4;
information temp;
for (i4 = 0; i4 < count-1; i4++)//排序算法
{
for (j4 = i4 + 1; j4 < count; j4++)
{
if (a[i4].score < a[j4].score)
{
temp = a[i4];
a[i4] = a[j4];
a[j4] = temp;
}
}
}
for(i4=0;i4
printf("学号: %d 姓名: %s 成绩: %d\n", a[i4].ID, a[i4].name, a[i4].score);
system("pause");
goto A;
case 6:
system("cls");
printf("感谢您的使用,再见");
system("pause");
break;
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)