参考 exit(0)结束程序
system ("cls"); 清除屏幕
system("pause");
清空缓存区 fflush(stdin);
#include
#include
#include
#include
#define N 10 //数据
#define LEN 10 //学号
#define NUM 100 //录入学生人数
typedef struct student
{
char num[LEN];
char name[N];
float chinese;
float math;
float english;
float ave;
student *next;
}student;
void check(student *p)
{
char num[LEN],name[N];
float chinese,math,english;
while(1)
{
scanf("%s%s%f%f%f",&num,&name,&chinese,&math,&english);
if(strlen(num)==9&&(chinese>=0&&chinese<=100)
&&(math>=0&&math<=100)&&(english>=0&&english<=100))
{
strcpy(p->num,num);strcpy(p->name,name);
p->chinese=chinese,p->english=english,p->math=math;
return ;
}
else
{
printf("数据错误,请检查一下重新输入->");
}
}
}
student *addstu()
{
system("cls");
student *p,*q,*h=NULL;
printf("请输入你想要录入的学生信息人数-> ");
int n,i;
scanf("%d",&n);
printf("请按照如下格式填写\n000000000 张三 100 99 98\n");
for(i=0;inext=NULL;
printf("---> ");
check(p);
//scanf("%s%s%f%f%f",&p->num,&p->name,&p->chinese,&p->math,&p->english);
if(h==NULL) h=p;
else q->next=p;
q=p;
printf("\n");
}
system("pause");
return h;
}
void all(student *h)
{
system("cls");
student *p=h;
while(p)
{
printf("学号\t\t姓名\t语文\t数学\t英语\t平均分\t\n");
printf("%s\t\t%s\t%.1f\t%.1f\t%.1f\t%.2f\t\n",
p->num,p->name,p->chinese,p->math,p->english,p->ave);
p=p->next;
}
printf("--------------------------------------------------------------\n");
printf(" 输出完毕 \n");
system("pause");
}
void bad(student *h)
{
system("cls");
student *p=h;
while(p)
{
printf("学号\t\t姓名\t语文\t数学\t英语\t平均分\t\n");
if(p->chinese<60||p->english<60||p->math<60)
{
printf("%s\t\t%s\t%.1f\t%.1f\t%.1f\t%.2f\t\n",
p->num,p->name,p->chinese,p->math,p->english,p->ave);
}
p=p->next;
}
printf("--------------------------------------------------------------\n");
printf(" 输出完毕 \n");
system("pause");
}
void swap(student *s,student *p)
{
student *t=(student *)malloc(sizeof(student));
strcpy(t->num,s->num);strcpy(s->num,p->num);strcpy(p->num,t->num);
strcpy(t->name,s->name);strcpy(s->name,p->name);strcpy(p->name,t->name);
t->chinese=s->chinese;s->chinese=p->chinese;p->chinese=t->chinese;
t->english=s->english;s->english=p->english;p->english=t->english;
t->math=s->math;s->math=p->math;p->math=t->math;
t->ave=s->ave;s->ave=p->ave;p->ave=t->ave;
t->next=s->next;s->next=p->next;p->next=t->next;
}
void insert_num(student *h)
{
student *p,*q,*s;
int t;
for(p=h;p;p=p->next)
{
s=p;
for(q=p->next;q;q=q->next)
{
if(strcmp(s->num,q->num)>0)
s=q;
}
if(s!=p) //交换
swap(s,p);
}
printf("交换完毕\n");
system("pause");
}
void insert_ave(student *h)
{
student *p,*q,*s;
int t;
for(p=h;p;p=p->next)
{
s=p;
for(q=p->next;q;q=q->next)
{
if(s->ave > q->ave)
s=q;
}
if(s!=p) //交换
swap(s,p);
}
printf("交换完毕\n");
system("pause");
}
void ave(student *h)
{
student *p=h;
while(p)
{
p->ave=(p->chinese+p->english+p->math)/3;
p=p->next;
}
printf("计算完毕\n");
system("pause");
}
void destroy(student *h)
{ student *p;
while(h!=NULL)
{
p = h; //p指向要销毁的结点
h = h ->next; //head指向再下一个要销毁的结点
free(p); //销毁p指向的结点
}
}
int login()
{
char key[N];
printf("请输入密码->__");
while(1)
{
scanf("%s",&key);
if((strcmp("12345",key)==0))
{
printf("yeah!\n");
return 1;
}
else
printf("one more time-> ");
}//重复输入密码直到正确
}
void menu()
{
system("cls");
printf("\n");
printf("--------------------___学生信息管理系统___--------------------\n");
printf("----- ------\n");
printf("----- 菜单 ------\n");
printf("----- ------\n");
printf("----- [0]退出 -----\n");
printf("----- [1]录入 -----\n");
printf("----- [2]计算各科平均分 -----\n");
printf("----- [3]按平均分排序 -----\n");
printf("----- [4]按学号排序 -----\n");
printf("----- [5]查看挂科学生信息 -----\n");
printf("----- [6]查看全部学生信息 -----\n");
printf("\n");
printf("--------------------------------------------------------------\n");
student *h=NULL;
int n;
printf("PS: 不要忘记先录入成绩哦__");
printf("选择菜单编号: ");
scanf("%d",&n);
switch(n)
{
case 0: printf("end......\n");destroy(h);exit(0); //退出
case 1: h=addstu();break; //录入
case 2: ave(h);break; //计算各科平均分
case 3: insert_ave(h);break; //按平均分排序
case 4: insert_num(h);break; //按学号排序
case 5: bad(h);break; //查看挂科学生信息
case 6: all(h);break; //查看全部学生信息
default : printf("请在 0~6 之间进行选择!\n");break;
}
}
int main()
{
if(login()==0)return 0;
while(1)
{
menu();
}
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)