C语言购物卡管理系统链表.docx
- 文档编号:5707704
- 上传时间:2023-05-09
- 格式:DOCX
- 页数:23
- 大小:121.65KB
C语言购物卡管理系统链表.docx
《C语言购物卡管理系统链表.docx》由会员分享,可在线阅读,更多相关《C语言购物卡管理系统链表.docx(23页珍藏版)》请在冰点文库上搜索。
C语言购物卡管理系统链表
购物卡管理系统
(一)系统主要功能模块:
(1)实现系统内制卡、发卡功能。
(2)实现系统内购物卡帐户及相关帐户管理。
(3)实现购物卡交易和合法性检查。
(4)实现购物卡交易积分功能。
(5)实现购物卡报表功能。
(6)数据以文件形式存储。
提示:
制卡:
指申请一个购物卡,但还没有使用。
发卡:
指该卡已经起用。
实现卡交易:
指从卡中消费掉一定金额。
(二)题目及要求的分析:
根据题目要求,系统应该实现以下功能:
(1)制卡:
主要是新建出一张购物卡,并输入了顾客部分信息,如姓名、密码等,但卡没有激活,依然不可使用。
(2)发卡:
激活新建的购物卡,用户能够使用卡进行各项活动。
(3)消费:
进入帐户后,取走少于帐户金额的钱款进行消费,并在帐户少减少相应的金额,增加相应的积分。
(4)存款:
进入帐户后,在金额项加上用户要存入的钱款。
(5)报表:
显示顾客购物卡上记录的所有信息,除密码外。
(6)存储:
购物卡内的信息以文件形式存储。
(7)退出:
从系统中退出。
(8)菜单:
提供良好的界面,方便用户的操作。
代码:
调用字符函数*/
通用输入输出库*/
#include
charname[20];charnumber[20];floatmoney;
charkey[10];floatjifen;
floatmid;
intpower;structcard*next;
};
save(structcard*head);voidlist();
voidjihuo();
structcard*chaxun();
save(structcard*head){
FILE*fp;
structcard*q;
q=head;
if((fp=fopen("e:
\\123.txt","ab+"))==NULL)
{
printf("无法打开\n");
exit(0);
}
while(q!
=NULL)
{
if(fwrite(q,sizeof(structcard),1,fp)!
=1){
printf("文件写入错误!
");
fclose(fp);
return(head);
}
q=q->next;
}
fclose(fp);
}
{
FILE*fp;
structcard*q;
q=head;
if((fp=fopen("e:
\\123.txt","wb"))==NULL)
{
printf("无法打开\n");
exit(0);
}
while(q!
=NULL)
{
if(fwrite(q,sizeof(structcard),1,fp)!
=1){
printf("文件写入错误!
");
fclose(fp);
return(head);
}
q=q->next;
}
fclose(fp);
structcard*duqu()//读取数据
{
structcard*head=NULL;
structcard*p1,*p2;
FILE*fp;
if((fp=fopen("e:
\\123.txt","rb+"))==NULL)
{
printf("打开文件出错\n");
exit(0);
}
while(!
feof(fp))
{
if((p1=(structcard*)malloc(sizeof(structcard)))==NULL)
{
printf("somethingiswrong!
\n");
fclose(fp);
exit(0);
}
free(p1);
break;
}
if(head==NULL)
head=p2=p1;
else
{
p2->next=p1;
p2=p1;
}
fclose(fp);
return(head);
}
structcard*createlist()
{
structcard*head,*p,*q;
inti;
charnum[20];
head=(structcard*)malloc(sizeof(structcard));
head->next=NULL;
head->money=0;
head->jifen=0;
system("cls");
do
{
printf("\n\n\t请输入要注册的卡号(六位数):
");scanf("%s",head->number);
if(strlen(head->number)!
=6)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t\t对不起您的输入有误,请重新输入!
\n\n");
*******************
\n\n\n");
Sleep(1000);system("cls");
continue;
printf("\n\n\t请输入您的名字:
");
scanf("%s",head->name);
printf("\n\n\t请输入您的密码:
");
scanf("%s",head->key);
head->power=99;
}
while(strlen(head->number)!
=6);
p=head;
system("cls");
printf("您的购物卡为:
\n\n");
积分\n\n");
printf("\t%2s%16s%13.2f%13.2f",p->name,p->number,p->
money,p->jifen);getche();
p->next=NULL;
save(head);
printf("\n\n\n\n\n\n\t\t\t");
printf("购物卡注册成功!
\n\n\n\n\t\t\t\t按任意键返
回");
getche();
}
voidcost(structcard*q){
structcard*p,*a;
p=duqu();
a=p;
while(strcmp(q->number,p->number)!
=0){
p=p->next;
system("cls");
printf("\n\n\n\n\n\n");
printf("\t\t\t请输入您的消费金额:
");
scanf("%f",&p->mid);
(p->money)=(p->money)-(p->mid);
(p->jifen)=(p->jifen)+(p->mid);
printf("\n\n\n\n\n\t\t\t显示完毕,按任意键返回子菜
单");
getche();
p=a;
save1(p);
}
voidcunkuan(structcard*q)
{
structcard*p,*a;
p=duqu();
a=p;
while(strcmp(q->number,p->number)!
=0)
{
p=p->next;
system("cls");
printf("\n\n\n\n\n\n");
printf("\t\t\t请输入您的存款金额:
");
scanf("%f",&p->mid);
(p->money)=(p->mid)+(p->money);
printf("\n\n\t\t\t
您的余额为:
%.2f",p->money);
printf("\n\n\n\n\n\t\t\t
显示完毕,按任意键返回子菜
单");
getche();
p=a;
save1(p);
}
voidxiugai(structcard*q)
{
charkey[10],num[10];
structcard*p,*a;
p=duqu();
a=p;
while(strcmp(q->number,p->number)!
=0){
p=p->next;
system("cls");
printf("\n\t\t
********************
修改账户密码
修改账户密码
*******************\n\n\n");
printf("\n\n\n\n");
printf("\t\t\t请输入您的新密码:
");
scanf("%s",num);
printf("\n\n\t\t\t请再次输入您的密码:
");
scanf("%s",key);
if(strcmp(key,num)!
=0)
{
system("cls");
*******************
\n\n\n");
}
if(strcmp(key,num)==0)
{
system("cls");
r>4"F/vv\*********************
strcpy(p->key,num);
printf("\n\n\n\n\n\n\t\t\t修改密码成功!
");
Sleep(1000);
p=a;
save1(p);
}
}
voidchaxun2(structcard*q)
{
structcard*p,*a;
p=duqu();
a=p;
while(strcmp(q->number,p->number)!
=0)
{
p=p->next;
}
system("cls");
printf("\n\t\t*
*******************
账户查询
*******************
\n\n\n");
printf("\t您的账户信息为:
\n\n\n");
printf("\n\t\t姓名卡号余额积分\n\n");
printf("\t\t%2s%16s%13.2f%13.2f",p->name,p->number,p->money,p->jifen);
printf("\n");
getch();
}
structcard*chaxun()
{
intb,i=0;
intflag=9;
structcard*head;charnum[10],key[10];
structcard*p,*head1;
head1=duqu();
p=head1;
system("cls");
printf("\n\t\t
********************
账户登陆
*******************
\n\n\n");
printf("\n\n\t请输入您的卡号(六位数):
");
scanf("%s",num);while(p!
=NULL)
if(strcmp(num,p->number)!
=0)
{
p=p->next;if(p==NULL)
printf("\n\n\t
请重新输入卡号(六位数):
");
system("cls");
scanf("%s",num);
p=head1;
continue;
}
if((p->power)==99)
{
system("cls");
printf("\n\t\t*
*******************
*******************
\n\n\n");
printf("\n\n\n\n\n\n\n\t\t\t
先激活!
");
账户登陆
对不起,该卡未激活,请
getche();
system("cls");
main();
}
if(p->power==100)
{
while(flag==9)
{
printf("\n\n\t请输入密码(六位数):
");scanf("%s",key);
if(strcmp(key,p->key)==0)
flag=10;
}
if(strcmp(key,p->key)!
=0)
{
system("cls");
r>4"F/vv\*********************
*******************
\n\n\n");
printf("\n\n\n\n\n\n\n\t\t\t
错误%次!
",i+1);
flag=9;
i++;
if(i==3)
{
system("cls");
printf("\n\n\n\n\n\n\n\t\t\t
次,系统自动返回主菜单!
");
Sleep(2000);system("cls");
return;
}
}
账户登陆
对不起,密码输入
密码输入错误三
账户查询
查询
}
if(flag==10)
break;
}
}
while
(1)
{
system("cls");
printf("
*****************************************\n");
printf("
*\n");
printf("*
*\n");
printf("
*\n");
printf("
——————————————————*\n");
printf("
*\n");
printf("*1
*\n");
printf("**\n");
printf("*2:
存款*\n");
printf("**\n");
printf("*3:
消费*\n");
printf("**\n");
printf("*4:
修改密码*\n");
printf("**\n");
printf("*5:
返回主菜单
*\n");
printf("**\n");
printf("
*****************************************\n");
printf("\n");
printf("\t\t请选择操作:
");
scanf("%d",&b);
switch(b)
{
case1:
chaxun2(p);break;
case2:
cunkuan(p);break;
case3:
cost(p);break;
case4:
xiugai(p);break;
case5:
main();
default:
printf("对不起,您的输入有误,请重新输入!
");
}
}
}
voidjihuo()
{
charx;
charnum[10];
structcard*p,*head1;
head1=duqu();
p=head1;
system("cls");
printf("\n\t\t
********************
激活购物卡
*******************
\n\n\n");
printf("\t请输入您要激活的卡号(六位数):
");
scanf("%s",num);while(p!
=NULL){
if(strcmp(num,p->number)!
=0)
{
p=p->next;
}
else
while(p==NULL)
{
system("cls");
r>4"F/vv\*********************
*******************
\n\n\n");
printf("\n\n\n\n\n\n\t\t\t
入卡号!
\n\n");
激活购物卡
没有该卡号信息,请重新输
break;
Sleep(1000);
system("cls");
printf("\n\t\t*
*******************
激活购物卡
*******************
\n\n\n");
printf("\t请重新输入您申请的卡号(六位数):
");
scanf("%s",num);
p=head1;
}
}
system("cls");
积分\n\n");
printf("\t%2s%16s%13.2f%13.2f",p->name,p->number,p->
scanf("%c",&x);
switch(x)
{
case'1':
system("cls");
*******************\n\n\n");
p->power=100;
save1(head1);
printf("\n\n\n\n\n\n\n\t\t\t");
printf("激活成功,按任意键返回主菜单");
getche();
break;
case'2':
system("cls");
getche();
break;
default:
system("cls");
printf("\n\n\n\n\n\n\n\t\t\t");
);
printf("对不起,您的输入有误,请重新输入!
Sleep(2000);
}
}
voidlist()
{
structcard*p1;
p1=duqu();
*******************
\n\n\n");
system("cls");
printf("所有购物卡信息为:
\n\n\n");
printf("\n\t姓名卡号余额积分\n\n");
while(p1!
=NULL)
{
printf("\t%2s%16s%14.2f%14.2f",p1->name,p1->number,p1->money,p1->jifen);
printf("\n");
p1=p1->next;
}main()
{
inta;
struct*head;printf("\n\n\n\n\n\n\n\n\t\t\t\t");printf("欢迎使用");
购物卡管理系统
printf("\n\n");
printf("\t******************
*******************\n");
Sleep(1000);
system("cls");
while
(1)
{
printf("\n");
printf("
*****************************************\n");
printf("*购物卡管理系统*\n");
printf("
*****************************************\n");
printf("*菜*\n");
printf("
*\n");
printf("*1:
注*\n");
printf("
*\n");
printf("*2:
激*\n");
printf("
*\n");
printf("*3:
帐户登录
*\n");
printf("
*\n");
名单
printf("*4
*\n");
printf("
*\n");
printf("*0:
退出系统
*\n");
printf("
*\n");
printf("
*****************************************\n");
printf("\n");
printf("\t\t请选择操作:
");
scanf("%d",&a);
switch(a)
{
case1:
createlist(head);
system("cls");break;
case2:
jihuo();system("cls");break;
case3:
chaxun();break;
case4:
list();
printf("\n\n\n\n\t\t\t显示完毕,按任意键返回主菜单");
getche();
system("cls");
break;
case0:
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\n\t\t\t");
printf("感谢您的使用,再见!
");
printf("\n\n\n\n\n\t\t\t\t\t");
Sleep(1000);
exit(0);
default:
system("cls");
printf("\n\n\n\t\t\t对不起!
您的输入有误!
请重新输
入。
");
printf("\n");
}
}
}
欢迎您的下载,
资料仅供参考!
致力为企业和个人提供合同协议,策划案计划书,学习资料等等
打造全网一站式需求
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 购物 管理 系统