📄 stusco.c
字号:
#include "stdio.h"
#include "conio.h"
#include "malloc.h"
#define LEN sizeof(struct student)
#define NULL 0
struct student
{long num;
char name[20];
float score[3];
float aver;
struct student *next;
}NODE,*NODEP;
int n;
main()
{
void mainmenu(void);
void menu2(void);
void menu5(void);
struct student * creat(void );
void print(struct student * );
struct student *del(struct student *,long);
struct student *insert(struct student *,struct student *stud);
struct student * load(void);
void save(struct student *);
struct student * modify(struct student *);
void sea_name(struct student * );
void sort_num(struct student *);
void sort_name(struct student *);
void sort_aver(struct student *);
void exit();
struct student *head,*p1,*stud;
int op,a2,a5;
float temp[3];
long d_num=0;
head=NULL;
p1=NULL;
if((head=load())==NULL)
{ printf("@@@@@@@@@@@@@@@@@@@@@ WELCIOME TO THE SCORE SYSTEM @@@@@@@@@@@@@@@@@@@@@\n");
printf("@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@\n");
printf("@@@@@@@@@ Please build the new records @@@@@@@@@\n");
printf("@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@\n");
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
printf(" &&when input 0,end \n\n");
head=creat();
printf("\n\n Now ,please press any key to print the information of all the students by number...\n\n");
getch();
clrscr();
sort_num(head);
print(head);
printf("\n\n\n Please any key to go to the main mune...");
getch();
clrscr();
mainmenu();
}
else
loop1:
{printf("\n\n\n Please any key to return the main mune...");
getch();
clrscr();
mainmenu();
}
while(1)
{ op=getchar();
if (op=='8')
{clrscr();
exit();
break;}
switch(op)
{ case '1': clrscr();
stud=(struct student*)malloc(LEN);
printf("\n=======@ Please input the additional student's information @=======");
loop:
{ printf("\n\n Please input the student's number :");
scanf("%lu",&stud->num);
}
p1=head;
while((p1->num!=stud->num)&&(p1->next!=NULL))p1=p1->next;
if(p1->num!=stud->num)
{ printf("\n Please input the name:");
scanf("%s",stud->name);
printf("\n Please input the score of Chinese(0~100):");
scanf("%f",&temp[0]);
if(temp[0]<0||temp[0]>100)
{
printf("Input the wrong mark,please input again:");
scanf("%f",&temp[0]);
}
printf("\n Please input the score of English(0~100):");
scanf("%f",&temp[1]);
if(temp[1]<0||temp[1]>100)
{
printf("Input the wrong mark,please input again:");
scanf("%f",&temp[1]);
}
printf("\n Please input the score of maths(0~100):");
scanf("%f",&temp[2]);
if(temp[2]<0||temp[2]>100)
{
printf("Input the wrong mark,please input again:");
scanf("%f",&temp[2]);
} stud->score[0]=temp[0];
stud->score[1]=temp[1];
stud->score[2]=temp[2];
stud->aver=(temp[0]+temp[1]+temp[2])/3;
}
else
{ printf("\n Sorry!This student's information has exited.Please input again...\n");
goto loop;
}
head=insert(head,stud);
printf("\n\n Congratulations! Add Successfully ...\n\n");
printf("\n\n Please press any key to print all the information by number..." );
getch();
clrscr();
print(head);
printf("\n\n Please press any key to return Mian Mune ...");
getch();
clrscr();
mainmenu();
break;
case '2':clrscr();
menu2();
while(1)
{
a2=getchar();
if(a2=='3')goto loop1;
switch(a2)
{ case '1':clrscr();
sea_name(head);
printf("\n\n Please press any key to return Require Record Menu...");
getch();
clrscr();
menu2();
break;
case '2':clrscr();
print(head);
printf("\n\n Please press any keys to return Require Record Menu...");
getch();
clrscr();
menu2();
break;
}}
case '3':clrscr();
printf("\n\n Please input the student's number you want to delete:");
scanf("%lu",&d_num);
head=del(head,d_num);
printf("\n\n\n Press any key to output the new records ...\n");
getch();
clrscr();
print(head);
printf("\n\n Please press any key to return Mian Menu ...");
getch();
clrscr();
mainmenu();
break;
case '4':clrscr();
head=modify(head);
printf("\n\n\n Press any key to output the new records ...\n");
getch();
clrscr();
print(head);
printf("\n\n\n\n Please press any keys to return Mian Menu ...");
getch();
clrscr();
mainmenu();
break;
case '5':clrscr();
menu5();
while(1)
{
a5=getchar();
if(a5=='4')goto loop1;
switch(a5)
{ case '1':clrscr();
sort_num(head);
print(head);
printf("\n\n Please press any keys to return Sort Records Menu...");
getch();
clrscr();
menu5();
break;
case '2':clrscr();
sort_name(head);
print(head);
sort_num(head);
printf("\n\n Please press any keys to return Sort Records Menu...");
getch();
clrscr();
menu5();
break;
case '3':clrscr();
sort_aver(head);
print(head);
sort_num(head);
printf("\n\n Please press any keys to return Sort Records Menu...");
getch();
clrscr();
menu5();
break;
}}
case '6': clrscr();
save(head);
printf("\n\n\n\n\n Please press any key to trturn mainmune ...\n");
getch();
clrscr();
mainmenu();
break;
case '7': clrscr();
load();
printf("\n\n\n\n Please press any key to return Main Menu ...\n");
getch();
clrscr();
mainmenu();
break;
}}
getch();
}
struct student *creat(void)
{ struct student *head;
struct student *p1,*p2,*p0;
float temp[3];
n=0;
head=NULL;
p0=NULL;
p1=p2=(struct student*)malloc(LEN);
printf("\n Please input the student's number(%d):",n+1);
scanf("%lu",&p1->num);
if(p1->num==0) goto end;
printf("\n Please input the name:");
scanf("%s",p1->name);
printf("\n Please input the score of Chinese(0~100):");
scanf("%f",&temp[0]);
if(temp[0]<0||temp[0]>100)
{
printf("Input the wrong mark,please input again:");
scanf("%f",&temp[0]);
}
printf("\n Please input the score of English(0~100):");
scanf("%f",&temp[1]);
if(temp[1]<0||temp[1]>100)
{
printf("Input the wrong mark,please input again:");
scanf("%f",&temp[1]);
}
printf("\n Please input the score of maths(0~100):");
scanf("%f",&temp[2]);
if(temp[2]<0||temp[2]>100)
{
printf("Input the wrong mark,please input again:");
scanf("%f",&temp[2]);
}
p1->score[0]=temp[0];
p1->score[1]=temp[1];
p1->score[2]=temp[2];
p1->aver=(temp[0]+temp[1]+temp[2])/3;
while(1)
{ n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
p1->next=NULL;
loop:
{
printf("\n\n Please input the number (%d) :",n+1);
scanf("%lu",&p1->num);
}
if(p1->num==0) goto end;
p0=head;
while((p0->num!=p1->num)&&(p0->next!=NULL))p0=p0->next;
if(p1->num!=p0->num)
{
printf("\n Please input the name:");
scanf("%s",p1->name);
printf("\n Please input the score of Chinese(0~100):");
scanf("%f",&temp[0]);
if(temp[0]<0||temp[0]>100)
{
printf("Input the wrong mark,please input again:");
scanf("%f",&temp[0]);
}
printf("\n Please input the score of English(0~100):");
scanf("%f",&temp[1]);
if(temp[1]<0||temp[1]>100)
{
printf("Input the wrong mark,please input again:");
scanf("%f",&temp[1]);
}
printf("\n Please input the score of maths(0~100):");
scanf("%f",&temp[2]);
if(temp[2]<0||temp[2]>100)
{
printf("Input the wrong mark,please input again:");
scanf("%f",&temp[2]);
}
p1->score[0]=temp[0];
p1->score[1]=temp[1];
p1->score[2]=temp[2];
p1->aver=(temp[0]+temp[1]+temp[2])/3;
}
else
{ printf(" This student's number (%lu) has exist.Please input number again.\n\n",p1->num);
goto loop;
}
}
end:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -