c语言图书销售系统源代码doc.docx

上传人:b****8 文档编号:10982016 上传时间:2023-02-24 格式:DOCX 页数:55 大小:27.30KB
下载 相关 举报
c语言图书销售系统源代码doc.docx_第1页
第1页 / 共55页
c语言图书销售系统源代码doc.docx_第2页
第2页 / 共55页
c语言图书销售系统源代码doc.docx_第3页
第3页 / 共55页
c语言图书销售系统源代码doc.docx_第4页
第4页 / 共55页
c语言图书销售系统源代码doc.docx_第5页
第5页 / 共55页
点击查看更多>>
下载资源
资源描述

c语言图书销售系统源代码doc.docx

《c语言图书销售系统源代码doc.docx》由会员分享,可在线阅读,更多相关《c语言图书销售系统源代码doc.docx(55页珍藏版)》请在冰豆网上搜索。

c语言图书销售系统源代码doc.docx

c语言图书销售系统源代码doc

#include

#include

#include

#include

#include

#include

#defineLENsizeof(structbook)

#defineVLENsizeof(structvip)

#defineSLENsizeof(structsales)

structvip*vhead=NULL;

structvip*v1,*v2;

structsales*shead=NULL;

structsales*s1,*s2;

intV,S;

/*结构体定义*/

structbook

{

charbnum[12];/*书号*/

charbname[41];/*书名*/

charauthor[20];/*作者*/

floatprice;/*书价*/

intacount;/*书存在本数*/

structbook*next;

};

structsales

{

floatcount;

structsales*snext;

};

structvip

{

charvnum[12];

charvname[41];

intlevel;

floatpersum;

floatdiscount;

structvip*vnext;

};

/*函数声明*/

voidloadbook();/*自动读入书库信息*/

voidwelcome();/*欢迎界面显示*/

voidinputbook();/*增加书本信息*/

voidloadvip();

voidloadsales();/*自动录入销售信息*/

voiddaysales();/*日销售额*/

voidmonthsales();/*月销售额*/

voidyearsales();/*年销售额*/

voidsearch();/*查询书数量*/

voidsearch_by_bnum();/*通过书号查询*/

voidsearch_by_bname();/*通过书名查询*/

voidsearch_by_author();/*通过作者查询*/

voidbuy();/*购买书籍*/

voidlist();/*列出书库信息*/

voidlistvip();

voidlistsales();/*列出销售信息*/

voiddelet();/*删除书目*/

voiddelet_by_bnum();/*通过书号删除*/

voiddelet_by_bname();/*通过书名删除*/

voiddelet_by_author();/*通过作者删除*/

voidsave();/*保存记录*/

voidredef();/*修改密码*/

voidbover();/*显示已售完的书*/

voidbuy_by_huiyuan();/*会员买书*/

voidbuy_by_feihuiyuan();/*非会员买书*/

voidexit0();/*退出*/

intmenu();/*主菜单*/

voidprint2();/*显示查询菜单*/

voidprintdelete();/*显示删除菜单*/

structbook*head=NULL,*head2=NULL;/*head和head2分别用于书库的头指针和已购书的头指针*/

structbook*p1,*p2,*p3,*p4,*p5,*p6;/*p1、p2、p3用于操作书库图书,p4、p5、p6用于操作已购书*/

intsave_flag=0;/*图书信息变动标志*/

intbuy_flag=0;/*买书时,是否调用过查询功能标志*/

intshan_flag=0;/*删书时,是否调用过显示已售完书功能标志*/

intT=0;/*记录导入的书本数*/

charmima[11]="123456";/*初始密码*/

voidbookmanage();

voidsalesmanage();/*销售统计*/

intmain()/*主函数*/

