C#影院售票系统
#include<stdio.h>#include<stdlib.h>
#include<string.h>
typedef struct a{
char name; //电影名
int grade; //序号
int number;//一天场次
int time;//电影时长
int hall; //展厅号
double price;//票价
char timeline; //时间段
struct a* next;
}Cinema,*List;
List head=NULL;
intLogin(); // 登陆
void Menu(); // 主菜单
int Choose(); //选择功能
void Creathead(); // 创建头结点
void Reload(); //载入本地文件
void Search(); //查找电影时间 进行购买
void DisplayAll();//显示所有电影进行购买
void Save(); //保存
int main()
{
if(Login()==0) return 0;
Creathead();
// 加载文件中的数据
Reload();
while (1)
{
Menu();
switch (Choose())
{
case 1:
Search(); break;
case 2:
DisplayAll(); break;
case 3:
Save(); break;
case 0:
return 0;
}
}
}
// 登录页面
int Login()
{
while (1)
{
printf("----------------------------------------------------------\n");
printf("* *\n");
printf("* 1:用户登录 *\n");
printf("* 2:用户注册 *\n");
printf("* *\n");
printf("----------------------------------------------------------\n");
int choose;
char fusername, fpassword;
char username, password;
scanf("%d", &choose);
if (choose == 1)
{
FILE* f1 = fopen("user.txt", "r");
printf("请输入用户名:");
scanf("%s", username);
getchar();
printf("请输入密码:");
char c;
int i = 0;
while ((c = getch()) != '\r')
{
if (c == '\b')
{
i--;
putchar('\b');
putchar(' ');
putchar('\b');
}
else
{
password = c;
i++;
putchar('*');
}
}
printf("\n");
password = '\0';
fscanf(f1, "%s %s", fusername, fpassword);
if ((strcmp(fusername, username) == 0) && (strcmp(fpassword, password)) == 0)
{
printf("登陆成功\n");
getch();
system("cls");
return 1;
}
else
{
printf("用户名或密码错误");
getch();
return 0;
}
}
else if (choose == 2)
{
FILE* f2 = fopen("user.txt", "w");
printf("请输入用户名:");
scanf("%s", username);
printf("请输入密码:");
scanf("%s", password);
fprintf(f2, "%s %s", username, password);
fclose(f2);
system("cls");
printf("注册成功!\n");
}
}
}
//主菜单
void Menu()
{
printf("\n\n");
printf("-----------------------------影院售票管理--------------------------------\n");
printf("\t1.查找某个电影时间段购买 2.显示所有电影信息进行购买 3.保存 0.退出\n");
printf("\n-------------------------------------------------------------------------\n");
}
//选择
int Choose(){
int n;
printf("请输入序号:");
while (scanf("%d", &n) != 1 || n < 0 || n>8)
{
printf("请重新输入:");
scanf("%d", &n);
}
return n;
}
//加载 data.txt文件的数据
void Reload()
{
int number,time,hall,count=0,grade;
double price;
char name;
char timeline;
List b=head;
FILE* p = fopen("data.txt", "a+");
while (fscanf(p, "%s%d%d%d%d%lf",name,&grade,&number,&time,&hall,&price) == 6)
{
List a = (List)malloc(sizeof(Cinema));
b->next=a;
a->grade = grade;
a->price = price;
a->time = time;
a->hall = hall;
a->number = number;
strcpy(a->name, name);
int i;
for(i=0;i<number;i++)
{
fscanf(p,"%s",timeline);
strcpy(a->timeline, timeline);
}
b = b->next;
count++;
}
if(count!=0)
b->next = NULL;
printf("成功载入%d条信息\n\n", count);
fclose(p);
}
//创造头节点
void Creathead()
{
List a=(List)malloc(sizeof(Cinema));
a->price = 0;
a->time = 0;
a->hall = 0;
a->number = 0;
a->grade = 0;
strcpy(a->name, "0");
// strcpy(a->timeline, "0");
a->next=NULL;
head=a;
}
//查找某个时间的
void Search()
{
int flag = 1;
List a,b;
a=b = head->next;
char name;
printf("输入要查找的电影时间段:");
scanf("%s", name);
printf("\n");
while(a->time==name)
{
b=a;
a=b->next;
if (a== NULL)
{
printf("查找失败\n\n");
flag = 0;
break;
}
}
if(flag)
{
printf("电影名\t\t序号\t\t场次\t\t时长\t\t展厅号\t\t票价\t\t上映时间段\n");
printf("---------------------------------------------------------");
printf("---------------------------------------------------\n");
printf("%*s\t%d\t\t%d\t\t%d\t\t%d\t\t%.2lf\t\t%s\n",-10,a->name,a->grade,a->number,a->time,a->hall,a->price,a->timeline);
int i;
for(i=1;i<a->number;i++)
printf("\t\t\t\t\t\t\t\t\t\t\t\t[%d]%s\n",i+1,a->timeline);
printf("\n");
}
printf("\n\n");
printf("选择购买的序号");
char n ;
scanf("%s", &n);
printf("购买成功");
getchar();
getchar();
system("cls");
}
// 显示所有时间 进行购买
void DisplayAll()
{
system("cls");
List a, b;
a = b = head->next;
if (head->next == NULL)
{
printf("无数据");
getchar();
getchar();
system("cls");
return;
}
printf("电影名\t\t序号\t\t场次\t\t时长\t\t展厅号\t\t票价\t\t上映时间段\n");
printf("---------------------------------------------------------");
printf("---------------------------------------------------\n");
while (a!=NULL)
{
int i;
int x=1 ;
printf("%d\n",x);
x=x+1;
printf("%*s\t%d\t\t%d\t\t%d\t\t%d\t\t%.2lf\t\t%s\n",-10,a->name,a->grade,a->number,a->time,a->hall,a->price,a->timeline);
for(i=1;i<a->number;i++)
printf("\t\t\t\t\t\t\t\t\t\t\t\t[%d]%s\n",i+1,a->timeline);
printf("\n");
b = a;
a = b->next;
}
printf("选择购买的序号");
char n ;
scanf("%s", &n);
printf("购买成功");
getchar();
getchar();
system("cls");
}
//保存数据
void Save()
{
if (head->next == NULL)
{
printf("未录入信息\n\n");
return;
}
List a=head->next,b=head;
FILE *p=fopen("data.txt","w");
while(a!=NULL)
{
fprintf(p, "%s %d %d %d %d %.2lf ", a->name,a->grade, a->number, a->time, a->hall, a->price);
int i;
for(i=0;i< a->number;i++)
fprintf(p,"%s ",a->timeline);
fprintf(p, "\n");
b=a;
a=a->next;
}
fclose(p);
printf("保存成功");
getch();
system("cls");
}
学校了,看来不错 楼主写的很不错,学到了很多。点个赞 写的不错,看代码质量很高,期待能获取到你更多的分享啊 学习了,看来不错 学习中,感谢楼主 {:301_1008:} 我书读得少,您别骗我。。。这是C# ??? 学习一下,谢谢大佬! 感谢分享,等会试试 学习到了