#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
typedef struct
{
int num;
char name[64];
char sex;
float score;
}S;
void menu(void);
int Showeveryone(S s[]);
int Add(S s[]);
int Del(S s[]);
int Find(S s[]);
int Change(S s[]);
S tmp;
S s[100] = { 0 };
void menu(void)
{
printf("**************学生管理系统*******************\n");
printf("***1.添加学生 2.删除学生****\n");
printf("***3.查找学生 4.修改学生信息\n");
printf("***5.显示所有已存在的学生(排序) 0.exit *****\n");
}
int main()
{
int n = 0;
while (1)
{
menu();
printf("请输入您要做的选项\n");
//again:
scanf("%d", &n);
switch (n)
{
case 1:Add(s); break;
case 2:Del(s); break;
case 3:Find(s); break;
case 4:Change(s); break;
case 5:Showeveryone(s); break;
case 0:return 0;
default:printf("抱歉输入错误,请重新输入\n");
//goto again;
}
}
return 0;
}
int Add(S s[])
{
printf("请输入学生信息\n");
for (int i = 0; i < 100; i++)
{
if (s[i].num == 0)
{
int num1 = 0;
char name1[64];
char sex1;
float score1;
t:
printf("请输入学号\n");
scanf("%d", &num1);//学号
for (int j = 0; j < 100; j++)
{
if (s[j].num == num1)
{
printf("抱歉,该学号已被占用\n");
goto t;
}
}
s[i].num = num1;
printf("请输入名字\n");
scanf("%s", name1);
strcpy(s[i].name, name1);//名字
getchar();
printf("请输入性别\n");
scanf("%c", &sex1);
s[i].sex = sex1;//性别
getchar();
printf("请输入成绩\n");
scanf("%f", &score1);
s[i].score = score1;//成绩
printf("\n");
printf("录入完成\n");
break;
}
}
}
int Del(S s[])
{
printf("请输入要删除的学生的学号\n");
int Del1 = 0;
scanf("%d", &Del1);
int i = 0;
for (i = 0; i < 100; i++)
{
if (s[i].num == Del1)
{
s[i].num = 0;
strcpy(s[i].name, "0");
s[i].sex = 0;
s[i].score = 0;
printf("删除完成\n");
break;
}
}
if (i == 100)
{
printf("查找不到该学生\n");
}
}
int Find(S s[])
{
printf("请输入要查找的学生学号\n");
int f1 = 0;
int j = 0;
scanf("%d", &f1);
for (j = 0; j < 100; j++)
{
if (s[j].num == f1)
{
printf("该学生学号为%d\t", s[j].num);
printf("该学生名字为%s\t", s[j].name);
printf("该学生性别为%c\t", s[j].sex);
printf("该学生成绩为%f", s[j].score);
printf("\n");
break;
}
}
if (j == 100)
{
printf("查找不到该学生\n");
}
}
int Change(S s[])
{
printf("请输入要修改的学生学号\n");
int c1 = 0;
int c = 0;
int num2;
char name2[64];
char sex2;
float score2;
scanf("%d", &c1);
for (c = 0; c < 100; c++)
{
if (s[c].num == c1)
{
printf("请输入要修改的\n");
printf("学号\t名字\t性别\t成绩\n");
scanf("%d", &num2);
s[c].num = num2;
scanf("%s", name2);
strcpy(s[c].name, name2);
getchar();
scanf("%c", &sex2);
s[c].sex = sex2;
scanf("%f", &score2);
s[c].score = score2;
printf("修改完毕\n");
break;
}
}
if (c == 100)
{
printf("查找不到该学生\n");
}
}
int Showeveryone(S s[])
{
for (int i = 0; i < 99; i++)
{
for (int j = 0; j < 99 - i; j++)
{
if (s[j].score <= s[j + 1].score)
{
tmp = s[j];
s[j]= s[j + 1];
s[j + 1]= tmp;
}
}
}
for (int i = 0; i < 100; i++)
{
if (s[i].num != 0)
{
printf("该学生学号为%d\t", s[i].num);
printf("该学生名字为%s\t", s[i].name);
printf("该学生性别为%c\t", s[i].sex);
printf("该学生成绩为%f", s[i].score);
printf("\n");
}
}
}
标签:管理系统,int,scanf,学生,break,num,printf,100
From: https://blog.51cto.com/u_16425777/9151811