程序设计实验报告Word下载.docx

上传人:b****6 文档编号:21790556 上传时间:2023-02-01 格式:DOCX 页数:25 大小:44.32KB
下载 相关 举报
程序设计实验报告Word下载.docx_第1页
第1页 / 共25页
程序设计实验报告Word下载.docx_第2页
第2页 / 共25页
程序设计实验报告Word下载.docx_第3页
第3页 / 共25页
程序设计实验报告Word下载.docx_第4页
第4页 / 共25页
程序设计实验报告Word下载.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

程序设计实验报告Word下载.docx

《程序设计实验报告Word下载.docx》由会员分享,可在线阅读,更多相关《程序设计实验报告Word下载.docx(25页珍藏版)》请在冰豆网上搜索。

程序设计实验报告Word下载.docx

intno;

//分类号

charpublisher[5];

//出版单位

chartime[10];

//出版时间

floatprice;

//价格

structbooks*next;

}BOO;

3主函数声明:

BOO*create_form();

voidCipher();

//密码登入菜单

BOO*del();

//删除与修改

voidprin();

//浏览图书信息

voidsearch();

//查询图书信息

voidinsert();

voidsavefile();

voidreadfile();

voidbooks();

voidmyInsert(BOO*books);

4主函数:

intmain()

intw=1;

do

{

system("

cls"

);

puts("

\n\n\t\t****************MENU**************\n\n"

\t\t\t\t1.登入菜单\n"

\t\t\t2.退出"

\n\n\t\t************************************\n"

printf("

请输入选择(1-2):

[]\b\b"

scanf("

%d"

&

ID);

switch(ID)

{

case1:

Cipher();

break;

case2:

w=0;

}

}while(w==1);

return0;

}

5录入密码模式源代码:

voidCipher()

intn,w=1,flag=0,i=3;

chars[8];

charpassword[7]="

123456"

;

\n\nEnterpassword:

"

%s"

s);

if(!

strcmp(s,password))

flag=1;

break;

else

printf("

\n\nError!

Youonlyhave%dtimes!

Enteragain:

\n"

i-1);

i--;

}while(i>

0);

if(!

flag)

youhaveEnter3times!

exit(0);

}

\n\n\t\t**************登陆菜单*******************\n\n"

\t\t\t\t1---图书信息录入\n"

\t\t\t\t2---图书信息浏览\n"

\t\t\t\t3---图书信息查询\n"

\t\t\t\t4---图书信息的删除与修改---\n"

\t\t\t\t5---返回主菜单"

\n\n\t\t********************************************\n"

请输入选择(1-5):

scanf("

n);

switch(n)

insert();

savefile();

prin();

case3:

search();

case4:

del();

case5:

return;

6浏览

浏览的函数名为“voidprin()”,浏览选项可以将录入的图书一次显示出来。

可被主函数调用

浏览的源代码为:

voidprin()//浏览图书信息

BOO*ptr=NULL;

head=NULL;

readfile();

if(head==NULL)

\n\n\t*******NORECORDS!

*******\n"

return;

printf("

登入号书名作者名分类号出版单位出版时间价格\n"

for(ptr=head;

ptr;

ptr=ptr->

next)

%5d%10s%12s%12d%10s%12s%12f\n"

ptr->

ID,ptr->

name,

ptr->

authorname,ptr->

no,ptr->

publisher,ptr->

time,ptr->

price);

