首先对三层架构的理解

首先UI 层的源代码

#pragma once#ifndef _UI_H_
#define _UI_H_#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<io.h>
#include<conio.h>
#include<Windows.h>
#include"UI.h"
#include"BLL.h"
#include"DAL.h"typedef struct Users
{char name[10];char phone[20];char password[20];struct Users* next;
}users, * list;typedef struct Admin
{char name5[10];char phone[20];char password[20];struct Admin* next;
}admin;typedef struct TicketShow
{char film[20];char dirctor[20];char cinema[20];char duration[20];char cost[10];char time[20];int  IMAX;int x;int y;struct TicketShow* next;
}ticket;int menu();
void Read();
void Admin();int register1();
int register2();
void UsersLogin();
void AdminLogin();int Add();
void Modify();
void Delete();
void Search();void BuyTickets();
void Refund();
void SeatShow1();
void SeatShow2();
void SeatShow3();void ChooseSeat();
void TicketShow();
void getch_password(char* pass);#endif // !_UI_H_
#include"UI.h"int menu() //菜单
{int k=1;while (k!=0){system("CLS");color(9);printf("\n\n\t\t\t\t***************\n\n");color(6);printf("\t\t\t\t**1.登     录**\n\n");color(6);printf("\t\t\t\t**2.注     册**\n\n");color(6); printf("\t\t\t\t**0.返     回**\n\n");color(9);printf("\t\t\t\t***************\n\n");printf("\n\n\t\t\t\t");scanf("%d", &k);if (k == 1){system("CLS");color(13);printf("\n\n\t\t\t\t请选择你的身份:");color(14);printf("\n\n\t\t\t\t1.用户");color(14);printf("\n\n\t\t\t\t2.管理员");color(13);printf("\n\n\t\t\t\t");scanf("%d", &k);switch (k){case 1:UsersLogin();break;case 2:AdminLogin();break;default:break;}}else if ( k == 2){system("CLS");color(13);printf("\n\n\t\t\t\t请选择你的身份:");color(14);printf("\n\n\t\t\t\t1.用户");color(14);printf("\n\n\t\t\t\t2.管理员");color(13);printf("\n\n\t\t\t\t");scanf("%d", &k);switch (k){case 1:register1();break;case 2:register2();break;default:break;}}}return k;
}//用户登录与注册查看信息
void Read()
{system("CLS");color(6);printf("\n\n\t\t\t\t请选择你想进行的操作:\n\n");printf("\n\n\t\t\t\t1.查询影片信息");printf("\n\n\t\t\t\t2.查询影院信息");printf("\n\n\t\t\t\t3.查询电影计划");printf("\n\n\t\t\t\t4.查询票房统计");printf("\n\n\t\t\t\t5.购票");printf("\n\n\t\t\t\t6.查看订单");printf("\n\n\t\t\t\t7.退票");printf("\n\n\t\t\t\t0.返回\n\n");printf("\n\t\t\t\t\n\n");UsersChoose();getchar();}//管理员管理影片信息
void Admin()
{system("CLS");color(9);printf("\n\n\t\t\t\t请输入您想进行的操作:\n\n");color(6);printf("\n\n\t\t\t\t1.查看影片信息 ");printf("\n\n\t\t\t\t2.增加影片信息 ");printf("\n\n\t\t\t\t3.删除影片信息 ");printf("\n\n\t\t\t\t4.修改影片信息 ");printf("\n\n\t\t\t\t5.查找影片信息 ");printf("\n\n\t\t\t\t0.返回\n\n");AdminChoose();getchar();
}//用户登录账号
void UsersLogin()
{system("CLS");FILE* fp;fp = fopen("users.txt", "r");if (fp == NULL){printf("文件打开失败!");exit(-1);}users* h, * p, * q;h = (users*)malloc(sizeof(users));h->next = NULL;q = h;p = (users*)malloc(sizeof(users));q->next = p;if ((fp = fopen("users.txt", "rb")) == NULL){printf("打开失败!");exit(-1);}char name[10];char phone[20];char password[20];char password2[20];int k = 2;int i = 0, j = 0;char ch='0', ch2='0';color(6);printf("\n\t\t\t\t请输入用户姓名: \n\n");color(3);printf("                                ");scanf("%s", name);/*getchar();int ch1 = getchar();*/color(6);printf("\n\t\t\t\t请输入电话: \n\n");color(3);printf("                                ");scanf("%s", phone);//getchar();//int ch3 = getchar();color(6);printf("\n\t\t\t\t请输入密码:\n\n");color(3);printf("                                ");/*getchar();int ch4 = getchar();*/while ((ch = getch()) != '\r'){if (ch == '\b'){if (i > 0){i--;printf("\b \b");}elseputchar(7);}else {password[i++] = ch;printf("*");}password[i] = '\0';}color(6);printf("\n\t\t\t\t请再次确认密码:\n\n");color(3);printf("                                ");while ((ch2 = getch()) != '\r'){if (ch2 == '\b'){if (j > 0){j--;printf("\b \b");}elseputchar(7);}else {password2[j++] = ch2;printf("*");}password2[j] = '\0';}if ( strcmp(password, password2) == 0 )printf("\n\t\t\t\t输入成功!\n\n");else if (strcmp(password, password2) != 0){printf("\n\t\t\t\t密码输入错误! 请重新输入: ");while ((ch2 = getch()) != '\r'){if (ch2 == '\b'){if (j > 0){j--;printf("\b \b");}elseputchar(7);}else {password2[j++] = ch2;printf("*");}password2[j] = '\0';}}while (!feof(fp) && p->next != NULL){fscanf(fp, "%s %s %s", &p->name, &p->phone, &p->password);q = p;if (strcmp(p->name, name) == 0 && strcmp(p->phone, phone) == 0 && strcmp(p->password, password) == 0){k = 1;}}if (k == 1){color(3);printf("\n\t\t\t\t登录成功!\n\n");system("pause");Read();}else if (k != 1){color(3);printf("\n\t\t\t\t登陆失败! 请重新登录: \n");system("pause");UsersLogin();}fclose(fp);
}//管理员登录账号
void AdminLogin()
{system("CLS");FILE* fp;fp = fopen("admin.txt", "r");if (fp == NULL){printf("文件打开失败!");exit(-1);}admin* h, * p, * q;h = (admin*)malloc(sizeof(admin));h->next = NULL;q = h;p = (admin*)malloc(sizeof(admin));q->next = p;if ((fp = fopen("admin.txt", "rb")) == NULL){printf("打开失败!");exit(-1);}char name[10];char phone[20];char password[20];char password2[20];int k = 2;int i = 0, j = 0;char ch = '0', ch2 = '0';color(6);printf("\n\t\t\t\t请输入管理员姓名: \n\n");color(3);printf("                                ");scanf("%s", name);/*getchar();int ch1 = getchar();*/color(6);printf("\n\t\t\t\t请输入电话: \n\n");color(3);printf("                                ");scanf("%s", phone); /*getchar();int ch3 = getchar();*/color(6);printf("\n\t\t\t\t请输入密码:\n\n");color(3);printf("                                ");while ((ch = getch()) != '\r'){if (ch == '\b'){if (i > 0){i--;printf("\b \b");}elseputchar(7);}else {password[i++] = ch;printf("*");}password[i] = '\0';}color(6);printf("\n\t\t\t\t请再次确认密码:\n\n");color(3);printf("                                ");while ((ch2 = getch()) != '\r'){if (ch2 == '\b'){if (j > 0){j--;printf("\b \b");}elseputchar(7);}else {password2[j++] = ch2;printf("*");}password2[j] = '\0';}if (strcmp(password, password2) == 0)printf("\n\t\t\t\t输入成功!\n\n\n");else{printf("\n\t\t\t\t密码输入错误! 请重新输入: ");int j = 0;while ((ch2 = getch()) != '\r'){if (ch2 == '\b'){if (j > 0){j--;printf("\b \b");}elseputchar(7);}else {password2[j++] = ch2;printf("*");}password2[j] = '\0';}}while (!feof(fp) && p->next != NULL){fscanf(fp, "%s %s %s", &p->name5, &p->phone, &p->password);q = p;if (strcmp(p->name5, name) == 0 && strcmp(p->phone, phone) == 0 && strcmp(p->password, password) == 0){k = 1;}}if (k == 1){color(3);printf("\n\n\t\t\t\t登录成功!\n");system("pause");Admin();}else if (k != 1){color(3);printf("\n\t\t\t\t登陆失败! 请重新登录: \n");system("pause");AdminLogin();}fclose(fp);
}//用户注册函数
int register1()
{char name[10];char phone[20];char password[20];char password2[20];int i = 0, j = 0;char ch = '0', ch2 = '0';users* head = NULL;system("CLS");color(9);printf("\n\n\t\t\t\t请输入用户名:\n");color(13);printf("\n\t\t\t\t");scanf("%s", name);getchar();int ch1 = getchar();color(9);printf("\n\n\t\t\t\t请输入电话:\n");color(13);printf("\n\t\t\t\t");scanf("%s", phone);getchar();int ch3 = getchar();color(9);printf("\n\n\t\t\t\t请输入密码:\n");color(13);printf("                                ");while ((ch = getch()) != '\r'){if (ch == '\b'){if (i > 0){i--;printf("\b \b");}elseputchar(7);}else {password[i++] = ch;printf("*");}password[i] = '\0';}color(9);printf("\n\n\t\t\t\t请再次确认密码:\n\n");color(13);printf("                                ");while ((ch2 = getch()) != '\r'){if (ch2 == '\b'){if (j > 0){j--;printf("\b \b");}elseputchar(7);}else {password2[j++] = ch2;printf("*");}password2[j] = '\0';}int n = strcmp(password, password2);if (n != 0){color(9);printf("\n\t\t\t\t");printf("\n\n\t\t\t\t输入错误! 请再次输入密码:\n");int j = 0;while ((ch2 = getch()) != '\r'){if (ch2 == '\b'){if (j > 0){j--;printf("\b \b");}elseputchar(7);}else {password2[j++] = ch;printf("*");}password2[j] = '\0';}}else{color(9);printf("\n\t\t\t\t");printf("\n\n\t\t\t\t注册成功!\n ");}//存储用户信息users* p = NULL;p = (users*)malloc(sizeof(users));strcpy(p->name, name);strcpy(p->phone, phone);strcpy(p->password, password);p->next = NULL;FILE* fp;head = (users*)malloc(sizeof(users));head->next = NULL;fp = fopen("film.txt", "a+");fputc('\n', fp);fclose(fp);fp = fopen("users.txt", "a+");while (p != NULL){fprintf(fp, "%s %s %s\n", p->name, p->phone, p->password);p = p->next;}fclose(fp);printf("\n\n\t\t\t\t存储完成!\n");system("pause");system("CLS");getchar();getchar();printf("\n\t\t\t\t请登录新注册的账号:");getchar();UsersLogin();return;
}//管理员注册
int register2()
{admin* head;char name[10];char phone[20];char password[20];char password2[20];char ch = '0', ch2 = '0';int i = 0, j = 0;system("CLS");color(9);printf("\n\n\t\t\t\t请输入姓名:\n");color(13);printf("\n\t\t\t\t");scanf("%s", name);getchar();int ch1 = getchar();color(9);printf("\n\n\t\t\t\t请输入电话:\n");color(13);printf("\n\t\t\t\t");scanf("%s", phone);getchar();int ch3 = getchar();color(9);printf("\n\n\t\t\t\t请输入密码:\n");color(13);printf("                                ");while ((ch = getch()) != '\r'){if (ch == '\b'){if (i > 0){i--;printf("\b \b");}elseputchar(7);}else {password[i++] = ch;printf("*");}password[i] = '\0';}color(9);printf("\n\n\t\t\t\t请再次确认密码:\n\n");color(13);printf("                                ");while ((ch2 = getch()) != '\r'){if (ch2 == '\b'){if (j > 0){j--;printf("\b \b");}elseputchar(7);}else {password2[j++] = ch2;printf("*");}password2[j] = '\0';}int n = strcmp(password, password2);if (n != 0){color(9);printf("\n\t\t\t\t");printf("\n\n\t\t\t\t输入错误! 请再次输入密码:\n");int j = 0;while ((ch2 = getch()) != '\r'){if (ch2 == '\b'){if (j > 0){j--;printf("\b \b");}elseputchar(7);}else {password2[j++] = ch;printf("*");}password2[j] = '\0';}}else{color(9);printf("\n\t\t\t\t");printf("\n\n\t\t\t\t注册成功!\n ");}//存储管理员信息admin* p = NULL;p = (admin*)malloc(sizeof(admin));strcpy(p->name5, name);strcpy(p->phone, phone);strcpy(p->password, password);p->next = NULL;FILE* fp;head = (admin*)malloc(sizeof(admin));head->next = NULL;fp = fopen("film.txt", "a+");fputc('\n', fp);fclose(fp);fp = fopen("admin.txt", "a+");while (p != NULL){fprintf(fp, "%s %s %s\n", p->name5, p->phone, p->password);p = p->next;}fclose(fp);printf("\n\n\t\t\t\t存储完成!\n");system("pause");system("CLS");printf("\n\t\t\t\t请登录新注册的账号:");getch();AdminLogin();getchar();return;
}//把管理员新增加的影片信息写入文件
int Add()
{movie a = { 0 };system("CLS");color(9);printf("\n\t\t\t\t请输入电影名称:\n");color(13);printf("\n\t\t\t\t");scanf("%s", a.film);getchar();int ch = getchar();if (ch > 20){printf("输入字符过长,请重新输入:");}color(9);printf("\n\t\t\t\t请输入电影导演姓名:\n");color(13);printf("\n\t\t\t\t");scanf("%s", a.dirctor);color(9);printf("\n\t\t\t\t请输入电影院名称:\n");color(13);printf("\n\t\t\t\t");scanf("%s", a.cinema);color(9);printf("\n\t\t\t\t请输入电影时长:\n");color(13);printf("\n\t\t\t\t");scanf("%s", a.duration);color(9);printf("\n\t\t\t\t请输入票价:\n");color(13);printf("\n\t\t\t\t");scanf("%s", a.cost);color(9);printf("\n\t\t\t\t请输入播出时间:\n");color(13);printf("\n\t\t\t\t");scanf("%s", a.time);int myes;color(9);printf("\n\t\t\t\t请选择:1.保存,2.放弃 ");color(13);printf("\n\t\t\t\t");scanf("%d", &myes);if (myes != 1) return -1;movie* p, * head;p = (movie*)malloc(sizeof(movie));head = (movie*)malloc(sizeof(movie));head->next = NULL;strcpy(p->film, a.film);strcpy(p->dirctor, a.dirctor);strcpy(p->cinema, a.cinema);strcpy(p->duration, a.duration);strcpy(p->cost, a.cost);strcpy(p->time, a.time);p->next = NULL;FILE* fp;//在后面追加影片信息fp = fopen("film.txt", "a+");while (p != NULL){fprintf(fp, "%s %s %s %s %s %s", p->film, p->dirctor, p->cinema, p->duration, p->cost, p->time);p = p->next;fputc('\n', fp);}printf("\n\n\t\t\t\t文件写入成功!");fclose(fp);getch();getch();Admin();return 1;
}//管理员修改影片信息
void Modify()
{system("CLS");FILE* fp;fp = fopen("film.txt", "r");if (fp == NULL){color(6);printf("\n\t\t\t\t文件打开失败!");exit(-1);}movie* p, * h, * q;h = (movie*)malloc(sizeof(movie));h->next = NULL;q = h;color(6);printf("\n\t\t\t\t请输入修改影片的名称:");char name[20];color(9);scanf("%s", name);getchar();int ch = getchar();while (!feof(fp)){p = (movie*)malloc(sizeof(movie));q->next = p;p->next = NULL;fscanf(fp, "%s %s %s %s %s %s", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time);q = p;if (strcmp(name, p->film) == 0){movie a = { 0 };color(6);printf("\n\t\t\t\t输入修改后的影片名称: ");color(9);scanf("%s", a.film);strcpy(p->film, a.film);color(6);printf("\n\t\t\t\t输入修改后的影片导演姓名: ");color(9);scanf("%s", a.dirctor);strcpy(p->dirctor, a.dirctor);color(6);printf("\n\t\t\t\t输入修改后的影院地址: ");color(9);scanf("%s", a.cinema);strcpy(p->cinema, a.cinema);color(6);printf("\n\t\t\t\t输入修改后的影片时长: ");color(9);scanf("%s", a.duration);strcpy(p->duration, a.duration);color(6);printf("\n\t\t\t\t输入修改后的影片票价: ");color(9);scanf("%s", a.cost);strcpy(p->cost, a.cost);color(6);printf("\n\t\t\t\t输入修改后的影片上映时间: ");color(9);scanf("%s", a.time);strcpy(p->time, a.time);}}fclose(fp);//在后面追加影片信息fp = fopen("film.txt", "w");q = h->next;while (q->next != NULL){fprintf(fp, " % s % s % s % s % s % s", q->film, q->dirctor, q->cinema, q->duration, q->cost, q->time);q = q->next;fputc('\n', fp);}color(6);printf("\n\t\t\t\t修改完成!");fclose(fp);getch();getch();Admin();
}//管理员删除影片信息
void Delete()
{system("CLS");FILE* fp;fp = fopen("film.txt", "r");if (fp == NULL){color(6);printf("\n\t\t\t\t文件打开失败!");exit(-1);}movie* p, * h, * q, * r, * s;h = (movie*)malloc(sizeof(movie));h->next = NULL;q = h;color(6);printf("\n\t\t\t\t请输入删除影片的名称:");char name[20];color(9);scanf("%s", name);getchar();int ch = getchar();while (!feof(fp)){p = (movie*)malloc(sizeof(movie));q->next = p;p->next = NULL;fscanf(fp, "%s %s %s %s %s %s", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time);r = q;q = p;}p = h->next;while (strcmp(name, p->film) != 0){q = p;p = p->next;}if(strcmp(name,p->film)==0){q->next = p->next;free(p);}fclose(fp);fp = fopen("film.txt", "w");q = h->next;while (q->next!= NULL){fprintf(fp, " % s % s % s % s % s % s",q->film, q->dirctor, q->cinema, q->duration, q->cost,q->time);q = q->next;fputc('\n', fp);}color(6);printf("\n\t\t\t\t删除完成!");fclose(fp);getch();getch();Admin();
}//管理员查找影片信息
void Search()
{char name[50], name2[50];system("CLS");color(9);printf("\n\t\t\t\t请输入想查找电影的名称:  ");scanf("%s", name);getchar();int ch = getchar();FILE* fp;fp = fopen("film.txt", "r");if (fp == NULL){color(6);printf("\n\t\t\t\t文件打开失败!");exit(-1);}movie* p, * h, * q;h = (movie*)malloc(sizeof(movie));h->next = NULL;q = h;while (!feof(fp)){p = (movie*)malloc(sizeof(movie));q->next = p;p->next = NULL;fscanf(fp, "%s %s %s %s %s %s", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time);q = p;strcpy(name2, p->film);char* x = strstr(name2, name);if (x != NULL ){printf("\n\t\t\t\t成功找到电影:%s\n\n", x);color(6);printf("---------------------------------------------------------------------------------------\n");printf("|电影名称      |电影导演    |电影院         |电影时长    |票价      |播放时间           \n");printf("|%-14s|%-12s|%-15s|%-12s|%-10s|%-20s\n", q->film, q->dirctor, q->cinema, q->duration, q->cost, q->time);getch();}}fclose(fp);getch();getch();Admin();
}//用户买票
void BuyTickets()
{system("CLS");movie* p, * h, * q;h = (movie*)malloc(sizeof(movie));h->next = NULL;q = h;//Readfilm1(&h);int myes1, myes2;char name[50], name2[50];color(6);printf("\n\t\t\t\t请输入想看电影的名称:  ");color(3);scanf("%s", name);getchar();int ch = getchar();FILE* fp;fp = fopen("film.txt", "r");if (fp == NULL){color(6);printf("\n\t\t\t\t文件打开失败!");exit(-1);}while (!feof(fp)){p = (movie*)malloc(sizeof(movie));q->next = p;//p->next = NULL;fscanf(fp, "%s %s %s %s %s %s", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time);q = p;strcpy(name2, p->film);char* x = strstr(name2, name);if (strcmp(name2, name) == 0){color(6);printf("\n\t\t\t\t成功找到电影:%s\n", name2);printf("\n\t\t\t\t请选择是否购票: 1.是 2.否 ");scanf("%d", &myes1);if (myes1 == 1){FILE* pf1;pf1 = fopen("UserBuyTicket.txt", "a+");fprintf(pf1, "%s %s %s %s %s %s ", p->film, p->dirctor, p->cinema, p->duration, p->cost, p->time);fclose(pf1);ChooseSeat();}elseRead();break;getch();getch();}else if (x != NULL && strcmp(name2, name) != 0){printf("\n\t\t\t\t没有找到电影:%s ,但找到电影:%s\n",name, name2);printf("\n\t\t\t\t请选择是否购票: 1.是 2.否 ");scanf("%d", &myes2);if (myes2 == 1){FILE* pf;pf = fopen("UserBuyTicket.txt", "a+");fprintf(pf, "%s %s %s %s %s %s ", p->film, p->dirctor, p->cinema, p->duration, p->cost, p->time);fclose(pf);ChooseSeat();}elseRead();break;getch();getch();}else if(x==NULL && p->next==NULL ){printf("\n\t\t\t\t不能找到电影;%s , 请重新输入: ", name);getch();getch();BuyTickets();//break;}}fclose(fp);}//座位显示:影厅1
void SeatShow1()
{system("CLS");int x, y;int i, j;int b[8][8];FILE* fp;fp = fopen("seat1.txt", "r");if (fp == NULL){printf("文件打开失败!");exit(-1);}for (i = 0; i < 8; i++){for (j = 0; j < 8; j++){fscanf(fp, "%d", &b[i][j]);}}for (i = 0; i < 8; i++){for (j = 0; j < 8; j++){if (b[i][j]==1)printf(" ▇  ");else if(b[i][j]==0)printf(" □ ");}printf("\n");}printf("\n\n请输入你想选择的位置(x,y):  \n");scanf("%d,%d", &x, &y);getchar();int c = x;int d = y;if (b[x - 1][y - 1] == 1){printf("\n您选的位置已经有主人啦!");printf("\n请重新选择位置吧: ");scanf("%d,%d", &x, &y);}if (x == 0 || y == 0 || x > 8 || y > 8){printf("\n您选择的位置不存在! 请重新选择:");scanf("%d,%d", &x, &y);}if ( x > 0 && x < 9 && y>0 && y < 9){printf("\n选座成功!\n");FILE* fp1;fp1 = fopen("UserBuyTicket.txt", "a+");fprintf(fp1, "%d %d ", x, y);fputc('\n', fp1); fclose(fp1);}getch();b[c - 1][d - 1] = 1;for (i = 0; i < 8; i++){for (j = 0; j < 8; j++){if (b[i][j]==1)printf(" ▇  ");else if (b[i][j] == 0)printf(" □ ");}printf("\n");}fp = fopen("seat1.txt", "w");for (i = 0; i < 8; i++){for (j = 0; j < 8; j++){fprintf(fp, "%d ", b[i][j]);}}fclose(fp);getch();getch();Read();return;}//座位显示:影厅2
void SeatShow2()
{system("CLS");int x, y;int i, j;int b[6][4];FILE* fp;fp = fopen("seat2.txt", "r");if (fp == NULL){printf("文件打开失败!");exit(-1);}for (i = 0; i < 4; i++){for (j = 0; j < 6; j++){fscanf(fp, "%d", &b[i][j]);}}for (i = 0; i < 4; i++){for (j = 0; j < 6; j++){if (b[i][j] == 1)printf(" ▇  ");else if (b[i][j] == 0)printf(" □ ");}printf("\n");}printf("\n\n请输入你想选择的位置(x,y):  \n");scanf("%d,%d", &x, &y);int c = x;int d = y;if (b[x - 1][y - 1] == 1){printf("\n您选的位置已经有主人啦!");printf("\n请重新选择位置吧: ");scanf("%d,%d", &x, &y);}if (x == 0 || y == 0 || x > 4 || y > 6){printf("\n您选择的位置不存在! 请重新选择:");scanf("%d,%d", &x, &y);}printf("\n选座成功!\n");getch();b[x - 1][y - 1] = 1;for (i = 0; i < 4; i++){for (j = 0; j < 6; j++){if (b[i][j] == 1)printf(" ▇  ");else if (b[i][j] == 0)printf(" □ ");}printf("\n");}fp = fopen("seat1.txt", "w");for (i = 0; i < 4; i++){for (j = 0; j < 6; j++){fprintf(fp, "%d ", b[i][j]);}}fclose(fp);//SaveTicket(ticket * h, char* name);getch();getch();Read();return;}//座位显示:影厅3
void SeatShow3()
{system("CLS");int x, y;int i, j;int b[9][10];FILE* fp;fp = fopen("seat3.txt", "r");if (fp == NULL){printf("文件打开失败!");exit(-1);}for (i = 0; i < 9; i++){for (j = 0; j < 10; j++){fscanf(fp, "%d", &b[i][j]);}}for (i = 0; i < 9; i++){for (j = 0; j < 10; j++){if (b[i][j] == 1)printf(" ▇  ");else if (b[i][j] == 0)printf(" □ ");}printf("\n");}printf("\n\n请输入你想选择的位置(x,y):  \n");scanf("%d,%d", &x, &y);int c = x;int d = y;if (b[x - 1][y - 1] == 1){printf("\n您选的位置已经有主人啦!");printf("\n请重新选择位置吧: ");scanf("%d,%d", &x, &y);}if (x == 0 || y == 0 || x > 9 || y > 10){printf("\n您选择的位置不存在! 请重新选择:");scanf("%d,%d", &x, &y);}printf("\n选座成功!\n");getch();b[x - 1][y - 1] = 1;for (i = 0; i < 9; i++){for (j = 0; j < 10; j++){if (b[i][j] == 1)printf(" ▇  ");else if (b[i][j] == 0)printf(" □ ");}printf("\n");}fp = fopen("seat1.txt", "w");for (i = 0; i < 9; i++){for (j = 0; j < 10; j++){fprintf(fp, "%d ", b[i][j]);}}fclose(fp);getch();getch();Read();return;}//用户选择影厅
void ChooseSeat()
{int x;printf("\n\t\t\t\t请选择你想选择的影厅序号(共有三个):");scanf("%d", &x);if (x == 0 || x > 3)printf("\n\t\t\t\t不存在该影厅!");else{FILE* fp;fp = fopen("UserBuyTicket.txt", "a+");fprintf(fp, "%d ",x);fclose(fp);switch (x){case 1:SeatShow1();break;case 2:SeatShow2();break;case 3:SeatShow3();break;default:break;}}}//显示我的订单
void TicketShow()
{system("CLS");ticket* p, * h, * q;h = (ticket*)malloc(sizeof(ticket));p = (ticket*)malloc(sizeof(ticket));h->next = NULL;q = h;q->next = p;printf("您的订单如下:\n");FILE* fp;fp = fopen("UserBuyTicket.txt", "r");if (fp == NULL){printf("当前还没有订单!");exit(-1);}printf("----------------------------------------------------------------------------------------------------------\n");printf("|电影名称       |电影导演  |电影院       |电影时长  |票价    |播放时间          |影厅序号 |行  |列 \n");fscanf(fp, "%s %s %s %s %s %s %d %d %d", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time,&p->IMAX,&p->x,&p->y);while (!feof(fp) && p != NULL){color(3);printf("|%-15s|%-10s|%-13s|%-10s|%-8s|%-18s|%-9d|%-4d|%-4d\n", p->film, p->dirctor, p->cinema, p->duration, p->cost, p->time, p->IMAX, p->x, p->y);fscanf(fp, "%s %s %s %s %s %s %d %d %d", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time, &p->IMAX, &p->x, &p->y);q = p;}fclose(fp);getchar();getchar();Read();
}//用户退票
void Refund()
{system("CLS");char name[20];char name2[20];int myes;int x1, y1, t, i, j;int a[10][10];printf("请输入您想退票的电影名称:");scanf("%s", name);FILE* fp;fp = fopen("UserBuyTicket.txt", "r");if (fp == NULL){printf("当前还没有订单! 按任意键返回.");exit(-1);}ticket* h, * p, * q, * r;h = (ticket*)malloc(sizeof(ticket));h->next = NULL;q = h;while (!feof(fp)){p = (ticket*)malloc(sizeof(ticket));q->next = p;p->next = NULL;fscanf(fp, "%s %s %s %s %s %s %d %d %d", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time, &p->IMAX, &p->x, &p->y);r = q;q = p;}p = h->next;while (strcmp(name, p->film) != 0){q = p;p = p->next;}if (strcmp(name, p->film) == 0){t = p->IMAX;x1 = p->x;y1 = p->y;q->next = p->next;free(p);}fclose(fp);fp = fopen("UserBuyTicket.txt", "w");q = h->next;while (q->next!=NULL){fprintf(fp, "%s %s %s %s %s %s %d %d %d", q->film, q->dirctor, q->cinema,q->duration, q->cost, q->time, q->IMAX,q->x, q->y);q = q->next;fputc('\n', fp);}fclose(fp);if (t == 1){FILE* fp1;fp1 = fopen("seat1.txt", "r");if (fp1 == NULL){printf("文件打开失败!");exit(-1);}for (i = 0; i < 8; i++){for (j = 0; j < 8; j++){fscanf(fp1, "%d", &a[i][j]);}}a[x1 - 1][y1 - 1] = 0;fp1 = fopen("seat1.txt", "w");for (i = 0; i < 8; i++){for (j = 0; j < 8; j++){fprintf(fp1, "%d ", a[i][j]);}}fclose(fp1);getch();getch();}else if (t == 2){FILE* fp2;fp2 = fopen("seat2.txt", "w");a[x1 - 1][y1 - 1] = 0;for (i = 0; i < 4; i++){for (j = 0; j < 6; j++){fprintf(fp2, "%d ", a[i][j]);}}fclose(fp2);getch();getch();}else if (t == 3){FILE* fp3;fp3 = fopen("seat3.txt", "w");a[x1 - 1][y1 - 1] = 0;for (i = 0; i < 9; i++){for (j = 0; j < 10; j++){fprintf(fp3, "%d ", a[i][j]);}}fclose(fp3);getch();getch();}Read();getch();getch();
}

其次是BLL层

#pragma once#ifndef _BLL_H_
#define _BLL_H_#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<io.h>
#include<conio.h>
#include<Windows.h>
#include"UI.h"
#include"BLL.h"
#include"DAL.h"void UsersChoose();
void AdminChoose();#endif // !_BLL_H_
#include"BLL.h"//用户选择查看的信息
void UsersChoose()
{users a = { 0 };users* head;int k = 0;printf("                                ");scanf("%d", &k);ticket* h = NULL;switch (k){case 1:Readfilm1(&head);break;case 2:Read_Cinema(&head);break;case 3:ReadPlan(&head);break;case 4:ReadBoxOffice(&head);break;case 5:BuyTickets();break;case 6:TicketShow();break;case 7:Refund();default:break;}
}//管理员选择进行什么操作
void AdminChoose()
{int k = 0;printf("                                ");scanf("%d", &k);movie *head=NULL;switch (k){case 1:Readfilm2(&head);break;case 2:Add();break;case 3:Delete();break;case 4:Modify();break;case 5:Search();break;default:break;}}

然后是DAL层

#pragma once#ifndef _DAL_H_
#define _DAL_H_#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<io.h>
#include<conio.h>
#include<Windows.h>
#include"UI.h"
#include"BLL.h"
#include"DAL.h"typedef struct Movie
{char film[20];char dirctor[20];char cinema[20];char duration[20];char cost[10];char time[20];struct Movie* next;
}movie, * link;typedef struct Cinema
{char name2[20];char location[20];char phone2[20];struct Cinema* next;
}cinema;typedef struct Plan
{char name3[20];char actor[20];char time3[15];char dora[10];struct Plan* next;
}plan;typedef struct Box
{char name4[20];char money[10];char account[10];struct Box* next;
}box;void Read_Cinema(cinema** head);
void ReadPlan(plan** head);
void Readfilm1(movie** head);
void Readfilm2(movie** head);
void ReadBoxOffice(box** head);
void Insert(link head);int Read_File(movie** h);
int SaveFile(movie* h);
//int SaveTicket(ticket* h, char* name);#endif // !_DAL_H_
#include"DAL.h"//读影片信息
void Readfilm1(movie** head)
{system("CLS");int k = 1;FILE* fp;movie* h;h = (movie*)malloc(sizeof(movie));movie* p, * q;q = h;p = (movie*)malloc(sizeof(movie));q->next = p;h->next = NULL;if ((fp = fopen("film.txt", "rb")) == NULL){printf("打开失败!");exit(-1);}color(6);printf("------------------------------------------------------------------------------------------------\n");printf("|序号|电影名称      |电影导演    |电影院         |电影时长    |票价      |播放时间           \n");fscanf(fp, "%s %s %s %s %s %s", &p->film, &p->dirctor,&p->cinema, &p->duration, &p->cost, &p->time);while (!feof(fp) && p!= NULL){color(3);printf("|%-4d|%-14s|%-12s|%-15s|%-12s|%-10s|%-20s\n", k, p->film, p->dirctor, p->cinema, p->duration, p->cost, p->time);fscanf(fp, "%s %s %s %s %s %s", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time);q = p;k++;}color(6);printf("------------------------------------------------------------------------------------------------\n");fclose(fp);getch();getch();Read();}void Readfilm2(movie** head)
{system("CLS");int k = 1;FILE* fp;movie* h;h = (movie*)malloc(sizeof(movie));movie* p, * q;q = h;p = (movie*)malloc(sizeof(movie));q->next = p;h->next = NULL;if ((fp = fopen("film.txt", "rb")) == NULL){printf("打开失败!");exit(-1);}color(6);printf("------------------------------------------------------------------------------------------------\n");printf("|序号|电影名称      |电影导演    |电影院         |电影时长    |票价      |播放时间           \n");fscanf(fp, "%s %s %s %s %s %s", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time);while (!feof(fp) && p != NULL){color(3);printf("|%-4d|%-14s|%-12s|%-15s|%-12s|%-10s|%-20s\n", k, p->film, p->dirctor, p->cinema, p->duration, p->cost, p->time);fscanf(fp, "%s %s %s %s %s %s", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time);q = p;k++;}color(6);printf("------------------------------------------------------------------------------------------------\n");fclose(fp);getch();getch();Admin();
}//读入影院信息
void Read_Cinema(cinema** head)
{system("CLS");int k = 1;FILE* fp;cinema* h;h = (cinema*)malloc(sizeof(cinema));cinema* p, * q;q = h;p = (cinema*)malloc(sizeof(cinema));q->next = p;h->next = NULL;if ((fp = fopen("cinema.txt", "rb")) == NULL){printf("打开失败!");exit(-1);}color(6);printf("-----------------------------------------------\n");printf("|序号 |影院名称       |影院地点       |影院电话      \n");fscanf(fp, "%s %s %s", &p->name2, &p->location, &p->phone2);while (!feof(fp) && p->next != NULL){color(9);printf("|%-5d|%-15s|%-15s|%-10s\n", k, p->name2, p->location, p->phone2);fscanf(fp, "%s %s %s", &p->name2, &p->location, &p->phone2);q = p;k++;}color(6);printf("-----------------------------------------------\n");fclose(fp);getch();getch();Read();
}//读电影计划
void ReadPlan(plan** head)
{system("CLS");int k = 1;FILE* fp;plan* h;h = (plan*)malloc(sizeof(plan));plan* p, * q;q = h;p = (plan*)malloc(sizeof(plan));q->next = p;h->next = NULL;if ((fp = fopen("plan.txt", "rb")) == NULL){printf("打开失败!");exit(-1);}color(6);printf("--------------------------------------------------------------\n");printf("|序号 |电影计划名称   |主演姓名       |计划时间       |电影时长\n");fscanf(fp, "%s %s %s %s", &p->name3, &p->actor, &p->time3, &p->dora);while (!feof(fp) && p->next != NULL){color(9);printf("|%-5d|%-15s|%-15s|%-15s|%-15s\n", k, p->name3, p->actor, p->time3, p->dora);fscanf(fp, "%s %s %s %s", &p->name3, &p->actor, &p->time3, &p->dora);q = p;k++;}color(6);printf("---------------------------------------------------------------\n");fclose(fp);getch();getch();Read();
}//读票房统计
void ReadBoxOffice(box** head)
{system("CLS");int k = 1;FILE* fp;box* h;h = (box*)malloc(sizeof(box));box* p, * q;q = h;p = (box*)malloc(sizeof(box));q->next = p;h->next = NULL;if ((fp = fopen("box office.txt", "rb")) == NULL){printf("打开失败!");exit(-1);}color(6);printf("-------------------------------------------\n");printf("|序号 |电影名称          |票房       |占比     \n");fscanf(fp, "%s %s %s", &p->name4, &p->money, &p->account);while (!feof(fp) && p->next != NULL){color(9);printf("|%-5d|%-18s|%-10s|%-15s\n", k, p->name4, &p->money, p->account);fscanf(fp, "%s %s %s", &p->name4, &p->money, &p->account);q = p;k++;}color(6);printf("-------------------------------------------\n");fclose(fp);getch();getch();menu();
}//读文件
int Read_File(movie** h)
{int k;movie* p, * q, * r;*h = (movie*)malloc(sizeof(movie));(*h)->next = NULL;r = *h;p = (movie*)malloc(sizeof(movie));FILE* fp;fp = fopen("film.txt", "r");if (fp == NULL){color(9);printf("\n\t\t\t\t文件读取失败!");getch();return 0;}while (!feof(fp) &&p->next!=NULL){fscanf(fp, "%s %s %s %s %s %s", &p->film, &p->dirctor, &p->cinema, &p->duration, &p->cost, &p->time);q = (movie*)malloc(sizeof(movie));q = p;r->next = q;r = q;}r->next = NULL;fclose(fp);return 1;
}//保存信息
int SaveFile(movie* h)
{FILE* fp;fp = fopen("film.txt", "w");if (fp == NULL)return -1;movie* p = h;while (p != NULL){fprintf(fp, " % s % s % s % s % s % s", p->film, p->dirctor, p->cinema, p->duration, p->cost, p->time);p = p->next;}fclose(fp);return 1;
}

最后是主函数

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<io.h>
#include<conio.h>
#include<Windows.h>
#include"UI.h"
#include"BLL.h"
#include"DAL.h"void color(int x)
{SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
}int main()
{menu();color(6);return 0;
}

(以上代码涉及到所有的文件均存储在同一个文件夹下)

实现功能:

首先是菜单

然后用户端:

以下是管理员端功能:

第一个项目: 票务管理系统相关推荐

  1. 复习Java第一个项目学生信息管理系统 04(权限管理和动态挂菜单功能) python简单爬数据实例Java面试题三次握手和四次挥手生活【记录一个咸鱼大学生三个月的奋进生活】016

    记录一个咸鱼大学生三个月的奋进生活016 复习Java(学生信息管理系统04权限管理和动态挂菜单功能) 改写MainFrame的构造方法 新增LoginFrame的验证登录是否成功的代码 新增Logi ...

  2. Java毕设项目影城票务管理系统计算机(附源码+系统+数据库+LW)

    Java毕设项目影城票务管理系统计算机(附源码+系统+数据库+LW) 项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Ec ...

  3. JAVA毕设项目汽车客运站票务管理系统(java+VUE+Mybatis+Maven+Mysql)

    JAVA毕设项目汽车客运站票务管理系统(java+VUE+Mybatis+Maven+Mysql) 项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX( ...

  4. 票务管理系统项目(part1)

    票务管理系统与订票系统项目(一) 前言: 票务管理系统,是一个联结几个表进行CRUD操作的一个小项目,这次决心将自己从规划项目到完成项目的整个过程记录下来,以求自己能在项目规范,设计,编码过程有所突破 ...

  5. 【数据库实验】《小型MIS的开发》— JavaFx 开发 民航票务管理系统

    <小型MIS的开发> 需求描述 数据库建表 用户表的 SQL 航班信息表的 SQL 项目演示 GitHub 网址获取源代码 比较重要的知识点 JavaFx 中 spring 工厂如何创建 ...

  6. c语言编程票务系统,C语言课程设计票务管理系统

    C语言课程设计票务管理系统 C语言课程设计1西安交通大学城市学院C语言程序设计课程设计报告题目图书信息管理系统专业自动化班级自动化101姓名陈蕾完成日期2012年5月31日C语言课程设计2目录第一章项 ...

  7. 【数据库实验】《小型MIS的开发》PyQt5 开发 民航票务管理系统

    PyQt5 开发 民航票务管理系统 为什么要拿 Python 做呢? 学习一天的知识点 开发环境 与 项目整体结构 数据库建表 用户表的 SQL 航班信息表的 SQL 界面代码 主界面:hello.p ...

  8. java计算机毕业设计汽车客运站票务管理系统源代码+数据库+系统+lw文档

    java计算机毕业设计汽车客运站票务管理系统源代码+数据库+系统+lw文档 java计算机毕业设计汽车客运站票务管理系统源代码+数据库+系统+lw文档 本源码技术栈: 项目架构:B/S架构 开发语言: ...

  9. Java在线教育项目 第一天项目介绍和工程搭建

    第一章 项目介绍和工程搭建 学习目标 熟悉移动端应用系统的架构设计 熟悉大型软件系统设计中的各种图形结构 熟悉数据库分库分表设计技巧 熟悉Spring boot2.0+JavaConfig项目封装配置 ...

最新文章

  1. Android网络框架Volley的快速使用
  2. Android permission 访问权限一览
  3. 模拟搭建Web项目的真实运行环境(五)
  4. 进程间通信(IPC)+进程加锁解锁
  5. 2. linux的日志文件在哪个目录,位于/var/log目录下的20个Linux日志文件
  6. 在数学空间中,物理分辨率可能失去了意义(behind the paper)
  7. 图像处理【代码合集】
  8. 掏出来的“耳屎经济”
  9. linux系统sql语句报错_linux之SQL语句简明教程---CREATE VIEW
  10. android对话框列表,android列表对话框(dialog)的实现
  11. DirectX 3D Mesh类
  12. 2021年安全生产模拟考试(全国特种作业操作证电工作业-防爆电气模拟考试题库一)安考星
  13. Unity Visual Effect Graph 制作Fireworks烟花特效
  14. python网络爬虫网易云音乐_怎么使用Python网络爬虫爬取网易云音乐歌词
  15. php仿淘宝课程设计任务书
  16. 霜语服务器优势服,暴风城都被毛了!魔兽世界“毛人风”所在霜语服务器联盟已经凉凉...
  17. 利用分支限界法解决01背包和货郎担问题
  18. 心脏滴血漏洞(CVE-2014-0160)
  19. 减脂肪应该吃什么食物
  20. RS485自收发实现方案,典型应用电路及问题经验总结

热门文章

  1. winform 鼠标 静止时间_双飞燕飞时代FG30S鼠标评测,谁说静音手感不两全?
  2. android 钛备份,钛备份下载-钛备份Titanium Backup 安卓版v8.3.2-PC6安卓网
  3. DiskGenius.5.1.2.766.rar
  4. 移动端调试神器——vconsole
  5. scp ssh自动填入密码
  6. vCenter介绍及安装配置
  7. 突破宽带共享路由限制的方法探讨
  8. c# 下载视频文件
  9. Android 因moov播放网络mp4失败的解决办法
  10. 票据打印控件 票据打印控件