#include<stdio.h>
#include<string.h>
#include <stdlib.h>
struct drama
{
int num; //剧目编号
char name[50]; //剧名
char type[50]; //剧目类型
char time[50]; //演出时间
char location[50]; //演出地点
int ticket_price; //票价
int margin; //余量
int bought_num; //已购数量
};
struct drama ju[50]=
{
{},
{1,"xiaoshuo","musical","2020-12-24","shanghai",580,1027,0},
{2,"xiaoshuo","musical","2020-12-25","shanghai",623,580,0},
{3,"zaiyuanfang","musical","2020-12-25","shanghai",580,627,0},
{4,"moushageyao","musical","2021-1-1","shanghai",380,3,0}
};
int total_num=4; //初始剧目数量
int code=1023627; //初始管理员密码
void show_all(int total_num) //展示全部演出信息
{
int i=1;
printf("\n剧名 剧目类型 演出日期 演出地点 票价 余量 剧目代码\n");
for(i=1; i<=total_num; i++)
{
printf("%-15s %-10s %-13s %-12s %-6d %-7d %-5d\n",ju[i].name,ju[i].type,ju[i].time,ju[i].location,ju[i].ticket_price,ju[i].margin,ju[i].num);
};
}
void buy_ticket() //购票
{
printf("请输入您要购买的剧目的剧目代码:\n");
int d_num;
scanf("%d",&d_num);
printf("请选择购买数量(每个ID限购5张):\n");
int buy_num;
scanf("%d",&buy_num);
if(ju[d_num].margin-buy_num>=0)
{
}
while(buy_num>5||buy_num<=0)
{
printf("输入数量有误,请重新输入:");
scanf("%d",&buy_num);
}
if(ju[d_num].margin-buy_num<0)
{
printf("您购买的商品数量已超过限制人数。");
}
else
{
printf("您已成功购买%s演出的%s演出票%d张\n",ju[d_num].time,ju[d_num].name,buy_num);
ju[d_num].margin-=buy_num;
ju[d_num].bought_num+=buy_num;
}
}
void view_ticket() //查看票夹
{
int i=1;
printf("---------------------------查看票夹---------------------------");
printf("\n 剧名 剧目类型 演出日期 演出地点 数量\n");
for(i=1; i<=total_num; i++)
{
if(ju[i].bought_num!=0)
{
printf(" %-15s %-10s %-13s %-12s %-3d\n",ju[i].name,ju[i].type,ju[i].time,ju[i].location,ju[i].bought_num);
}
};
printf("--------------------------------------------------------------");
}
void help() //帮助
{
system("start D:help.txt");
}
void aboutme() //关于我们
{
system("start D:aboutme.txt");
}
void print0() //首页界面
{
printf("***************************************************\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* 请选择入口: *\n");
printf("* [1] 客户端 *\n");
printf("* [2] 管理员端 *\n");
printf("* [0] 退出系统 *\n");
printf("* *\n");
printf("* *\n");
printf("***************************************************\n");
}
void print1() //客户端界面
{
printf("*****欢迎使用悠票购票系统1.0(客户端)*****\n");
printf("* *\n");
printf("* *\n");
printf("* [1]1:查看在售演出信息 *\n");
printf("* [2]2:购票 *\n");
printf("* [3]3:帮助 *\n");
printf("* [4]4:关于我们 *\n");
printf("* [0]0:返回首页 *\n");
printf("* [5]5:查看票夹 *\n");
//printf("* 9:返回首页 *\n");
printf("* *\n");
printf("*****************************************\n");
}
void print2() //管理员端界面
{
printf("*****欢迎使用悠票购票系统1.0(管理员端)*****\n");
printf("* *\n");
printf("* *\n");
printf("* 1:增添演出信息 *\n");
printf("* 2:修改演出信息 *\n");
printf("* 0:返回首页 *\n");
printf("* 3:修改密码 *\n");
printf("* 4:帮助 *\n");
printf("* 5:关于我们 *\n");
printf("* *\n");
printf("*******************************************\n");
}
void add_drama() //增添演出信息
{
while(1)
{
//printf("%d",ifadd);
total_num++;
printf("添加剧目信息:\n");
ju[total_num].num=total_num;
printf("您现在正在添加剧目代码为%d的演出:\n",ju[total_num].num);
printf("请输入新加剧目名字:");
scanf("%s",&ju[total_num].name);
printf("请输入新加剧目的类型:\n");
scanf("%s",&ju[total_num].type);
printf("请输入新加剧目演出时间:\n");
scanf("%s",&ju[total_num].time);
printf("请输入新加剧目演出地点:\n");
scanf("%s",&ju[total_num].location);
printf("请输入新加剧目票价:\n");
scanf("%d",&ju[total_num].ticket_price);
printf("请输入新加剧目余量\n");
scanf("%d",&ju[total_num].margin);
printf("添加成功!是否还要继续添加?\n");
printf("[1]是 [0]否");
int flag;
scanf("%d",&flag);
//printf("*%d*",flag);
if(flag==0) break;
}
}
void modify_drama() //修改演出信息
{
printf("请选择您要修改的剧目的剧目代号:\n");
int m_num;
scanf("%d",&m_num);
while(1)
{
printf("请选择您要修改的选项:1.剧目名字 2.剧目类型 3.演出时间 4.演出地点 5.票价 6.余量 7.已购数量\n");
int m_choose;
scanf("%d",&m_choose);
switch(m_choose)
{
case 1:
{
printf("请输入新的剧名:\n");
char mname[50];
scanf("%s",&mname);
strcpy(ju[m_num].name,mname);
};
break;
case 2:
{
printf("请输入新的剧目类型:\n");
char mtype[50];
scanf("%s",&mtype);
strcpy(ju[m_num].type,mtype);
};
break;
case 3:
{
printf("请输入新的演出时间:\n");
char mtime[50];
scanf("%s",&mtime);
strcpy(ju[m_num].time,mtime);
};
break;
case 4:
{
printf("请输入新的演出地点:\n");
char mlocation[50];
scanf("%s",&mlocation);
strcpy(ju[m_num].location,mlocation);
};
break;
case 5:
{
printf("请输入新的票价:\n");
int mticket_price;
scanf("%d",&mticket_price);
ju[m_num].ticket_price=mticket_price;
};
break;
case 6:
{
printf("请输入新的余量:\n");
int mmargin;
scanf("%d",&mmargin);
ju[m_num].margin=mmargin;
};
break;
case 7:
{
printf("请输入新的已购数量:\n");
int mbought_num;
scanf("%d",&mbought_num);
ju[m_num].bought_num=mbought_num;
};
break;
default:
printf("操作有误!\n");
break;
}
if(m_choose>=1&&m_choose<=6) printf("修改成功!");
printf("请问是否需要继续修改剧目代码为%d的演出?\n",ju[m_num].num);
printf("[1]是 [0]否");
int ifm=-1;
scanf("%d",&ifm);
if(ifm==0) break;
}
}
void mofify_code()
{
printf("请输入旧的密码:\n");
int used_code;
scanf("%d",&used_code);
if(used_code==code)
{
int ncode;
printf("请输入新密码:\n");
scanf("%d",&ncode);
code=ncode;
}
else printf("密码错误!");
}
int main()
{
while(1)
{
print0();
int entrance=-1;
scanf("%d",&entrance);
if(entrance==0)
{
printf("感谢使用悠票购票系统3.0!\n");
return 0;
}
if(entrance==1)
{
print1();
printf("请输入您的选择:");
int choose1;
while(1)
{
scanf("%d",&choose1);
if(choose1==0)
{
//printf("谢谢使用!");
break;
}
switch(choose1)
{
case 1:
show_all(total_num);
break;
case 2:
buy_ticket();
break;
case 3:
help();
break;
case 4:
aboutme();
break;
case 5:
view_ticket();
break;
default:
break;
}
printf("\n请选择下一步操作:回到首页(0) 继续选择(1/2/3/4/5)\n");
}
}//entrance=1结束
if(entrance==2)
{
//int code=1023627;
printf("请输入管理员密码:");
int in_code;
scanf("%d",&in_code);
if(in_code==code) //密码正确模块
{
print2();
printf("请输入您的选择:");
int choose2=-1;
while(1)
{
scanf("%d",&choose2);
if(choose2==0)
{
//printf("谢谢使用!");
break;
}
switch(choose2)
{
case 1:
add_drama();
break;
case 2:
modify_drama();
break;
case 3:
mofify_code();
break;
case 4:
help();
break;
case 5:
aboutme();
break;
default:
break;
}
printf("\n请选择下一步操作:回到首页(0) 继续选择(1/2/3/4/5)\n");
}
}
else //密码错误模块
{
printf("密码错误,给爷爬\n");
}
} //entrance2结束
}
printf("运行到return 0前面了");
return 0;
}
c大作业
最新推荐文章于 2024-01-11 13:06:57 发布