C语言课程设计Word格式文档下载.docx
《C语言课程设计Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C语言课程设计Word格式文档下载.docx(21页珍藏版)》请在冰豆网上搜索。
Add
Delete:
四、课程设计小结
1、熟练掌握链表的创建、添加、查找、修改、删除、输出。
2、熟练掌握自定义函数及主函数调用。
3、熟练掌握C语言基础知识。
4、插入指针new时,要有newnext=NULL。
5、fflush(stdin);
用于消除缓冲区,无法正确输入时要消除缓冲区
五、附源代码
#include<
stdio.h>
conio.h>
stdlib.h>
#defineNULL0
string.h>
structtushu/*结构体*/
{
charcno[8],cname[12],cwiter[8],cpublish[8];
intikc;
structtushu*next;
};
structtushu*create();
structtushu*output(structtushu*head);
voidmenu();
intmenu0();
structtushu*find(structtushu*head);
structtushu*witerfind(structtushu*head);
structtushu*publishfind(structtushu*head);
voidmenu00();
structtushu*find0(structtushu*head);
voiderror();
voidchange(structtushu*head);
structtushu*delete(structtushu*head);
voidseek(structtushu*head);
structtushu*add(structtushu*head);
menu000();
structtushu*nofind(structtushu*head);
structtushu*namefind(structtushu*head);
structtushu*create()/*创建*/
structtushu*head=NULL,*new,*tail;
intii=1;
clrscr();
fflush(stdin);
while
(1)
{
clrscr();
new=(structtushu*)malloc(sizeof(structtushu));
new->
next=NULL;
printf("
\t\t\tputinto%dbook'
informaitaion:
"
ii);
\n"
);
\t1.putintono(ifno==0toend):
gets(new->
cno);
if(strcmp(new->
cno,"
0"
)==0)
{
free(new);
returnhead;
}
\t2.putintoname:
cname);
\t3.putintowiter:
cwiter);
\t4.putintopublish:
cpublish);
\t5.putintokucun:
scanf("
%d"
&
new->
ikc);
if(ii==1)
next=head;
tail=head=new;
}
else
tail->
next=new;
tail=new;
ii++;
}
structtushu*output(structtushu*head)/*输出*/
structtushu*p=head;
no\tname\twiter\tpublish\tkucun\n"
if(p==NULL)
printf("
Noidata"
while(p!
=NULL)
%-s\t%-s\t%-s\t%-s\t%-d\n"
p->
cno,p->
cname,p->
cwiter,p->
cpublish,p->
p=p->
next;
getchar();
voidmenu()/*主菜单*/
{
inti,ii=1;
for(i=0;
i<
8;
i++)printf("
\t\t"
for(i=1;
27;
i++)
%c"
\n\t\t%cWelcometobooksystem%c\n"
ii,ii);
\n\t\t\t1.create.\n\t\t\t2.seek.\n\t\t\t3.add.\n\t\t\t4.delete.\n\t\t\t5.change.\n\t\t\t6.output.\n\t\t\t7.exit.\n\t\t\t%cchoose:
ii+4);
intmenu0()/*选择菜单*/
intchoose;
choose);
returnchoose;
structtushu*find(structtushu*head)/*查找(书号、书名)*/
charwiter[8],publish[8],no,name;
structtushu*p=head,*q;
menu00();
choose=menu0();
while(choose!
=3)
switch(choose)
case1:
clrscr();
putintowitername:
gets(witer);
=NULL&
&
strcmp(p->
cwiter,witer)!
=0)
{
}
if(p==NULL)
printf("
\nnoposition"
fflush(stdin);
getchar();
break;
else
returnp;
case2:
clrscr();
putintopublishname:
gets(publish);
cpublish,publish)!
{
}
default:
error();
menu00();
voidmenu00()
intii=6;
\t\t1.witer\n\t\t2.publish\n\t\t3.Exit\n\t\t%cchoose:
structtushu*find0(structtushu*head)/*查找(删除,修改)*/
charcno[8],cname[12],no[8],name[8];
menu000();
clrscr();
putintono:
gets(no);
if(strcmp(head->
cno,no)==0)
else
{
q=p->
while(q!
strcmp(q->
cno,no)!
p=p->
q=p->
if(p==NULL)
printf("
else
returnp;
}
putintobookname:
gets(name);
if(strcmp(head->
cname,name)==0)
returnhead;
cname,name)!
menu000();
menu000()
\t\t1.no\n\t\t2.name\n\t\t3.Exit\n\t\t%cchoose:
structtushu*add(structtushu*head)/*添加*/
structtushu*p,*new,*q;
p=find(head);
new->
next=p->
p->
p=new;
returnhead;
voidseek(structtushu*head)/*查询*/
structtushu*p;
no\t\tname\t\twiter\t\tpublish\t\tkucun\n"
clrscr();
%-s\t\t%-s\t\t%-s\t\t%-s\t\t%-d"
structtushu*delete(structtushu*head)/*删除*/
structtushu*x,*y;
intii;
x=find0(head);
if(x==head)
y=x;
y=x->
%-s\t\t%-s\t\t%-s\t\t%-s\t\t%-d\n"
y->
cno,y->
cname,y->
cwiter,y->
cpublish,y->
Areyousuretodeleteit?
1.Yes.2.No:
ii);
if(x==head)
head=x->
free(x);
x->
next=y->
free(y);
voidchange(structtushu*head)/*修改*/
gets(y->
putintoname:
putintowiter:
putintopublish:
putintokucun:
y->
voiderror()/*错误提示*/
error,putintoagain!
!
voidmain()/*主函数*/
intchoose,ik=1;
structtushu*head=NULL;
if(ik!
=1)
fflush(stdin);
menu();
ik++;
while(choose!
=7)
{switch(choose)
case1:
head=create();
case2:
seek(head);
case3:
add(head);
case4:
head=delete(head);
case5:
change(head);
case6:
output(head);
default:
error();
if(ik!
menu();
ik++;
\t\tThanks,seeyouagain!
六、参考文献
1、《C语言程序设计》
2、GUESSnum.C