永发信息网

C语言程序100行

答案:3  悬赏:40  手机版
解决时间 2021-02-14 10:39
C语言程序100行
最佳答案
//学生成绩管理系统C代码

#include
#include
#include
#include
#include
#include
#include

#define LEN sizeof(STUDENT)

typedef struct stu
{
char num[6];
char name[5];
int score[3];
int sum;
float average;
int order;
struct stu *next;
}STUDENT;


STUDENT *init();
int menu_select();
STUDENT *create();
void print(STUDENT *head);
void search(STUDENT *head);
STUDENT *delete(STUDENT *head);
STUDENT *sort(STUDENT *head);
STUDENT *insert(STUDENT *head,STUDENT *newnode);
void save(STUDENT *head);
STUDENT *load();


main()
{
STUDENT *head,newnode;
head=init();
for(;;)
{
switch(menu_select())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:search(head);break;
case 4:head=delete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,&newnode);break;
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0);
}
}
}


STUDENT *init()
{
return NULL;
}


menu_select()
{
int n;
struct date d;
getdate(&d);
printf("press any key to enter the menu......");
getch();
clrscr();
printf("********************************************************************************\n");
printf("\t\t Welcome to\n");
printf("\n\t\t The student score manage system\n");
printf("*************************************MENU***************************************\n");
printf("\t\t\t1. Enter the record\n");
printf("\t\t\t2. Print the record\n");
printf("\t\t\t3. Search record on name\n");
printf("\t\t\t4. Delete a record\n");
printf("\t\t\t5. Sort to make new a file\n");
printf("\t\t\t6. Insert record to list\n");
printf("\t\t\t7. Save the file\n");
printf("\t\t\t8. Load the file\n");
printf("\t\t\t9. Quit\n");
printf("\n\t\t Made by Hu Haihong.\n");
printf("********************************************************************************\n");
printf("\t\t\t\t%d\\%d\\%d\n",d.da_year,d.da_mon,d.da_day);
do{
printf("\n\t\t\tEnter your choice(1~9):");
scanf("%d",&n);
}while(n<1||n>9);
return(n);
}


STUDENT *create()
{
int i,s;
STUDENT *head=NULL,*p;
clrscr();
for(;;)
{p=(STUDENT *)malloc(LEN);
if(!p)
{printf("\nOut of memory.");
return (head);
}
printf("Enter the num(0:list end):");
scanf("%s",p->num);
if(p->num[0]=='0') break;
printf("Enter the name:");
scanf("%s",p->name);
printf("Please enter the %d scores\n",3);
s=0;
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&p->score[i]);
if(p->score[i]<0 || p->score[i]>100)
printf("Data error,please enter again.\n");
}while(p->score[i]<0 || p->score[i]>100);
s=s+p->score[i];
}
p->sum=s;
p->average=(float)s/3;
p->order=0;
p->next=head;
head=p;
}
return(head);
}


void print(STUDENT *head)
{
int i=0;
STUDENT *p;
clrscr();
p=head;
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
while(p!=NULL)
{
i++;
printf("| %3d | %4s | %-4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
i, p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("-------------------------------------------------------------------------------\n");
printf("**************************************END**************************************\n");
}


void search(STUDENT *head)
{
STUDENT *p;
char s[5];
clrscr();
printf("Please enter name for searching.\n");
scanf("%s",s);
p=head;
while(strcmp(p->name,s) && p != NULL)
p=p->next;
if(p!=NULL)
{printf("\n*************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
}
else
printf("\nThere is no num %s student on the list.\n",s);
}


STUDENT *delete(STUDENT *head)
{int n;
STUDENT *p1,*p2;
char c,s[6];
clrscr();
printf("Please enter the deleted num: ");
scanf("%s",s);
p1=p2=head;
while(strcmp(p1->num,s) && p1 != NULL)
{p2=p1;
p1=p1->next;
}
if(strcmp(p1->num,s)==0)
{printf("**************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1->num,p1->name,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
printf("Are you sure to delete the student Y/N ?");
for(;;)
{scanf("%c",&c);
if(c=='n'||c=='N') break;
if(c=='y'||c=='Y')
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
n=n-1;
printf("\nNum %s student have been deleted.\n",s);
printf("Don't forget to save.\n");break;
}
}
}
else
printf("\nThere is no num %s student on the list.\n",s);
return(head);
}


STUDENT *sort(STUDENT *head)
{int i=0;
STUDENT *p1,*p2,*t,*temp;
temp=head->next;
head->next=NULL;
while(temp!=NULL)
{
t=temp;
temp=temp->next;
p1=head;
p2=head;
while(t->averageaverage&&p1!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p1==p2)
{
t->next=p1;
head=t;
}
else
{
t->next=p1;
p2->next=t;
}
}
p1=head;
while(p1!=NULL)
{
i++;
p1->order=i;
p1=p1->next;
}
printf("Sorting is sucessful.\n");
return (head);
}


STUDENT *insert(STUDENT *head,STUDENT *newnode)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head;
p0=newnode;
printf("\nPlease enter a newnode record.\n");
printf("Enter the num:");
scanf("%s",newnode->num);
printf("Enter the name:");
scanf("%s",newnode->name);
printf("Please enter the %d scores.\n",3);
sum1=0;
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&newnode->score[i]);
if(newnode->score[i]>100||newnode->score[i]<0)
printf("Data error,please enter again.\n");
}while(newnode->score[i]>100||newnode->score[i]<0);
sum1=sum1+newnode->score[i];
}
newnode->sum=sum1;
newnode->average=(float)sum1/3;
newnode->order=0;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{while((p0->averageaverage)&&(p1->next!=NULL))
{p2=p1;
p1=p1->next;
}
if(p0->average>=p1->average)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;}
}
n=n+1;
head=sort(head);
printf("\nStudent %s have been inserted.\n",newnode->name);
printf("Don't forget to save the newnode file.\n");
return(head);
}