system("

pause"

7书名的读取

读取保存在”all_book.txt”中的图书信息。

读取的源代码:

voidreadfile()

BOO*newBoo=NULL;

charc,fID[15];

FILE*fp;

strcpy(fID,"

all_boo.txt"

fp=fopen(fID,"

r"

if(fp==NULL){printf("

readfileerror!

exit(0);

while(!

feof(fp))

if((c=fgetc(fp))=='

\n'

}printf("

ok"

newBoo=(BOO*)malloc(sizeof(BOO));

fscanf(fp,"

%d%s%s%d%s%s%f"

newBoo->

ID,newBoo->

newBoo->

authorname,&

no,newBoo->

publisher,newBoo->

time,&

myInsert(newBoo);

fclose(fp);

8书名的保存

保存录入的图书信并存入”all_book.txt”电子书中,以便在读取,查询,浏览中调用。

源代码为:

voidsavefile()

BOO*p;

fp=fopen("

"

w"

openfileerror!

fprintf(fp,"

for(p=head;

p;

p=p->

fprintf(fp,"

p->

ID,p->

name,p->

authorname,p->

no,p->

publisher,p->

time,p->

创建后的信息已放入'

all_boo.txt'

文件中\n"

PAUSE"

}

9书名查找

“查找”的函数名为“voidsearch_book(void)”能够对录入的图书进行查找,查找的方式有“按书名查询”和“按作者名查询”,可被主函数调用。

查找的源代码为:

voidsearch()

inta;

intt=1;

chartype[10],min[10];

l1:

system("

\n\n\t\t*********请选择查询方式*********\n"

\n\t\t\t1---按书名查询\n"

\n\t\t\t2---按作者名查询\n"

\n\t\t\t3---退出查询\n"

\n\t\t\t****************************\n"

\n\nChooseyournumber(1-3):

a);

switch(a)

case1:

请输入要查询的书名:

min);

if(strcmp(min,ptr->

name)==0)

ptr->

time,

t=0;

if(t)

\t\n未找到!

t=1;

gotol1;

case2:

请输入要查询的作者名:

type);

if(strcmp(type,ptr->

authorname)==0)

case3:

10图书信息的录入

源代码如下:

voidmyInsert(BOO*books)//红色字全体为刚刚所加的

BOO*p1,*p2;

p1=books;

head=p1;

head->

next=NULL;

else

for(p2=head;

p2;

p2=p2->

if(p2->

next==NULL)

{

p2->

next=books;

next->

break;

}

voidinsert()

BOO*ptr,*books;

intsize=sizeof(BOO);

charch='

1'

ch1;

while(ch!

='

0'

books=(BOO*)malloc(size);

输入录入的图书信息:

\n\t\t登入号:

books->

\n\t\t书名:

books->

name);

\n\t\t作者名:

authorname);

\n\t\t分类号:

no);

\n\t\t出版单位:

publisher);

\n\t\t出版时间:

time);

\n\t\t价格:

%f"

myInsert(books);

\n\n继续录入请按回车\n"

\n结束录入请按\n:

ch1=getchar();

ch=getchar();

11删除

“删除”的函数名为“voidbook_del(void)”主要功能为对录入的图书信息进行删除。

可被主函数调用。

删除的源代码为:

BOO*del()

charch,ch1;

输入想要删除的图书ID:

[]\b\b\b\b\b"

if(head->

ID==ID)

p2=head;

head=head->

next;

free(p2);

if(head==NULL)

returnNULL;

p1=head;

p2=head->

while(p2)

p1->

next=p2->

p1=p2;

p2=p2->

\n继续删除请按回车\n"

\n结束删除图书信息按0:

12信息保存在TXT中要链接

链接代码:

BOO*create_form()

BOO*head,*tail,*p;

intno,ID;

charname[5],authorname[5],publisher[5],time[5];

head=tail=NULL;

输入图书信息:

%5d%5s%12s%12s%10s%12s%12d\n"

ID,name,authorname,&

no,publisher,time,&

while(ID!

=0)

p=(BOO*)malloc(size);

p->

ID=ID;

strcpy(p->

name,name);

authorname,authorname);

publisher,publisher);

time,time);

no=no;

price=price;

head=p;

tail->

next=p;

tail=p;

%5d%5s%12s%12s%10s%12s%12d"

tail->

returnhead;

四调试与测试

在编程的过程中我们遇到了许许多多的错误,令我印象最深的调试错误有如下:

1.函数的未定义声明。

因为把一般函数写在主函数的后面而没有在前面做函数的声明,导致函数未定义声明错误。

2.两个不同类型的变量在用if语句时相比较。

3.变量的重复定义,未能成功调用函数。

4.语句的混乱导致主要功能的无法运用的。

5.也学会如果语句无法调用时,看程序运行到哪一条语句时,可以写入输出语句,如:

printf(“ok”),看是否会被输出。

五整个图书信息管理系统源代码如下:

#include<

BOO*head=NULL;

intID=0;

//定义可能为错

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1