#include#include#include#include#defineMax2typedefstructbook//书的信息{charbook_num[10]//书号charbook_name[20]//书名charbook_writer[10]//作者intbook_xy//书的剩余数量intbook_kc//书的总数量structbook*next}BKtypedefstructborrow//被借书的信息{charborrow_book_num[10]//借书书号charlimit_date[8]//借书归还日期}BOtypedefstructreader//
读者信息{charreader_num[10]//读者号charreader_name[10]//读者姓名intright//已借数量BOborrow[Max]//已借书信息structreader*next}RDBK*h_bookRD*h_readervoidLogin()intMenu()voidInit()voidInit_book()voidMenu_select()voidInsert_New_Book()voidFind_Book()voidadd_reader()voidPrint_reader()voidPrint_book()voidBorrow_Book()voidReturn_Book()voidSave()voidSave_Book()voidSave_Reader()voidLoad()voidLoad_Reader()voidLoad_Book()voidLogin(){system("cls")printf("\n\n\n\t\t\t欢迎使用
图书管理系统\n")printf("\n\n\t\t本程序分析者秦义学号:200907014122\n\n\n\n\n\n\n")//以前是设计者xxxxprintf("\n\n\n\t\t按任意键进入系统")getch()system("cls")}intMenu()/*主菜单*/{intdmprintf("\n\t\t图书管理系统主菜单\n")printf("=================================================\n")printf("☆\t0----退出系统☆\n")printf("☆\t1----采编入库☆\n")printf("☆\t2----登记读者☆\n")printf("☆\t3----借阅登记☆\n")printf("☆\t4---还书管理☆\n")printf("☆\t5---查询图书信息☆\n")printf("☆\t6----查询读者信息☆\n")printf("=================================================\n")printf("请选择相应的代码:")for(){scanf("%d",&dm)if(dm6)printf("\n错误!请重新输入:")elsebreak}returndm}voidMenu_select()/*主菜单选择函数*/{for(){switch(Menu())/*功能选择*/{case0:system("cls")Save()printf("\n\n\t文件保存成功!\n")printf("\n\n\t欢迎下次使用本系统!\n")getch()exit(0)case1:Insert_New_Book()breakcase2:add_reader()breakcase3:Borrow_Book()breakcase4:Return_Book()breakcase5:Print_book()breakcase6:Print_reader()breakdefault:printf("\n错误!")exit(0)}}}voidInit()/*初始化*/{Init_book()}voidInit_book()/*初始化图书信息*/{BK*p0printf("\n图书初始化开始,请输入图书信息..\n包括编号.书名.数量..\n")p0=(BK*)malloc(sizeof(BK))h_book=p0printf("\n请输入图书信息:\n")printf("图书编号:")/*输入图书编号(唯一)*/scanf("%s",p0->book_num)printf("图书名称:")/*输入图书名称*/scanf("%s",p0->book_name)printf("图书作者:")/*输入图书作者*/scanf("%s",p0->book_writer)printf("图书数量:")/*输入图书数量*/scanf("%d",&p0->book_kc)p0->book_xy=p0->book_kc/*开始时图书现有量和库存量相等*/p0->next=NULLprintf("\n图书信息初始化完毕!按任意键继续下一步 *** 作..\n")getch()system("cls")}voidInsert_New_Book()/*新书入库*/{BK*p,*p0,*p1p=p1=h_bookprintf("\n新书入库模块\n")printf("\n请输入新书信息..\n包括书号.书名.数量..\n")p0=(BK*)malloc(sizeof(BK))printf("图书编号:")scanf("%s",p0->book_num)while(strcmp(p0->book_num,p1->book_num)!=0&&p1->next!=NULL)p1=p1->nextif(strcmp(p0->book_num,p1->book_num)==0)/*此处分两种情况,若图书编号存在,则直接进库,只须输入书的数量*/{printf("\n此编号图书已存在!!直接入库!\n")printf("图书数量:")scanf("%d",&p0->book_kc)p1->book_kc+=p0->book_kcp1->book_xy+=p0->book_kc}else/*若不存在,则需要输入其他的信息,然后在进行插入 *** 作*/{printf("图书名称:")scanf("%s",p0->book_name)printf("图书作者:")scanf("%s",p0->book_writer)printf("图书数量:")scanf("%d",&p0->book_kc)while(p->next){p=p->next}if(h_book==NULL)h_book=p0/*此处分两种情况,链表中没有数据,head直接指向p0处*/elsep->next=p0/*此处分两种情况,链表中有数据,链表中最后元素的next指向p0处*/p0->next=NULLp0->book_xy=p0->book_kc}printf("\n新书入库完毕!按任意键继续下一步 *** 作..\n")getch()system("cls")}voidadd_reader()/*添加读者*/{RD*p0intiprintf("\n读者初始化开始,请输入读者信息..\n包括书证号.姓名..\n")p0=(RD*)malloc(sizeof(RD))/*申请新结点存储空间*/h_reader=p0printf("\n请输入读者的信息:\n")printf("读者书证号:")scanf("%s",p0->reader_num)printf("读者姓名:")scanf("%s",p0->reader_name)p0->right=0for(i=0iborrow[i].borrow_book_num,"0")/*所借图书直接置为0(即没有借书)*/strcpy(p0->borrow[i].limit_date,"0")}p0->next=NULLprintf("\n读者信息初始化完毕!按任意键继续下一步 *** 作..\n")getch()system("cls")}voidBorrow_Book()/*借书模块*/{BK*p0RD*p1charbo_num[10],rea_num[10],lim_date[8]intip0=h_bookp1=h_readerprintf("\n借书模块\n")printf("\n请输入借书的读者书证号:")scanf("%s",rea_num)while(p1->next!=NULL&&strcmp(rea_num,p1->reader_num)!=0)//查找读者号{p1=p1->next}if(p1->next==NULL&&strcmp(rea_num,p1->reader_num)!=0){printf("\n此读者编号不存在!按任意键返回..\n")gotoEND}printf("\n请输入你要借的书的编号:")scanf("%s",bo_num)while(strcmp(bo_num,p0->book_num)!=0&&p0->next!=NULL)//查找书号{p0=p0->next}if(p0->next==NULL&&strcmp(bo_num,p0->book_num)!=0){printf("\n此图书编号不存在!按任意键返回..\n")}elseif(p0->book_xyright>=Max){printf("\n不好意思,借书数目已满!不能借书!\n按任意键返回.")}elseif(strcmp(p1->borrow[0].borrow_book_num,"0")!=0){for(i=0iborrow[i].borrow_book_num,bo_num)==0){printf("\n抱歉!同一个读者不能同借两本相同的书!\n")}elseif(strcmp(p1->borrow[i].borrow_book_num,"0")==0){printf("\n请输入你要归还图书的日期:")scanf("%s",lim_date)strcpy(p1->borrow[p1->right++].borrow_book_num,bo_num)strcpy(p1->borrow[p1->right-1].limit_date,lim_date)p0->book_xy--printf("\n读者编号%s借书完毕!按任意键继续下步 *** 作..",p1->reader_num)}}}else{printf("\n请输入你要归还图书的日期:")scanf("%s",lim_date)strcpy(p1->borrow[p1->right++].borrow_book_num,bo_num)strcpy(p1->borrow[p1->right-1].limit_date,lim_date)p0->book_xy--printf("\n读者编号%s借书完毕!按任意键继续下步 *** 作..",p1->reader_num)}END:getch()system("cls")}voidReturn_Book()/*还书模块*/{BK*pRD*qinti,j,find=0charreturn_book_num[10],return_reader_num[10]p=h_bookq=h_readerprintf("\n还书模块\n")printf("\n请输入要还书的读者编号:")scanf("%s",return_reader_num)while(q->next!=NULL&&strcmp(return_reader_num,q->reader_num)!=0)q=q->nextif(q->next==NULL&&strcmp(return_reader_num,q->reader_num)!=0){find=2printf("\n此读者编号不存在!按任意键返回..\n")gotoend}printf("\n请输入读者还书的编号:")scanf("%s",return_book_num)while(p->next!=NULL&&strcmp(return_book_num,p->book_num)!=0)p=p->nextif(p->next==NULL&&strcmp(return_book_num,p->book_num)!=0){find=2printf("\n错误!此图书编号不存在!按任意键返回..\n")gotoend}for(i=0iborrow[i].borrow_book_num)==0)/*如果此读者借了此书*/{find=1for(j=ijborrow[j].borrow_book_num,q->borrow[j+1].borrow_book_num)strcpy(q->borrow[j].limit_date,q->borrow[j+1].limit_date)}strcpy(q->borrow[Max-1].borrow_book_num,"0")strcpy(q->borrow[Max-1].limit_date,"0")p->book_xy++q->right--printf("\n编号%s的读者还书完毕!按任意键继续下步 *** 作..",return_reader_num)}if(find==0)printf("\n错误!此读者未借此书!按任意键返回..\n")end:getch()system("cls")}voidPrint_book()/*查询图书信息*/{BK*pp=h_bookprintf("\n图书信息如下:\n\n")printf("图书编号\t图书名称\t图书作者\t现有\t\t库存\n")while(p!=NULL){printf("%s\t\t%s\t\t%s\t\t%d\t\t%d\n",p->book_num,p->book_name,p->book_writer,p->book_xy,p->book_kc)p=p->next}printf("\n图书信息打印完毕!按任意键继续下一步 *** 作..")getch()system("cls")}voidPrint_reader()/*查询读者信息*/{RD*pintip=h_readerprintf("\n读者信息如下:\n\n")printf("读者书证号\t\t读者姓名\n")printf("\n")while(p!=NULL){printf("\t%s\t\t%s",p->reader_num,p->reader_name)for(i=0iborrow[i].borrow_book_num)printf("\t\t%s",p->borrow[i].limit_date)}printf("\n")p=p->next}printf("\n读者信息打印完毕!按任意键继续下一步 *** 作..")getch()system("cls")}//文件模块voidSave()/*保存信息*/{Save_Reader()Save_Book()}voidSave_Reader()/*保存读者信息*/{FILE*fp_readerRD*p,*p0p=h_readerif((fp_reader=fopen("Reader.txt","wb"))==NULL)/*创建文件,进行保存*/{printf("\n文件保存失败!\n请重新启动本系统\n")exit(0)}while(p!=NULL){if(fwrite(p,sizeof(RD),1,fp_reader)!=1)/*将链表中的信息写入文件中*/printf("\n写入文件失败!\n请重新启动本系统!\n")p0=pp=p->nextfree(p0)/*释放所有结点*/}h_reader=NULLfclose(fp_reader)/*关闭文件*/}voidSave_Book()/*保存图书信息*/{FILE*fp_book/*创建文件型指针*/BK*p,*p0p=h_bookif((fp_book=fopen("Book.txt","wb"))==NULL)/*创建文件,进行保存*/{printf("\n文件保存失败!\n请重新启动本系统\n")exit(0)}while(p!=NULL){if(fwrite(p,sizeof(BK),1,fp_book)!=1)/*将链表中的信息写入文件中*/printf("\n写入文件失败!\n请重新启动本系统!\n")p0=pp=p->nextfree(p0)}h_book=NULLfclose(fp_book)/*关闭文件*/}voidLoad()/*加载信息*/{Load_Reader()Load_Book()}voidLoad_Reader()/*加载读者信息*/{RD*p1,*p2,*p3FILE*fp/*创建文件型指针*/fp=fopen("book.txt","rb")/*打开文件*/p1=(RD*)malloc(sizeof(RD))fread(p1,sizeof(RD),1,fp)h_reader=p3=p2=p1while(!feof(fp))/*读出信息,重新链入链表*/{p1=(RD*)malloc(sizeof(RD))fread(p1,sizeof(RD),1,fp)p2->next=p1p3=p2p2=p1}p3->next=NULLfree(p1)fclose(fp)/*关闭文件*/}voidLoad_Book()/*加载图书信息*/{BK*p1,*p2,*p3FILE*fp/*创建文件型指针*/fp=fopen("Book.txt","rb")/*打开文件*/p1=(BK*)malloc(sizeof(BK))fread(p1,sizeof(BK),1,fp)h_book=p3=p2=p1while(!feof(fp))/*读出信息,重新链入链表*/{p1=(BK*)malloc(sizeof(BK))fread(p1,sizeof(BK),1,fp)p2->next=p1p3=p2p2=p1}p3->next=NULLfree(p1)fclose(fp)/*关闭文件*/}voidmain(){FILE*fp_book,*fp_reader/*创建文件型指针*/Login()if((fp_book=fopen("Book.txt","rb"))==NULL||(fp_reader=fopen("Reader.txt","rb"))==NULL){Init()}elseLoad()Menu_select()/*调用主菜单*/}#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
typedef struct
{
int no
char name[5]
int number
}Data
typedef struct node
{
Data inform
struct node* next
}LNode,*LinkList
void Onit_LinkList(LinkList L)
LinkList Creat_LinkList(LinkList L)
void Print_LinkList(LNode* L)
LinkList Search_Data(int No,LinkList L)
LinkList In_Data(Data d,LinkList L)
void Out_Data(int No,int number,LinkList L)
LinkList Sort_LinkList(LinkList L)
LNode* Compare_NO(LinkList L)
LNode* Mix(LinkList L)
int main()
{
int option
LNode* L
L=(LNode*)malloc(sizeof(LNode))
Onit_LinkList(L)
do
{
cout<<"\n----------------------------------"
<<"请选择相应的 *** 作"
<<"------------------------------\n"
<<"1.........录入货物信息"<<endl
<<"2.........查找货物并输出相应信息"<<endl
<<"3.........加入货物"<<endl
<<"4.........提取货物"<<endl
<<"5.........输出货物信息"<<endl
<<"0.........退出仓库管理系统"<<endl
cin>>option
switch(option)
{
case 0:
break
case 1: L=Creat_LinkList(L)
break
case 2:
{
int n1
LinkList L1
L1=(LNode*)malloc(sizeof(LNode))
cout<<"\n键入0退出查找。\n"
do
{
cout<<"\n输入要查找的货号:"
cin>>n1
if(n1==0)break
L1=Search_Data(n1, L)
if(L1==NULL)
{
cout<<"\n找不到指定的货物!!!!\n"
}
else
{
cout<<"------------------------------------\n"
<<"货物代号"<<setw(15)
<<"货物名称"<<setw(15)
<<"货物数量"<<endl
<<L1->inform.no<<setw(18)
<<L1->inform.name<<setw(18)
<<L1->inform.number<<endl
}
}while(n1)
break
}
case 3:
{
LinkList L1
L1=(LNode*)malloc(sizeof(LNode))
cout<<"键入0退出加入货物。\n"
do
{
Data d
cout<<"\n输入加入的货号:"
cin>>d.no
L1=Search_Data(d.no,L)
if(d.no==0)break
if(L1!=NULL)
{
cout<<"\n仓库中已存在要加入的货物,\n"
<<"只需输入加入的数量:"
cin>>d.number
}
else
{
cout<<"\n输入货物名称及数量:"
cin>>d.name>>d.number
}
L=In_Data(d,L)
}while(1)
break
}
case 4:
{
LinkList L1
L1=(LNode*)malloc(sizeof(LNode))
cout<<"\n键入0退出提取货物。\n"
do
{
int No,number
cout<<"\n输入要提取货号:"
cin>>No
if(No==0)break
L1=Search_Data(No,L)
if(L1==NULL)
{
cout<<"该货物信息不存在!!!\n"
continue
}
cout<<"------------------------------------\n"
<<"货物代号"<<setw(15)
<<"货物名称"<<setw(15)
<<"货物数量"<<endl
<<L1->inform.no<<setw(18)
<<L1->inform.name<<setw(18)
<<L1->inform.number<<endl
cout<<"\n输入提取货物的数量:"
cin>>number
Out_Data( No,number,L)
}while(1)
break
}
case 5:
{
Print_LinkList(L)
break
}
default:
cout<<"无效 *** 作!!"
break
}
}while(option)
return 0
}
void Onit_LinkList(LinkList L)
{
L->next=NULL
}
LinkList Creat_LinkList(LinkList L)
{
LNode *s,*r=L
cout<<"键入0退出录入。\n"
do
{
cout<<"\n输入货号:"
s=(LNode*)malloc(sizeof(LNode))
cin>>s->inform.no
if(s->inform.no==0)
{
free(s)
break
}
if(r->inform.no==s->inform.no)
{
cout<<"\n货号重复!!!!\n"
continue
}
cout<<"\n输入货物名称及数量:"
cin>>s->inform.name
>>s->inform.number
r->next=s
r=s
}while(1)
if(r!=NULL)r->next=NULL
L=Sort_LinkList(L)
return L
}
void Print_LinkList(LNode* L)
{
LNode *r=L
if(L->next==NULL)cout<<"仓库中无货物\n"
else
{
cout<<"------------------------------------\n"
<<"货物代号"<<setw(15)
<<"货物名称"<<setw(15)
<<"货物数量"<<endl
do
{
r=r->next
cout<<r->inform.no<<setw(18)
<<r->inform.name<<setw(18)
<<r->inform.number
<<endl
}while(r->next!=NULL)
}
}
LinkList Search_Data(int No,LinkList L)
{
LinkList r
r=L->next
while(r!=NULL &&r->inform.no!=No)
r=r->next
return r
}
LinkList In_Data(Data d,LinkList L)
{
LinkList L1
L1=(LNode*)malloc(sizeof(LNode))
L1=Search_Data(d.no,L)
if(L1==NULL)
{
LNode *r,*p,*s
r=L->next
s=L
p=(LNode*)malloc(sizeof(LNode))
p->inform.no=d.no
for(int i=0i<6i++)
{
p->inform.name[i]=d.name[i]
}
p->inform.number=d.number
while(r->inform.no<d.no)r=r->next
while(s->next!=r)s=s->next
p->next=s->next
s->next=p
}
else
L1->inform.number +=d.number
return L
}
LinkList Sort_LinkList(LinkList L)
{
LinkList new_list
LNode *r,*p,*mix
new_list=(LNode*)malloc(sizeof(LNode))
new_list->next=NULL
r=new_list
mix=Mix(L)
do
{
p=(LNode*)malloc(sizeof(LNode))
p=Compare_NO(L)
r->next=p
r=p
}while(p->inform.no<mix->inform.no)
if(r!=NULL)r->next=NULL
L=new_list
return L
}
void Out_Data(int No,int number,LinkList L)
{
LinkList L1
L1=(LNode*)malloc(sizeof(LNode))
L1=Search_Data(No,L)
if(L1->inform.number>=number)
L1->inform.number-=number
else
{
char p
cout<<"\n该货物库存不足,是否提取(Y/N):"
cin>>p
if(p=='y'||p=='Y')
{
cout<<"\n货物"<<L1->inform.name<<endl
<<"提取了"<<L1->inform.number
<<"件,还需"<<number-L1->inform.number
<<"件才能满足您的要求~~"<<endl
L1->inform.number=0
}
}
}
LNode* Compare_NO(LinkList L)
{
LNode *r,*p,*s
s=(LNode*)malloc(sizeof(LNode))
p=L->next
if(p->next==NULL)return p
r=p->next
while(r!=NULL)
{
if(p->inform.no>r->inform.no)p=r
r=r->next
}
*s=*p
while(L->next!=p)L=L->next
if(p->next==NULL)L->next=NULL
else L->next=p->next
free(p)
return s
}
LNode* Mix(LinkList L)
{
LNode *r,*p,*s
s=(LNode*)malloc(sizeof(LNode))
p=L->next
if(p->next==NULL)return p
r=p->next
while(r!=NULL)
{
if(p->inform.no<r->inform.no)p=r
r=r->next
}
return p
}
看看能用不
设一个表,购物车表,大约是
购物车(ID,用户ID,产品编号,单价,数量),其中ID为自动编号类型
当点餐时,插入一行,然后用Gridview控件显示出来
然后统计GridView里的各行单价*数量的和,即为总价格之和。
付款下订单流程是
将购物车的商品信息插入订单表,共两张表,表如下
销售单(ID,销售单号, *** 作人,订单生成时间,金额,订单状态,备注)
销售单详情(ID,销售单号,产品ID,销售价,数量)
同时删除购物车
评论列表(0条)