void save(STUDENT *head)
{FILE *fp;
STUDENT *p;
char outfile[10];
printf("Enter outfile name,for example c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"wb"))==NULL)
{
printf("Cannot open the file\n");
return;
}
printf("\nSaving the file......\n");
p=head;
while(p!=NULL)
{
fwrite(p,LEN,1,fp);
p=p->next;
}
fclose(fp);
printf("Save the file successfully!\n");
}


STUDENT *load()
{STUDENT *p1,*p2,*head=NULL;
FILE *fp;
char infile[10];
printf("Enter infile name,for example c:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"rb"))==NULL)
{
printf("Can not open the file.\n");
return(head);
}
printf("\nLoading the file!\n");
p1=(STUDENT *)malloc(LEN);
if(!p1)
{
printf("Out of memory!\n");
return(head);
}
head=p1;
while(!feof(fp))
{
if(fread(p1,LEN,1,fp)!=1) break;
p1->next=(STUDENT *)malloc(LEN);
if(!p1->next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1;
p1=p1->next;
}
p2->next=NULL;
fclose(fp);
printf("You have success to read data from the file!\n");
return (head);
}
满意请采纳。
全部回答
//学生成绩管理系统C代码

#include
#include
#include
#include
#include
#include
#include
#define LEN sizeof(STUDENT)
typedef struct stu
{
char num[6];
char name[5];
int score[3];
int sum;
float average;
int order;
struct stu *next;
}STUDENT;

STUDENT *init();
int menu_select();
STUDENT *create();
void print(STUDENT *head);
void search(STUDENT *head);
STUDENT *delete(STUDENT *head);
STUDENT *sort(STUDENT *head);
STUDENT *insert(STUDENT *head,STUDENT *newnode);
void save(STUDENT *head);
STUDENT *load();

main()
{
STUDENT *head,newnode;
head=init();
for(;;)
{
switch(menu_select())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:search(head);break;
case 4:head=delete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,&newnode);break;
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0);
}
}
}

STUDENT *init()
{
return NULL;
}

menu_select()
{
int n;
struct date d;
getdate(&d);
printf("press any key to enter the menu......");
getch();
clrscr();
printf("********************************************************************************\n");
printf("\t\t Welcome to\n");
printf("\n\t\t The student score manage system\n");
printf("*************************************MENU***************************************\n");
printf("\t\t\t1. Enter the record\n");
printf("\t\t\t2. Print the record\n");
printf("\t\t\t3. Search record on name\n");
printf("\t\t\t4. Delete a record\n");
printf("\t\t\t5. Sort to make new a file\n");
printf("\t\t\t6. Insert record to list\n");
printf("\t\t\t7. Save the file\n");
printf("\t\t\t8. Load the file\n");
printf("\t\t\t9. Quit\n");
printf("\n\t\t Made by Hu Haihong.\n");
printf("********************************************************************************\n");
printf("\t\t\t\t%d\\%d\\%d\n",d.da_year,d.da_mon,d.da_day);
do{
printf("\n\t\t\tEnter your choice(1~9):");
scanf("%d",&n);
}while(n<1||n>9);
return(n);
}

