#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h> //清屏操作
#include<errno.h> //如果文件为空,则进行相关的报错显示
#include<ctype.h>
#include<io.h> //包含文件的read,write.....
/*电影票的基本信息*/
typedef struct Node
{
char number[20]; //电影序号
char name[20]; //电影名称
char score[20]; //电影评分
char time[20]; //电影时长
char price[20]; //电影票价钱
char on_time[20]; //上映市场
struct Node *Next;
}*PStu,Stu;
/*管理员的账号和密码*/
typedef struct manager
{
char Account[20];
char Password[20];
struct manager *Next;
}Node,*LinkList;
void denglu(); //管理员账户登录
void zhuce(); //管理员账户注册
void manager(); //管理员(登录/注册)
void welcome(); //欢迎界面
int openfile1(char *manage,char *password); //将manage读取比对,看是否正确
int openfile2(char *manage,char *password); //将新注册的信息存入manage
int savefile3(PStu headNode); //将电影信息存储在film_message
int openfile4(PStu headNode); //以追加的形式打开film_message,尾部增添信息
void openfile5(PStu headNode); //删除情况下将film_message信息存储在链表中
void user(); //用户登录界面
void menu(); //进入电影票务系统主页面
void ListNode_Byhead(PStu headNode); //头插法插入信息
PStu ListNode_Byhead2(PStu headNode); //增添追加信息返回一个节点
void deleteList(PStu headNode,int n); //删除信息
void printList(PStu head); //打印信息
void reviseList(PStu headNode,int k); //修改信息
void searchList(PStu head,char *a); //查找信息
void sortList1(PStu headNode); //评分排序
void sortList2(PStu headNode); //时长排序
void sortList3(PStu headNode); //价格排序(由高到低)
void bye(); //结束退出页面
/*初始化头节点*/
PStu createList()
{
PStu headNode = (PStu)malloc(sizeof(Stu));
headNode->Next = NULL;
return headNode;
}
LinkList createNode()
{
Node *headNode = (Node*)malloc(sizeof(Node));
headNode->Next = NULL;
return headNode;
}
void denglu()
{
system("cls");
//自行输入账号和密码
char manage[20];
char password[20];
printf("\n\n\n\n\n\n\t\t\t\t\t登录账号:");
scanf("%s",manage);
getchar();
printf("\n\t\t\t\t\t登录密码:");
scanf("%s",password);
getchar();
openfile1(manage,password);
}
void zhuce()
{
system("cls");
char manage[20];
char password[20];
char password_[20];
int k = 1,i = 1;
printf("\n\n\n\n\n\n\t\t\t\t\t请输入新账号:");
scanf("%s",manage);
while(k == 1)
{
printf("\n\t\t\t\t\t请输入新密码:");
scanf("%s",password);
getchar();
printf("\n\t\t\t\t\t请再次确认密码:");
scanf("%s",password_);
if(strcmp(password,password_) == 0)
{
printf("创建成功");
openfile2(manage,password);
denglu(); //跳转至用户登录界面
k = 0;
}
else
{
printf("\n\t\t\t\t\t两次密码不同\n\t\t\t\t\t请重新输入您的密码!");
sleep(1);
system("cls");
k = 1;
}
}
}
void manager()
{
char choice;
system("cls");
getchar();
printf("\n\n\n\t\t\t\t\t\t1.登录账户\n\t\t\t\t\t\t2.注册账户");
printf("\n\t\t\t\t\t\t请您进行选择:");
scanf("%c",&choice);
switch(choice)
{
case '1':
denglu(); //进入管理员登录界面
break;
case '2':
zhuce(); //进入管理员注册页面,将信息存储在文件manager.txt
break;
}
}
void user()
{
printf("QAQ");
}
void welcome()
{
char choice;
printf("\n\n\n\n\n\t\t\t\t\t\t欢迎来到影院馆里系统");
printf("\n\t\t\t\t\t\t1.管理员登录\n\t\t\t\t\t\t2.用户登录");
printf("\n\t\t\t\t\t\t请您进行选择:");
scanf("%c",&choice);
switch(choice)
{
case '1':
manager(); //进入管理员登录界面
break;
case '2':
user(); //进入用户使用页面
break;
}
}
int openfile1(char *manage,char *password)
{
int i,l;
char choice;
FILE *fp = fopen("D:\\desk\\剧院管理系统\\manager.txt","rt+");
if(fp == NULL )
{
printf("打开文件失败");
printf("error:%s\n", strerror(errno)); //错误原因的显示
exit(1);
}
//接受文本文中的账号和密码
char manage_[20];
char password_[20];
while(fscanf(fp,"%s %s",manage_,password_) != EOF)
{
if((strcmp(manage_,manage) == 0)&&(strcmp(password_,password) == 0)) //判断是否正确
{
printf("输入正确!");
l = 1;
menu(); //进入管理员主页面
break;
}
else
{
l = 2;
}
}
fclose(fp);
if(l == 2) //若未找到对应的账户和密码,则退出系统
{
printf("\n\t\t\t\t\t本系统不存与您相匹配的信息");
sleep(1);
system("cls");
printf("\n\t\t\t\t\t1.注册新的账户\n\t\t\t\t\t2.退出系统\n\t\t\t\t\t3.重新登录\n\t\t\t\t\t请输入您的选择:");
scanf("%c",&choice);
switch(choice)
{
case '1':
zhuce();
break;
case '2':
printf("\n\t\t\t\t\t不存在此人的信息,系统将于三秒后退出系统");
sleep(1);
system("cls");
char shut[] = {"系统将于%d秒后关闭...."};
for(i = 0;i<3;i++)
{
printf("系统将于%d秒后进行关闭...",3-i); /*printf(shut,3-i);*/
sleep(1);
system("cls");
}
exit(0);
case '3':
denglu();
break;
}
}
return 1;
}
int openfile2(char *manage,char *password)
{
FILE *fp = fopen("D:\\desk\\剧院管理系统\\manager.txt","a+");
if(fp == NULL )
{
printf("打开文件失败");
printf("error:%s\n", strerror(errno)); //错误原因的显示
exit(1);
}
fprintf(fp,"\n%s %s",manage,password);
fclose(fp);
return 1;
}
int savefile3(PStu headNode)
{
headNode = headNode->Next;
FILE *fp = fopen("D:\\desk\\剧院管理系统\\film_message","w+");
if(fp == NULL )
{
printf("打开文件失败");
printf("error:%s\n", strerror(errno)); //错误原因的显示
exit(1);
}
while(headNode)
{
fprintf(fp,"%s %s %s %s %s %s\n",headNode->number,headNode->name,headNode->price,headNode->score,headNode->time,headNode->on_time);
headNode = headNode->Next;
}
fclose(fp);
return 1;
}
int openfile4(PStu k)
{
//headNode = headNode->Next;
FILE *fp = fopen("D:\\desk\\剧院管理系统\\film_message","a+");
if(fp == NULL )
{
printf("打开文件失败");
printf("error:%s\n", strerror(errno)); //错误原因的显示
exit(1);
}
fprintf(fp,"\n%s %s %s %s %s %s",k->number,k->name,k->price,k->score,k->time,k->on_time);
/*while(headNode)
{
fprintf(fp,"%s %s %s %s %s %s\n",headNode->number,headNode->name,headNode->price,headNode->score,headNode->time,headNode->on_time);
headNode = headNode->Next;
}*/
fclose(fp);
return 1;
}
void openfile5(PStu headNode)
{
char name[20];
char number[20];
char on_time[20];
char score[20];
char time[20];
char price[20];
PStu r = headNode;
FILE *fp = fopen("D:\\desk\\剧院管理系统\\film_message","rt+");
if(fp == NULL )
{
printf("打开文件失败");
printf("error:%s\n", strerror(errno)); //错误原因的显示
exit(1);
}
while(fscanf(fp,"%s%s%s%s%s%s",number,name,price,score,time,on_time) != EOF)
{
PStu p = (PStu)malloc(sizeof(Stu));
r->Next = p;
strcpy(p->name ,name);
strcpy(p->number ,number);
strcpy(p->score ,score);
strcpy(p->time ,time);
strcpy(p->price,price);
strcpy(p->on_time ,on_time);
r = p;
}
r->Next = NULL;
fclose(fp);
}
void menu()
{
char b,c,number_[20];
int i,j,v,