c语言宠物管理系统,请用C语言编出一个简单的宠物管理系统。
匿名用戶
1級
2008-08-11 回答
#include
#include
#include
#define E "%s%s%s%d"
#define F p->num,p->name,p->sex,&p->score
#define G " %s %-5s %s %4d\n"
#define H i->num,i->name,i->sex,i->score
#define J "number name sex score\n"
struct student /*結構體定義*/
{char num[5];
char name[20];
char sex[2];
int score;
struct student *next;
};
int m=1;
struct student *creat() /*建立單向動態鏈表函數*/
{struct student *head;
struct student *p,*q;
head=p=q=(struct student *)malloc(sizeof(struct student));
printf("please input the information of students:\n");
while(scanf(E,F),strcmp(p->num,"0")!=0)
{p=(struct student *)malloc(sizeof(struct student));
q->next=p;q=p;m++;}
q->next=NULL;
return(head);}
/*以下根據學生的姓名和學號進行操作*/
void stu_printf(struct student *p) /*輸出全部學生信息函數*/
{struct student *i;
printf(J);
for(i=p;i!=NULL;i=i->next) printf(G,H);}
void stu_search(struct student *p,char *c) /*查詢學生信息函數*/
{struct student *i;int n=0;
for(i=p;i!=NULL;i=i->next)
if(strcmp(i->num,c)==0||strcmp(i->name,c)==0)
{printf(J);printf(G,H);}
else n++;
if(n==m) printf("not found\n");}
void stu_correct(struct student *p,char *c) /*修改學生信息函數*/
{struct student *i;int n=0;
for(i=p;i!=NULL;i=i->next)
if(strcmp(i->num,c)==0||strcmp(i->name,c)==0)
scanf(E,i->num,i->name,i->sex,&i->score);
else n++;
if(n==m) printf("not found\n");
printf("\n");
stu_printf(p);
}
void stu_delete(struct student *p,char *c) /*刪除學生信息函數*/
{struct student *i,*j;int n=0;
for(i=p;i!=NULL;i=i->next)
if(strcmp(i->num,c)==0||strcmp(i->name,c)==0) break;
else n++;
if(n==m) printf("not found\n");
else {for(j=p;j->next!=i;j=j->next);
j->next=i->next;}
printf("\n");
stu_printf(p);
}
void stu_new_down(struct student *p,char *c) /*插入學生信息函數*/
{struct student *i,*j;int n=0;
for(i=p;i!=NULL;i=i->next)
if(strcmp(i->num,c)==0||strcmp(i->name,c)==0) break;
else n++;
if(n==m) printf("not found\n");
else {j=(struct student *)malloc(sizeof(struct student));
j->next=i->next;i->next=j;
scanf(E,j->num,j->name,j->sex,&j->score);}
printf("\n");
stu_printf(p);
}
main()
{char a[20];char x;int flag=1,q;
struct student *head;
void (*pt)(struct student *p,char *c); /*指向函數的指針變量*/
head=creat(); /*建立單向動態鏈表*/
while(flag)
{printf("please choose the operatian:\n");
printf("1:search\n2:corret\n3:delete\n4:new\n");
printf("choose:");
scanf("%d",&q);
switch(q) /*菜單*/
{case 1:pt=stu_search;break;
case 2:pt=stu_correct;break;
case 3:pt=stu_delete;break;
case 4:pt=stu_new_down;break;
default:printf("ERROR\n");}
printf("please input the number or name\n");
scanf("%s",a);
(*pt)(head,a);
printf("continue or not?(y/n)\n"); /*循環的菜單*/
getchar();
x=getchar();
if(x=='n') flag=0;}
getchar();
getchar();
}
總結
以上是生活随笔為你收集整理的c语言宠物管理系统,请用C语言编出一个简单的宠物管理系统。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Visual Studio 2008 S
- 下一篇: C# 转繁体转简体转拼音,超级文本大转换