STUDENT *create()
{
int i,s;
STUDENT *head=NULL,*p;
clrscr();
for(;;)
{p=(STUDENT *)malloc(LEN);
if(!p)
{printf("\nOut of memory.");
return (head);
}
printf("Enter the num(0:list end):");
scanf("%s",p->num);
if(p->num[0]=='0') break;
printf("Enter the name:");
scanf("%s",p->name);
printf("Please enter the %d scores\n",3);
s=0;
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&p->score[i]);
if(p->score[i]<0 || p->score[i]>100)
printf("Data error,please enter again.\n");
}while(p->score[i]<0 || p->score[i]>100);
s=s+p->score[i];
}
p->sum=s;
p->average=(float)s/3;
p->order=0;
p->next=head;
head=p;
}
return(head);
}

void print(STUDENT *head)
{
int i=0;
STUDENT *p;
clrscr();
p=head;
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
while(p!=NULL)
{
i++;
printf("| %3d | %4s | %-4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
i, p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("-------------------------------------------------------------------------------\n");
printf("**************************************END**************************************\n");
}

void search(STUDENT *head)
{
STUDENT *p;
char s[5];
clrscr();
printf("Please enter name for searching.\n");
scanf("%s",s);
p=head;
while(strcmp(p->name,s) && p != NULL)
p=p->next;
if(p!=NULL)
{printf("\n*************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
}
else
printf("\nThere is no num %s student on the list.\n",s);
}

STUDENT *delete(STUDENT *head)
{int n;
STUDENT *p1,*p2;
char c,s[6];
clrscr();
printf("Please enter the deleted num: ");
scanf("%s",s);
p1=p2=head;
while(strcmp(p1->num,s) && p1 != NULL)
{p2=p1;
p1=p1->next;
}
if(strcmp(p1->num,s)==0)
{printf("**************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1->num,p1->name,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
printf("Are you sure to delete the student Y/N ?");
for(;;)
{scanf("%c",&c);
if(c=='n'||c=='N') break;
if(c=='y'||c=='Y')
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
n=n-1;
printf("\nNum %s student have been deleted.\n",s);
printf("Don't forget to save.\n");break;
}
}
}
else
printf("\nThere is no num %s student on the list.\n",s);
return(head);
}

STUDENT *sort(STUDENT *head)
{int i=0;
STUDENT *p1,*p2,*t,*temp;
temp=head->next;
head->next=NULL;
while(temp!=NULL)
{
t=temp;
temp=temp->next;
p1=head;
p2=head;
while(t->averageaverage&&p1!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p1==p2)
{
t->next=p1;
head=t;
}
else
{
t->next=p1;
p2->next=t;
}
}
p1=head;
while(p1!=NULL)
{
i++;
p1->order=i;
p1=p1->next;
}
printf("Sorting is sucessful.\n");
return (head);
}

STUDENT *insert(STUDENT *head,STUDENT *newnode)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head;
p0=newnode;
printf("\nPlease enter a newnode record.\n");
printf("Enter the num:");
scanf("%s",newnode->num);
printf("Enter the name:");
scanf("%s",newnode->name);
printf("Please enter the %d scores.\n",3);
sum1=0;
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&newnode->score[i]);
if(newnode->score[i]>100||newnode->score[i]<0)
printf("Data error,please enter again.\n");
}while(newnode->score[i]>100||newnode->score[i]<0);
sum1=sum1+newnode->score[i];
}
newnode->sum=sum1;
newnode->average=(float)sum1/3;
newnode->order=0;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{while((p0->averageaverage)&&(p1->next!=NULL))
{p2=p1;
p1=p1->next;
}
if(p0->average>=p1->average)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;}
}
n=n+1;
head=sort(head);
printf("\nStudent %s have been inserted.\n",newnode->name);
printf("Don't forget to save the newnode file.\n");
return(head);
}

void save(STUDENT *head)
{FILE *fp;
STUDENT *p;
char outfile[10];
printf("Enter outfile name,for example c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"wb"))==NULL)
{
printf("Cannot open the file\n");
return;
}
printf("\nSaving the file......\n");
p=head;
while(p!=NULL)
{
fwrite(p,LEN,1,fp);
p=p->next;
}
fclose(fp);
printf("Save the file successfully!\n");
}

STUDENT *load()
{STUDENT *p1,*p2,*head=NULL;
FILE *fp;
char infile[10];
printf("Enter infile name,for example c:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"rb"))==NULL)
{
printf("Can not open the file.\n");
return(head);
}
printf("\nLoading the file!\n");
p1=(STUDENT *)malloc(LEN);
if(!p1)
{
printf("Out of memory!\n");
return(head);
}
head=p1;
while(!feof(fp))
{
if(fread(p1,LEN,1,fp)!=1) break;
p1->next=(STUDENT *)malloc(LEN);
if(!p1->next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1;
p1=p1->next;
}
p2->next=NULL;
fclose(fp);
printf("You have success to read data from the file!\n");
return (head);
}
以上回答你满意么?
//学生成绩管理系统C代码

#include
#include
#include
#include
#include
#include
#include
#define LEN sizeof(STUDENT)
typedef struct stu
{
char num[6];
char name[5];
int score[3];
int sum;
float average;
int order;
struct stu *next;
}STUDENT;

STUDENT *init();
int menu_select();
STUDENT *create();
void print(STUDENT *head);
void search(STUDENT *head);
STUDENT *delete(STUDENT *head);
STUDENT *sort(STUDENT *head);
STUDENT *insert(STUDENT *head,STUDENT *newnode);
void save(STUDENT *head);
STUDENT *load();

main()
{
STUDENT *head,newnode;
head=init();
for(;;)
{
switch(menu_select())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:search(head);break;
case 4:head=delete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,&newnode);break;
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0);
}
}
}

STUDENT *init()
{
return NULL;
}

menu_select()
{
int n;
struct date d;
getdate(&d);
printf("press any key to enter the menu......");
getch();
clrscr();
printf("********************************************************************************\n");
printf("\t\t Welcome to\n");
printf("\n\t\t The student score manage system\n");
printf("*************************************MENU***************************************\n");
printf("\t\t\t1. Enter the record\n");
printf("\t\t\t2. Print the record\n");
printf("\t\t\t3. Search record on name\n");
printf("\t\t\t4. Delete a record\n");
printf("\t\t\t5. Sort to make new a file\n");
printf("\t\t\t6. Insert record to list\n");
printf("\t\t\t7. Save the file\n");
printf("\t\t\t8. Load the file\n");
printf("\t\t\t9. Quit\n");
printf("\n\t\t Made by Hu Haihong.\n");
printf("********************************************************************************\n");
printf("\t\t\t\t%d\\%d\\%d\n",d.da_year,d.da_mon,d.da_day);
do{
printf("\n\t\t\tEnter your choice(1~9):");
scanf("%d",&n);
}while(n<1||n>9);
return(n);
}

STUDENT *create()
{
int i,s;
STUDENT *head=NULL,*p;
clrscr();
for(;;)
{p=(STUDENT *)malloc(LEN);
if(!p)
{printf("\nOut of memory.");
return (head);
}
printf("Enter the num(0:list end):");
scanf("%s",p->num);
if(p->num[0]=='0') break;
printf("Enter the name:");
scanf("%s",p->name);
printf("Please enter the %d scores\n",3);
s=0;
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&p->score[i]);
if(p->score[i]<0 || p->score[i]>100)
printf("Data error,please enter again.\n");
}while(p->score[i]<0 || p->score[i]>100);
s=s+p->score[i];
}
p->sum=s;
p->average=(float)s/3;
p->order=0;
p->next=head;
head=p;
}
return(head);
}

void print(STUDENT *head)
{
int i=0;
STUDENT *p;
clrscr();
p=head;
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
while(p!=NULL)
{
i++;
printf("| %3d | %4s | %-4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
i, p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("-------------------------------------------------------------------------------\n");
printf("**************************************END**************************************\n");
}

void search(STUDENT *head)
{
STUDENT *p;
char s[5];
clrscr();
printf("Please enter name for searching.\n");
scanf("%s",s);
p=head;
while(strcmp(p->name,s) && p != NULL)
p=p->next;
if(p!=NULL)
{printf("\n*************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
}
else
printf("\nThere is no num %s student on the list.\n",s);
}

STUDENT *delete(STUDENT *head)
{int n;
STUDENT *p1,*p2;
char c,s[6];
clrscr();
printf("Please enter the deleted num: ");
scanf("%s",s);
p1=p2=head;
while(strcmp(p1->num,s) && p1 != NULL)
{p2=p1;
p1=p1->next;
}
if(strcmp(p1->num,s)==0)
{printf("**************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1->num,p1->name,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
printf("Are you sure to delete the student Y/N ?");
for(;;)
{scanf("%c",&c);
if(c=='n'||c=='N') break;
if(c=='y'||c=='Y')
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
n=n-1;
printf("\nNum %s student have been deleted.\n",s);
printf("Don't forget to save.\n");break;
}
}
}
else
printf("\nThere is no num %s student on the list.\n",s);
return(head);
}

STUDENT *sort(STUDENT *head)
{int i=0;
STUDENT *p1,*p2,*t,*temp;
temp=head->next;
head->next=NULL;
while(temp!=NULL)
{
t=temp;
temp=temp->next;
p1=head;
p2=head;
while(t->averageaverage&&p1!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p1==p2)
{
t->next=p1;
head=t;
}
else
{
t->next=p1;
p2->next=t;
}
}
p1=head;
while(p1!=NULL)
{
i++;
p1->order=i;
p1=p1->next;
}
printf("Sorting is sucessful.\n");
return (head);
}

STUDENT *insert(STUDENT *head,STUDENT *newnode)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head;
p0=newnode;
printf("\nPlease enter a newnode record.\n");
printf("Enter the num:");
scanf("%s",newnode->num);
printf("Enter the name:");
scanf("%s",newnode->name);
printf("Please enter the %d scores.\n",3);
sum1=0;
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&newnode->score[i]);
if(newnode->score[i]>100||newnode->score[i]<0)
printf("Data error,please enter again.\n");
}while(newnode->score[i]>100||newnode->score[i]<0);
sum1=sum1+newnode->score[i];
}
newnode->sum=sum1;
newnode->average=(float)sum1/3;
newnode->order=0;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{while((p0->averageaverage)&&(p1->next!=NULL))
{p2=p1;
p1=p1->next;
}
if(p0->average>=p1->average)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;}
}
n=n+1;
head=sort(head);
printf("\nStudent %s have been inserted.\n",newnode->name);
printf("Don't forget to save the newnode file.\n");
return(head);
}

void save(STUDENT *head)
{FILE *fp;
STUDENT *p;
char outfile[10];
printf("Enter outfile name,for example c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"wb"))==NULL)
{
printf("Cannot open the file\n");
return;
}
printf("\nSaving the file......\n");
p=head;
while(p!=NULL)
{
fwrite(p,LEN,1,fp);
p=p->next;
}
fclose(fp);
printf("Save the file successfully!\n");
}

STUDENT *load()
{STUDENT *p1,*p2,*head=NULL;
FILE *fp;
char infile[10];
printf("Enter infile name,for example c:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"rb"))==NULL)
{
printf("Can not open the file.\n");
return(head);
}
printf("\nLoading the file!\n");
p1=(STUDENT *)malloc(LEN);
if(!p1)
{
printf("Out of memory!\n");
return(head);
}
head=p1;
while(!feof(fp))
{
if(fread(p1,LEN,1,fp)!=1) break;
p1->next=(STUDENT *)malloc(LEN);
if(!p1->next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1;
p1=p1->next;
}
p2->next=NULL;
fclose(fp);
printf("You have success to read data from the file!\n");
return (head);
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
爱尚婚纱(武马路中国电信对面爱尚婚纱)地址好
大张伟是哪个小学的
求<<思念会惊>>整张专辑的歌词
我们有笔30天以上的预付货款没有在付款之日的
斑马摄影怎么去啊,我要去那办事
伊开浩希浩瑙克萨拉在哪里啊,我有事要去这个
和多音字组词和
长鑫数码摄影地址好找么,我有些事要过去
我想问一下人人车是车的品牌商标,还是二手车
怎样下载红米刷机包
利发旅馆在什么地方啊,我要过去处理事情
证明 如果一个多项式恒大于等于0,则必能写成2
长鑫数码摄影地址在什么地方,想过去办事
一个年轻人对现在恋爱的看法,求过来人点评指
氧化铝 的成型、烧结、制备方法以及性能,用
推荐资讯
我家的wifi路由器老是断网,每次断网都重置一
我信用卡还没寄过来他就让我激活安不安全
读等高线地形图,回答下列问题:(10分)(1
广众批零店地址在什么地方,我要处理点事
单选题下列城市的主要区位因素的排序,符合交
win7旗舰64位,电脑连路由器,出现无法识别网
天雁菜市地址有知道的么?有点事想过去
这功放板电容怎接!哪边正负!哪个接c5或c6怎
阿里巴巴国际站的服务费用是多少?可以便宜点
陕西延长石油化建股份有限公司停车场怎么去啊
中药川莲有什么别名
亲爱的的嫂嫂生日祝福语
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?