{

welcome();/*欢迎界面显示*/

loadbook();

loadsales();

loadvip();/*自动导入书库信息*/

while

(1)

{

switch(menu())

{

case1:

system("cls");bookmanage();break;

case2:

system("cls");buy();break;

case3:

system("cls");listvip();break;

case4:

system("cls");;salesmanage();break;

case5:

system("cls");;break;

case0:

system("cls");exit0();break;

default:

{

printf("\n选择错误,请按主菜单提示输入您的正确选择(0~8)\n");

printf("按任意键返回继续:

");

rewind(stdin);/*清空缓冲区*/

getch();

}

}

}

return0;

}

/*菜单*/

intmenu()

{

intchoice;

system("cls");/*系统清屏*/

printf("\n*************************主菜单*************************\n\n");

printf("1.图书管理\n\n");

printf("2.销售管理\n\n");

printf("3.会员管理\n\n");

printf("4.销售额统计\n\n");

printf("5.说明\n\n");

printf("0.退出\n\n\n");

printf("请输入您的选择(0~8):

");

rewind(stdin);/*清空缓冲区*/

scanf("%d",&choice);

returnchoice;/*返回用户的选择*/

}

voidbookmanage()

{

system("cls");

intchoice1;

do

{

printf("");/*显示菜单*/

printf("*************图书管理*************");

printf("");

printf("");

printf("功能选项:

\n");

printf("1:

图书信息录入\n");

printf("2:

图书信息浏览\n");

printf("3:

图书信息查询\n");

printf("4:

图书信息删除\n");

printf("5:

图书信息保存\n");

printf("0:

返回主界面\n");

printf("");

printf("\t请选择操作:

");

scanf("%d",&choice1);

switch(choice1)/*菜单选择*/

{

case1:

system("cls");inputbook();

break;

case2:

system("cls");list();

break;

case3:

system("cls");search();

break;

case4:

system("cls");delet();

break;

case5:

system("cls");save();

break;

case0:

system("cls");

break;

}

}while(choice1!

=0);

printf("\n");

}

voidwelcome()/*欢迎界面显示*/

{

system("cls");

printf("\n\n\t\t*************欢迎使用图书销售管理系统*************\n\n");

}

voidloadbook()/*开始导入书库信息*/

{

FILE*fp;

structbook*p7;

if((fp=fopen("0.txt","r"))==NULL)/*打开文件*/

{

printf("\n\n文件打开失败或文件不存在\n");

printf("\n\n按回车键继续:

");

getchar();

return;

}

head=p3=p1=(structbook*)malloc(LEN);/*开辟一个新单元*/

p1->next=NULL;

p7=(structbook*)malloc(LEN);/*作为一个临时存储空间,避免读取文件最后的回车符*/

fscanf(fp,"%s%s%s%f%d",&p7->bnum,&p7->bname,&p7->author,&p7->price,&p7->acount);

while(!

feof(fp))

{

T++;

*p1=*p7;/*文件没结束就将p7中的信息给p1*/

p2=(structbook*)malloc(LEN);/*继续开辟一个新单元,直到文件读完*/

p1->next=p2;

p3=p1;

p1=p2;

p1->next=NULL;

fscanf(fp,"%s%s%s%f%d",&p7->bnum,&p7->bname,&p7->author,&p7->price,&p7->acount);

}

free(p2);/*释放多申请的一个单元*/

p3->next=NULL;

printf("\n\n\t\t\t%d项图书信息已经由系统自动载入.\n\n\t\t\t",T);

rewind(stdin);/*清空缓冲区*/

if(fclose(fp))

{

printf("文件关闭失败!

\n");

exit(0);

}

}

voidsalesmanage()

{

system("cls");

intchoice4;

do

{

printf("");/*显示菜单*/

printf("*************销售统计*************");

printf("");

printf("");

printf("功能选项:

\n");

printf("1:

日销售额\n");

printf("2:

月销售额\n");

printf("3:

年销售额\n");

printf("0:

返回主界面\n");

printf("");

printf("\t请选择操作:

");

scanf("%d",&choice4);

switch(choice4)/*菜单选择*/

{

case1:

system("cls");daysales();

break;

case2:

system("cls");monthsales();

break;

case3:

system("cls");yearsales();

break;

case0:

system("cls");

break;

}

}while(choice4!

=0);

printf("\n");

}

voidloadsales()/*开始导入销售信息*/

{

FILE*vfp;

if((vfp=fopen("sales.txt","r"))==NULL)/*打开文件*/

{

printf("\n\n\t\t\t销售数据文件打开失败或文件不存在\n\n");

return;

}

shead=s2=s1=(structsales*)malloc(VLEN);

while(!

feof(vfp))

{

S++;

fscanf(vfp,"%f",&s2->count);

s1=(structsales*)malloc(VLEN);

s2->snext=s1;

s2=s1;

}

s1=NULL;

s2->snext=NULL;

free(s2);

printf("\n\n\t\t\t项销售信息已经由系统自动载入.\n\n\n\n\t\t\t",S);

rewind(stdin);/*清空缓冲区*/

if(fclose(vfp))

{

printf("文件关闭失败!

\n");

exit(0);

}

}

voiddaysales()

{

}

voidmonthsales()

{

}

voidyearsales()

{

}

voidlistsales()

{

s2=shead;

{

printf("\n\n\t\t*************当前销售信息*************\n");

printf("\n\n销售额\n\n");

while(s2->count!

=NULL)

{

printf("%f",s2->count);

s2=s2->snext;

}

(s2->snext)=s2=NULL;

printf("\n");

}

printf("销售信息列出完毕,按回车键返回子菜单:

");

rewind(stdin);/*清空缓冲区*/

getchar();

system("cls");

}

voidloadvip()/*开始导入会员信息*/

{

FILE*vfp;

if((vfp=fopen("1.txt","r"))==NULL)/*打开文件*/

{

printf("\n\nvip数据文件打开失败或文件不存在\n");

printf("\n\n按回车键继续:

");

getchar();

return;

}

vhead=v2=v1=(structvip*)malloc(VLEN);

while(!

feof(vfp))

{

V++;

fscanf(vfp,"%s%s%d%f%f",&v2->vnum,&v2->vname,&v2->level,&v2->persum,&v2->discount);

v1=(structvip*)malloc(VLEN);

v2->vnext=v1;

v2=v1;

}

v1=NULL;

v2->vnext=NULL;

free(v2);

printf("\n\n\t\t\t%d项会员信息已经由系统自动载入.\n\n\n\n\t\t\t按任意键显示主菜单:

",V);

rewind(stdin);/*清空缓冲区*/

getchar();

if(fclose(vfp))

{

printf("文件关闭失败!

\n");

exit(0);

}

}

voidlistvip()

{

v2=vhead;

if(v2==NULL||V==0)/*文件不存在或书库中没书*/

{

printf("\n\n\n\n\t\t\t\t当前书库没书!

!

!

");

printf("\n\n\t\t按回车键返回:

");

rewind(stdin);/*清空缓冲区*/

getchar();

return;

}

else

{

printf("\n\n\t\t*************当前书库信息*************\n");

printf("\n\n会员号姓名等级会员总消费会员折扣\n\n");

while(v2->discount!

=NULL)

{

printf("%-18s%-10s%-5d%-6.2f%-5f\n",v2->vnum,v2->vname,v2->level,v2->persum,v2->discount);

v2=v2->vnext;

}

printf("\n");

}

printf("会员信息列出完毕,按回车键返回子菜单:

");

rewind(stdin);/*清空缓冲区*/

getchar();

system("cls");

}

voidbuy()

{

system("cls");/*系统清屏*/

intchoice1;

do

{

printf("");/*显示菜单*/

printf("*************销售管理*************");

printf("");

printf("");

printf("功能选项:

\n");

printf("1:

会员购买\n");

printf("2:

非会员购买\n");

printf("0:

返回主界面\n");

printf("");

printf("\t请选择操作:

");

scanf("%d",&choice1);

switch(choice1)/*菜单选择*/

{

case1:

system("cls");buy_by_huiyuan();

break;

case2:

system("cls");buy_by_feihuiyuan();

break;

case0:

system("cls");

break;

}

}while(choice1!

=0);

printf("\n");

}

voidbuy_by_huiyuan()/*会员买书*/

{

time_ttimep;

charvipnum[6];

structtm*p;

time(&timep);

p=gmtime(&timep);

charbnum[11];

charch;

inti=0;

floatsum=0;/*保存所购买书的总费*/

v1=vhead;

printf("\n\n\n\n\n\n\n\n\n\n\n\t\t\t请输入会员号码:

");

scanf("%s",vipnum);

while(v1!

=NULL)

{

if(strcmp(vipnum,v1->vnum)==0)

break;

elsev1=v1->vnext;

}

if(v1==NULL)

printf("对不起,你所输入的会员号不存在");

if(p1==NULL||T==0)/*文件不存在或书库中没书*/

{

printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t当前书库没书!

!

!

");

printf("\n\n\t\t\t\t按任意键返回:

");

rewind(stdin);/*清空缓冲区*/

getch();

return;

}

p5=p4=head2=(structbook*)malloc(LEN);

p4->next=NULL;

system("cls");

printf("\n\n\t\t收费标准:

一级会员打9折二级会员打8折\n\n\t\t\t三级会员打7折四级会员打6折");

do{

printf("\n\n请输入所需购买的书的书号(图书编号):

");/*书号唯一*/

rewind(stdin);/*清空缓冲区*/

gets(bnum);

p1=head;

while(p1!

=NULL)

{

if(strcmp(p1->bnum,bnum)==0)

break;

elsep1=p1->next;

}

if(p1==NULL)

{

system("cls");

printf("\n\n\n\n\n\n\n\n\n\n\t没有找到该书信息,可能书号输入有误,是否再次输入书号?

\n\n");

printf("\n\n\t\t\tY.是N.否");

rewind(stdin);/*清空缓冲区*/

ch=getchar();

if(ch=='y'||ch=='Y')

{

system("cls");

buy_flag=1;/*防止在此函数中调用时,search()函数执行了清屏*/

search();/*调用查询,通过其他途径确定书号*/

}

while

(1)

{

printf("\n\n\t\t\t提示:

若没有您要找的书,可按0结束!

!

!

");

printf("\n\n\t\t\t\t请重新输入书号:

");

rewind(stdin);/*清空缓冲区*/

gets(bnum);

if(strcmp(bnum,"0")==0)break;/*没有需要的书,结束输入书号*/

p1=head;

while(p1!

=NULL)

{

if(strcmp(p1->bnum,bnum)==0)break;

elsep1=p1->next;

}

if(p1!

=NULL)break;

system("cls");

}

}

if(p1!

=NULL)

if(p1->acount==0)

printf("\n\n\t\t\t\t该书已售完!

!

!

");

while(p1!

=NULL)

{

if(strcmp(p1->bnum,bnum)==0)/*有相同书号,循环提前结束*/

break;

elsep1=p1->next;

}

if(p1!

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

当前位置:首页 > 经管营销 > 公共行政管理

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

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