#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//定义结构体类型
struct student{
int sno;
char name[20];
float score;
};
int make_student(struct student st[]);
void show_student(int n,struct student st[]);
void menu(void);
int main(void)
{
int n,i,p;
int k,l,xh;
float cj;
char xm[20];
//定义结构体变量
struct student st[100];
while(1){
menu();
printf("请选择功能:");
scanf("%d",&k);
switch(k){
case 0:
/* printf("请输入要添加的学生人数:");
scanf("%d",&n);
for(i = 0 ; i < n; i++){
printf("请输入学生信息(sno name score):");
scanf("%d%s%f",&st[i].sno,st[i].name,&st[i].score);
}
*/
make_student(st);
break;
case 1:
n=1;
show_student(n,st);
break;
case 2: //查询学生信息
printf("请输入学生的学号:");
scanf("%d",&p);
for(i=0;i<n;i++)
{
if(p==st[i].sno)
printf("%d %s %0.2f\n",st[i].sno,st[i].name,st[i].score);
}
break;
case 3: //修改学生信息
printf("请输入学生的学号:");
scanf("%d",&l);
for(i=0;i<n;i++)
{
if(l==st[i].sno)
{
printf("请输入要修改的学号,姓名,成绩:");
scanf("%d %s %f",&xh,xm,&cj);
st[i].sno=xh;
strcpy(st[i].name,xm);
st[i].score=cj;
}
}
break;
case 4:
printf("谢谢使用\n");
exit(0);
}
}
return 0;
}
void menu(void)
{
printf("---------------------------------------\n");
printf(" 学生管理系统 \n");
printf("---------------------------------------\n");
printf(" 0 --- 添加学生信息\n");
printf(" 1 --- 显示学生信息\n");
printf(" 2 --- 查询学生信息\n");
printf(" 3 --- 修改学生信息\n");
printf(" 4 --- 退出系统\n");
printf("---------------------------------------\n");
}
int make_student(struct student st[] )
{
int i;
int n;
printf("请输入要添加的学生人数:");
scanf("%d",&n);
for(i = 0 ; i < n; i++){
printf("请输入学生信息(sno name score):");
scanf("%d%s%f",&st[i].sno,st[i].name,&st[i].score);
}
return n;
}
void show_student(int n,struct student st[])
{
int i;
printf("-------------------\n");
for(i = 0 ; i < n; i++)
printf("%d %s %.2f\n",st[i].sno,st[i].name,st[i].score);
}