?? manager.c
字號(hào):
#include <Stdio.h>
#include <Conio.h>
#include <stdlib.h>
#include <string.h>
typedef struct studentinformation
{
char num[10]; //學(xué)號(hào)
char name[20]; //學(xué)生姓名
int score[10]; //十次成績(jī)
struct studentinformation *next;
}infor;
int menu(void)
{
int a;
//clrscr();
printf("=====THE MANAGEMENT OF THE STUDENTS' ASSIGNMENT======\n\n");
printf("1-------------------------------enter students' score\n\n");
printf("2-----------------------------display student's score\n\n");
printf("3------------------display the condition of the class\n\n");
printf("4--------------------------modify the student's score\n\n");
printf("5---------------modify the information of the student\n\n");
printf("6------------------------display the statistical data\n\n");
printf("0------------------------------------------------exit\n\n");
printf("=====================================================\n\n");
printf("please enter your select:");
scanf("%d",&a);
return a;
}
infor *loadfile()
{
infor *p,*s,*head;
int i;
FILE *fp;
fp=fopen("SI.txt","r");
head=(infor*)malloc(sizeof(infor));
p=head;
do
{
s=(infor*)malloc(sizeof(infor));
fscanf(fp,"%s%s",p->num,p->name);
for(i=0;i<10;i++)
{
fscanf(fp,"%d",&(p->score[i]));
}
s->next=NULL;
p->next=s;
p=s;
}while(!feof(fp));
fclose(fp);
return head;
}
void displayscore(infor *head)
{
infor *p;
int i,number;
p=head;
//clrscr();
printf("\nPlease enter the number of the student:");
scanf("%d",&number);
while(1)
{
if(number==atoi(p->num))
{
printf("The information of the student:\n\n");
printf("%s %s\n\n",p->num,p->name);
for(i=0;i<10;i++)
printf("SCORE %d: %d\n\n",i+1,p->score[i]);
getch();
break;
}
p=p->next;
if(p->next==NULL)
{
printf("Sorry!the student hasn't been found!\n");
printf("Please make sure you have got the right number of the student!");
p=head;
getch();
//clrscr();
printf("\nPlease enter the number of the student(ENTER 0 TO EXIT):");
scanf("%d",&number);
if(number==0)
break;
}
}
}
void savescore(infor *head)
{
infor *p;
FILE *fp;
int i;
p=head;
fp=fopen("SI.txt","w");
do
{
fprintf(fp,"%s %s ",p->num,p->name);
for(i=0;i<10;i++)
fprintf(fp,"\n");
p=p->next;
}while(p->next!=NULL);
fclose(fp);
}
void loadscore(infor *head) //錄入成績(jī)
{
infor *p;
int number,time;
p=head;
//clrscr();
printf("\nPlease enter the number of the student:");
scanf("%d",&number);
while(1)
{
if(number==atoi(p->num))
{
printf("The information of the student:\n\n");
printf("%s %s\n\n",p->num,p->name);
printf("Which time of the score do you want to change?\n\n");
scanf("%d",&time);
printf("Please enter the score:");
scanf("%d",&(p->score[time-1]));
break;
}
p=p->next;
if(p->next==NULL)
{
printf("Sorry!The student hasn't been found!\n");
printf("Please make sure you have got the right number of the student!");
p=head;
getch();
//clrscr();
printf("\nPlease enter the number of the student(ENTER 0 TO EXIT):");
scanf("%d",&number);
if(number==0)
break;
}
}
savescore(head);
}
void changescore(infor *head)
{
infor *p;
int number,time;
p=head;
//clrscr();
printf("\nPlease enter the number of the student:");
scanf("%d",&number);
while(1)
{
if(number==atoi(p->num))
{
printf("The information of the student:\n\n");
printf("%s %s\n\n",p->num,p->name);
printf("Which time of the score do you want to change?\n\n");
scanf("%d",&time);
getchar();
printf("This student Score%d is %d.\n",time,p->score[time-1]);
printf("Please enter the score:");
scanf("%d",&(p->score[time-1]));
break;
}
p=p->next;
if(p->next==NULL)
{
printf("Sorry!The student hasn't been found!\n");
printf("Please make sure you have got the right number of the student!");
p=head;
getch();
//clrscr();
printf("\nPlease enter the number of the student(ENTER 0 TO EXIT):");
scanf("%d",&number);
if(number==0)
break;
}
}
savescore(head);
}
void displayclass(infor *head)
{
infor *p;
int i;
char classnum[10];
p=head;
//clrscr();
printf("\nPlease enter the number of the class:");
scanf("%s",classnum);
printf("\nThe information of the class:\n");
do
{
if(strncmp(classnum,p->num,6)==0)
{
printf("%s %s\n",p->num,p->name);
for(i=0;i<10;i++)
printf("%d ",p->score[i]);
printf("\n\n");
}
p=p->next;
}while(p->next!=NULL);
getch();
}
void changeinfor(infor *head)
{
infor *p;
int number;
p=head;
//clrscr();
printf("\nPlease enter the number of the student:");
scanf("%d",&number);
getchar();
while(1)
{
if(number==atoi(p->num))
{
printf("The information of the student:\n\n");
printf("%s %s\n\n",p->num,p->name);
printf("Please enter the new information(NUMBER NAME):\n");
scanf("%s%s",p->num,p->name);
break;
}
p=p->next;
if(p->next==NULL)
{
printf("Sorry!The student hasn't been found!\n");
printf("Please make sure you have got the right number of the student!");
p=head;
getch();
//clrscr();
printf("\nPlease enter the number of the student(ENTER 0 TO EXIT):");
scanf("%d",&number);
if(number==0)
break;
}
}
savescore(head);
}
void main();
void fullmark(infor *head)
{
infor *p;
int time;
p=head;
printf("Please enter which time you want to know:");
scanf("%d",&time);
while(1)
{
if(time>10||time<1)
{
printf("\nSorry!the time is between 1 to 10\n");
printf("\nPlease enter which time you want to know:");
scanf("%d",&time);
continue;
}
else
{
do
{
if(p->score[time-1]==100)
printf("%s %s\n\n",p->num,p->name);
p=p->next;
}while(p->next!=NULL);
getch();
break;
}
}
}
void lowmark(infor *head)
{
infor *p;
int time;
p=head;
printf("Please enter which time you want to know:");
scanf("%d",&time);
while(1)
{
if(time>10||time<1)
{
printf("\nSorry!the time is between 1 to 10\n");
printf("\nPlease enter which time you want to know:");
scanf("%d",&time);
continue;
}
else
{
do
{
if(p->score[time-1]<=60)
printf("%s %s\n\n",p->num,p->name);
p=p->next;
}while(p->next!=NULL);
getch();
break;
}
}
}
void average(infor *head)
{
infor *p;
int time,sum=0,i=0;
char classnum[10];
p=head;
printf("\nPlease enter the number of the class:");
scanf("%s",classnum);
printf("\nPlease enter which time you want to know:");
scanf("%d",&time);
do
{
if(strncmp(classnum,p->num,6)==0)
{
sum=sum+(p->score[time-1]);
i++;
}
p=p->next;
}while(p->next!=NULL);
printf("THE AVERAGE OF THE CLASS IS:%d",sum/i);
getch();
}
void stats(infor *head)
{
int a;
while(1)
{
//clrscr();
printf("==============================================\n\n");
printf("1---------------display the full mark student\n\n");
printf("2------------display the low mark[<60] student\n\n");
printf("3-------------display the average of the class\n\n");
printf("0----------------------return to the main menu\n\n");
printf("Please enter the function number:");
scanf("%d",&a);
switch(a)
{
case 1:
fullmark(head);
continue;
case 2:
lowmark(head);
continue;
case 3:
average(head);
continue;
case 0:
main();
default:
//clrscr();
printf("\nSorry!The function you have chosen hasn't been built!\n");
printf("Press any key to return to the menu!");
getch();
continue;
}
}
}
void main(void)
{
int select;
infor *head;
head=loadfile();
while(1)
{
select=menu();
switch(select)
{
case 1:
loadscore(head);
continue;
case 2:
displayscore(head);
continue;
case 3:
displayclass(head);
continue;
case 4:
changescore(head);
continue;
case 5:
changeinfor(head);
continue;
case 6:
stats(head);
continue;
case 0:
exit(0);
default:
//clrscr();
printf("\nSorry!The function you have chosen hasn't been built!\n");
printf("Press any key to return to the menu!");
getch();
continue;
}
}
getch();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -