c语言不会大作业怎么办,求一c语言大作业 不超过300行

5-442-png_6_0_0_84_153_762_497_892.979_1262.879-677-0-59-677.jpg

#include

#include

#include

#define SN 2

typedef struct student

{

char num[10],

name[10];

float score[SN],

sum,

avg;

struct student *next;

}STU;

/**********输入数组单元内容************/

void input(STU *p)

{

int i;

printf("please input number:\n");

scanf("%s",p->num);

printf("please input name:\n");

scanf("%s",p->name);

printf("please input %d scores:\n",SN);

p->sum=0;

for(i=0;i

{

scanf("%f",&p->score[i]);

p->sum+=p->score[i];

}

p->avg=p->sum/SN;

}

/**********创建一个链表单元**********/

STU *creat_node()

{

STU *p;

p=(STU *)malloc(sizeof(STU));

if(p == NULL)

{printf("No enough memory !");

exit(0);

}

input(p);

p->next=NULL;

return p;

}

/**********创建一个链表**********/

STU *creat_list()

{

STU *head=NULL,*tail=NULL,*p;

char str[4];

printf("List creating...\n");

do

{

printf("Do you want to continue (yes/no) :");

scanf("%s"c语言大作业心得,str);

if(strcmp(str,"yes")==0)

{

p=creat_node();

if(head==NULL){head=tail=p;continue;}

tail->next=p;

tail=p;

}

if(strcmp(str,"yes")!=0&&strcmp(str,"no")!=0)

{

printf("You must input 'yes' or 'no'.\n");

//getchar();

continue;

}

if(strcmp(str,"no")==0)break;

//getchar();

}while(1);

printf("List create end...\n\n");

4120676f77ad98789b518e77b1ce6c9a.png

return head;

}

/************输出一个链表单元**********/

void print_a_node(STU *fin)

{

int i;

printf("%s;\t%s;\t%0.2f;\t%0.2f\t",fin->num,fin->name,fin->avg,fin->sum);

for(i=0;i

printf("%0.2f\t",fin->score[i]);

putchar(10);

}

/************输出一个链表头部**********/

void print_a_head()

{

int i;

printf("number\tname\tavg\tsum\t");

for(i=0;i

printf("score%d\t",i+1);

putchar(10);

}

/************输出操作菜单**********/

void print_menu_list()

{

printf("======the operation menu list======\n");

printf("[0]-->exit\n[1]-->creat a list\n[2]-->print the list\n[3]-->insert a list node\n[4]-->select by number\n[5]-->select by name\n");

printf("[6]-->delete a list node\n[7]-->update a list node\n[8]-->order the list by score\n[9]-->print the operation menu list\n");

printf("======the operation menu list======\n");

putchar(10);

}

/************输出链表**********/

int print_list(STU *stu)

{

STU *p=stu;

if(stu==NULL)

{

printf("no records!!!\n");

return (0);

}

print_a_head();

while(p!=NULL)

{

print_a_node(p);

p=p->next;

}

putchar(10);

return (0);

}

/************插入数组单元************/

void insert(STU *stu)

{

STU *tail=stu,*p;

printf("now insert a list node...\n");

while(tail->next!=NULL)

{

tail=tail->next;

}

p=creat_node();

tail->next=p;

printf("Insert end...\n\n");

}

/**********查找字段num**********/

STU *find_num(STU *stu,char num[])

{

STU *p=stu,*pr=NULL;

while(p!=NULL)

{

if(strcmp(p->num,num)==0){pr=p;break;}

p=p->next;

}

return pr;

d58efd4e1604b0571c32a82ec71455bf.png

}

/**********查找字段name**********/

STU *find_name(STU *stu,char name[])

{

STU *p=stu,*pr=NULL;

while(p!=NULL)

{

if(strcmp(p->namec语言大作业心得,name)==0){pr=p;break;}

p=p->next;

}

return pr;

}

/************删除数组单元************/

STU * delet(STU *stu,char name[])

{

STU *p=stu,*front=stu;

if((p=find_name(stu,name))!=NULL)

{

printf("the delete record:\n");

print_a_head();

print_a_node(p);

}

else

{

printf("can not find the student!\n");

return stu;

}

p=stu;

while(p!=NULL&&strcmp(p->name,name)!=0)

{

front=p;

p=p->next;

}

if(p==stu&&front==stu)stu=NULL;

else front->next=p->next;

if(p!=NULL)p->next=NULL;

free(p);

printf("delete end...\n\n");

return stu;

}

/**********更新链表单元**********/

void update(STU *stu,char name[])

{

STU *fin;

if((fin=find_name(stu,name))!=NULL)

{

printf("before update:\n");

print_a_head();

print_a_node(fin);

}

else

{

printf("can not find the student!\n");

exit(0);

}

printf("please input the new records now...\n");

input(fin);

printf("update end...\n\n");

}

/**********数组单元顺序**********/

void order(STU *stu)

{

STU *pi,*pj,*max,temp;

int i;

if(stu!=NULL&&stu->next!=NULL)

{

for(pi=stu;pi!=NULL;pi=pi->next)

{

max=pi;

for(pj=pi->next;pj!=NULL;pj=pj->next)

c7c7ade8c35fb873f916cc7b8896af9e.png

{

if(max->sumsum)

max=pj;

}

if(max!=pi)

{

strcpy(temp.num,max->num);

strcpy(max->num,pi->num);

strcpy(pi->num,temp.num);

strcpy(temp.name,max->name);

strcpy(max->name,pi->name);

strcpy(pi->name,temp.name);

temp.sum=pi->sum;

pi->sum=max->sum;

max->sum=temp.sum;

temp.avg=max->avg;

max->avg=pi->avg;

pi->avg=temp.avg;

for(i=0;i

{

temp.score[i]=max->score[i];

max->score[i]=pi->score[i];

pi->score[i]=temp.score[i];

}

}

}

printf("order end...\n\n");

}

else

printf("do not need to order...\n\n");

}

/************释放链表**********/

void fre(STU *stu)

{

STU *p=stu,*pf;

if(stu==NULL)

{

printf("the list is NULL!\n");

exit(0);

}

while(p!=NULL)

{

pf=p;

p=p->next;

stu=p;

pf->next=NULL;

free(pf);

}

if(stu==NULL)

printf("free the list.\n");

}

STU * menu(STU *stu,int cas)

{

STU *fin=NULL;

char a[10];

switch(cas)

{

//创建数组

case 1:

if(stu!=NULL)fre(stu);

stu=creat_list();

break;

//输出数组

case 2:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

print_list(stu);

break;

//插入数组单元

case 3:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

5473681a96d00175de243386793e9bd1.png

insert(stu);

break;

//查找输出number

case 4:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

printf("please input the 'number' you want to find:\n");

scanf("%s",a);

if((fin=find_num(stu,a))!=NULL)

{

print_a_head();

print_a_node(fin);

}

else printf("no found!\n");

break;

//查找输出name

case 5:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

printf("please input the 'name' you want to find:\n");

scanf("%s",a);

if((fin=find_name(stu,a))!=NULL)

{

print_a_head();

print_a_node(fin);

putchar(10);

}

else printf("no found!\n");

break;

//删除数组单元

case 6:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

printf("please input the 'name' you want to delete:\n");

scanf("%s",a);

stu=delet(stu,a);

break;

//更新数组单元

case 7:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

printf("please input the 'name' you want to update:\n");

scanf("%s",a);

update(stu,a);

break;

//链表单元顺序

case 8:

if(stu==NULL){printf("can not do this operation!\n");putchar(10);break;}

printf("order by score\n");

order(stu);

break;

//打印数组操作菜单

case 9:

print_menu_list();

break;

default:

printf("can not do this operation!\n");putchar(10);break;

}

return stu;

}

void main()

{

STU *stu=NULL;

int cas;

//打印操作提示

print_menu_list();

//用户操作

do

{

printf("press 0~9 to choose operation!\n");

scanf("%d",&cas);

if(cas<0||cas>9){printf("you must press 0 to 9 !\n");continue;}

if(cas!=0)stu=menu(stu,cas);

if(cas==0){printf("operation end !\n");putchar(10);}

}while(cas!=0);

//释放链表

fre(stu);

}

本文来自电脑杂谈,转载请注明本文网址:

http://www.pc-fly.com/a/jisuanjixue/article-120039-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值