当前位置:网站首页>C language course setting: cinema ticket selling management system

C language course setting: cinema ticket selling management system

2022-07-05 03:58:00 WE-ubytt

Preface

Recently, I happened to be writing my own curriculum , The lesson design system written in a hurry , There are still shortcomings , Take it out and share it with you , I hope it can help you .

One 、 Outline design

1、 essential information

data type : Linked list

typedef struct node
{
    
    char name[N];          		//  name 
    char type[N];          		//  type 
    int time;              		//  Duration 
    char day[N];            	//  date 
    char start[N];         		//  Starting time 
    char site[N];           	//  place 
    int price;              	//  Price 
    int num;                	//  Number 
    int id;                 	//  Number 
    int seat[N][N];       		//  seat 
    struct node* next;       	//  Pointer to the domain 
}NODE;

Realization function :
 Insert picture description here

typedef struct ticket
{
    
    char name[N];           	//  name 
    char type[N];           	//  type 
    int time;              		//  Duration 
    char day[N];            	//  date 
    char start[N];          	//  Starting time 
    char site[N];           	//  place 
    int price;             		//  Price 
    int id;                   	//  Number 
    char username[N];        	//  user name 
    int x;                		//  That's ok 
    int y;               	 	//  Column 
    int istake;                	//  Whether to collect tickets 
    struct ticket* next;      	//  Pointer to the domain 
}TICKET;

Realization function :
 Insert picture description here

development environment :VS2019

2、 Functional module diagram

 Insert picture description here

3、 Function description

(1) Administrators
① Add movies : Add a movie to the system
② Show movie : Display all movie information in the system
③ Find movies : By name 、 type 、 Number query movie information
④ Modify the movie : Check the movie by number , Modify movie information
⑤ Delete movie : Check the movie by number , Delete movie information
⑥ Sort movies : According to the length of time 、 date 、 Price 、 Number sort movie information
(2) user
① Ticket purchase : Sort movie information , Show movie information , Query movie information by number , Ticket information is displayed after ticket purchase
② Ticket collection : Show ticket information , Choose whether to collect tickets
③ To refund a ticket : Show ticket information , Choose whether to refund

4、 Call graph

 Insert picture description here

Two 、 Complete code

#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<conio.h>
#define N 100

typedef struct administrator
{
    
	char id[N];								//  user name 
	char password[N];						//  password 

	struct administrator* next;				//  Pointer to the domain 
}ADMIN;

typedef struct user
{
    
	char id[N];								//  user name 
	char password[N];						//  password 

	struct user* next;						//  Pointer to the domain 
}USER;

typedef struct node
{
    
	char name[N];				//  name 
	char type[N];				//  type 
	int time;					//  Duration 
	char day[N];				//  date 
	char start[N];				//  Starting time 
	char site[N];				//  place 
	int price;					//  Price 
	int num;					//  Number 
	int id;						//  Number 
	int seat[N][N];				//  seat 

	struct node* next;			//  Pointer to the domain 
}NODE;

typedef struct ticket
{
    
	char name[N];				//  name 
	char type[N];				//  type 
	int time;					//  Duration 
	char day[N];				//  date 
	char start[N];				//  Starting time 
	char site[N];				//  place 
	int price;					//  Price 
	int id;						//  Number 

	char username[N];			//  user name 
	int x;						//  That's ok 
	int y;						//  Column 
	int istake;					//  Whether to collect tickets 

	struct ticket* next;		//  Pointer to the domain 
}TICKET;

ADMIN a;									//  Administrator information 
USER b;										//  User information 
NODE list;									//  Movie information 
TICKET c;									//  Ticket purchase 

char fusername[N], fpassword[N];			//  user name / password ( file )
char username[N], password[N];				//  user name / password ( Input )
int flag = 0;								//  Determine whether the login is successful 

//  Administrator login 
void menu_Login_admin();					//  Interface 
void fun_Login_admin();						//  function 
void admin_login();							//  Sign in 
int Read_admin_login();						//  File read 

//  The user login 
void menu_Login_user();						//  Interface 
void fun_Login_user();						//  function 
void user_login(USER* L);					//  Sign in 
int Read_user(USER* L);						//  User login file read 
int Read_user_login(USER* L);				//  Judge 
int user_logon(USER* L);					//  register 
void Add1(USER* L, USER e);					//  Insert 

//  Read the file 
int Read_FILE(NODE* L);

//  Save the file 
int Save_FILE(NODE* L);

//  menu 
void welcome();								//  The main menu 
void fun_welcome();							//  Main menu function 
void menu_administrator();					//  Administrator interface 
void fun_administrator();					//  Administrator function 
void menu_user();							//  The user interface 
void fun_user();							//  User functions 

//  Add movies 
void Add(NODE* L, NODE e);					//  function 
void Add_Printf();							//  Interface 

//  Query movie 
void Search_Printf(NODE* L);					//  Interface 
int Search_allname(char name[], NODE* L);		//  Find by name 
NODE* Search_name(char name[], NODE* L);		//  Find the first by name 
int Search_type(char type[], NODE* L);			//  Find by type 
NODE* Search_id(int id, NODE* L);				//  Search by number 

//  Delete movie 
void Delete_Printf(NODE* L);				//  Interface 
void Delete(NODE* s);						//  function 

//  Modify the movie 
void Fix(NODE* L);

//  Show movie 
void Print(NODE* L);						//  function 
void Print_Printf();						//  Interface 

//  Sort movies 
void Sort(NODE* L);
int cmp_big_time(NODE e1, NODE e2);			//  The duration varies from large to small 
int cmp_big_day(NODE e1, NODE e2);			//  Date from big to small 
int cmp_big_price(NODE e1, NODE e2);		//  The price ranges from big to small 
int cmp_big_num(NODE e1, NODE e2);			//  The quantity ranges from large to small 
int cmp_small_time(NODE e1, NODE e2);		//  From small to large 
int cmp_small_day(NODE e1, NODE e2);		//  Date from small to large 
int cmp_small_price(NODE e1, NODE e2);		//  The price increases from small to large 
int cmp_small_num(NODE e1, NODE e2);		//  From small to large 

//  Ticket purchase 
void Buy_ticket();							//  function 
int Buy_ticket_Printf();					//  Interface 
void Add2(TICKET* L, TICKET e);				//  Save reservation information 
int Save_TICKET(TICKET* L);					//  File save ticket information 
int Read_TICKET(TICKET* L);					//  Read ticket information 

//  Ticket collection 
void Collect_ticket();
//  Print ticket information 
void Print_ticket(TICKET* L);
void Print_ticket_Printf();

//  To refund a ticket 
void Return_ticket();
void Print_ticket1(TICKET* L);						//  Print information 
TICKET* Find_ticket(TICKET* L, char username[]);	//  Find the precursor node 
void Delete_ticket(TICKET* s);						//  Delete 

//  Exit the system 
void goodbye();

int main()
{
    
	Read_FILE(&list);
	Read_TICKET(&c);
	Read_user(&b);

	while (1)
	{
    
		fun_welcome();
	}

	return 0;
}

//  The main menu 
void welcome()
{
    
	system("cls");
	printf("****************************************************************\n");
	printf("***********  Cinema management system  ***********\n");
	printf("*********** 1 ----  Administrators  ***********\n");
	printf("*********** 2 ----  user  ***********\n");
	printf("*********** 0 ----  sign out  ***********\n");
	printf("****************************************************************\n");

	printf("【 System 】 Please choose your identity ( Numbers ):");
}

//  Main menu function 
void fun_welcome()
{
    
	int choice = 0;
	welcome();
	scanf("%d", &choice);
	switch (choice)
	{
    
	case 1://  Administrators 
		fun_administrator();
		break;
	case 2://  user 
		fun_user();
		break;
	case 0://  sign out 
		goodbye();
		break;
	}
}

//  Administrator interface 
void menu_administrator()
{
    
	system("cls");
	printf("【 System 】 welcome %s!!!\n", username);
	printf("****************************************************************\n");
	printf("***********  welcome !!! ***********\n");
	printf("*********** 1 ----  Add movies  ***********\n");
	printf("*********** 2 ----  Show movie  ***********\n");
	printf("*********** 3 ----  Find movies  ***********\n");
	printf("*********** 4 ----  Modify the movie  ***********\n");
	printf("*********** 5 ----  Delete movie  ***********\n");
	printf("*********** 6 ----  Sort movies  ***********\n");
	printf("*********** 0 ----  sign out  ***********\n");
	printf("****************************************************************\n");

	printf("【 System 】 Please select the function you want to realize ( Numbers ):");
}

//  Administrator function 
void fun_administrator()
{
    
	fun_Login_admin();

	if (flag == 1)
	{
    
		int choice = 0;
		while (1)
		{
    
			menu_administrator();
			scanf("%d", &choice);
			switch (choice)
			{
    
			case 1://  Add movies 
				Add_Printf();
				break;
			case 2://  Show movie 
				Print(&list);
				break;
			case 3://  Find movies 
				Search_Printf(&list);
				break;
			case 4://  Modify the movie 
				Fix(&list);
				break;
			case 5://  Delete movie 
				Delete_Printf(&list);
				break;
			case 6://  Sort movies 
				Sort(&list);
				break;
			case 0://  sign out 
				return;
			}

			printf(" Need to continue ?(Yes:1 / No:0):");
			scanf("%d", &choice);

			if (choice != 1)
			{
    
				if (choice != 0)
					printf(" Input error !!!\n");
				system("pause");
				break;
			}
		}
	}
}

//  The user interface 
void menu_user()
{
    
	system("cls");
	printf("【 System 】 welcome %s!!!\n", username);
	printf("****************************************************************\n");
	printf("***********  welcome !! ***********\n");
	printf("*********** 1 ----  Ticket purchase  ***********\n");
	printf("*********** 2 ----  Ticket collection  ***********\n");
	printf("*********** 3 ----  To refund a ticket  ***********\n");
	printf("*********** 0 ----  sign out  ***********\n");
	printf("****************************************************************\n");

	printf("【 System 】 Please select the function you want to realize ( Numbers ):");
}

//  User functions 
void fun_user()
{
    
	fun_Login_user();

	if (flag == 1)
	{
    
		int choice = 0;
		while (1)
		{
    
			menu_user();
			scanf("%d", &choice);
			switch (choice)
			{
    
			case 1://  Ticket purchase 
				Buy_ticket();
				break;
			case 2://  Ticket collection 
				Collect_ticket();
				break;
			case 3://  To refund a ticket 
				Return_ticket();
				break;
			case 0://  sign out 
				return;
			}

			system("cls");

			printf("【 System 】 Need to continue ?(Yes:1 / No:0):");
			scanf("%d", &choice);

			if (choice != 1)
			{
    
				if (choice != 0)
					printf("【 System 】 Input error !!!\n");
				system("pause");
				break;
			}
		}
	}
}

//  Administrator login interface 
void menu_Login_admin()
{
    
	system("cls");
	printf("****************************************************************\n");
	printf("***********  Administrator login  ***********\n");
	printf("*********** 1 ----  Sign in  ***********\n");
	printf("*********** 0 ----  sign out  ***********\n");
	printf("****************************************************************\n");

	printf("【 System 】 Please select the function you want to realize ( Numbers ):");
}

//  Administrator login function 
void fun_Login_admin()
{
    
	int choice = 0;
	menu_Login_admin();
	scanf("%d", &choice);
	switch (choice)
	{
    
	case 1://  Sign in 
		admin_login();
		break;
	case 0://  sign out 
		flag = 0;
		return;
	}
}

//  Administrator login 
void admin_login()
{
    
	int cnt = 0;
	do {
    
		printf("【 System 】 Please enter a user name :");
		scanf("%s", username);
		getchar();

		printf("【 System 】 Please input a password :");
		char c;
		int i = 0;
		while ((c = getch()) != '\r')
		{
    
			password[i] = c;
			i++;
			putchar('*');

		}
		printf("\n");
		password[i] = '\0';

		cnt++;
	} while (Read_admin_login() == 0 && cnt < 3);
}

//  Administrator login file read 
int Read_admin_login()
{
    
	FILE* fp = fopen("admin.txt", "r");

	if (fp == NULL)
	{
    
		return 0;
	}

	while (fscanf(fp, "%s %s", fusername, fpassword) != EOF)
	{
    
		fscanf(fp, "\n");
		if ((strcmp(fusername, username) == 0) && (strcmp(fpassword, password)) == 0)
		{
    
			printf("【 System 】 Landing successful \n");
			getch();
			system("cls");
			flag = 1;
			return 1;
		}
	}
	printf("【 System 】 Wrong user name or password , Please re-enter \n");
	getch();
	system("pause");

	return 0;
}

//  User login interface 
void menu_Login_user()
{
    
	system("cls");
	printf("****************************************************************\n");
	printf("***********  The user login  ***********\n");
	printf("*********** 1 ----  register  ***********\n");
	printf("*********** 2 ----  Sign in  ***********\n");
	printf("*********** 0 ----  sign out  ***********\n");
	printf("****************************************************************\n");

	printf(" Please select the function you want to realize ( Numbers ):");
}

//  User login function 
void fun_Login_user()
{
    
	int choice = 0;
	menu_Login_user();
	scanf("%d", &choice);
	switch (choice)
	{
    
	case 1:
		user_logon(&b);
	case 2:
		user_login(&b);
		break;
	case 0:
		flag = 0;
		return;
	}
}

//  The user login 
void user_login(USER* L)
{
    
	int cnt = 0;
	do {
    
		printf("【 System 】 Please enter a user name :");
		scanf("%s", username);
		getchar();

		printf("【 System 】 Please input a password :");
		char c;
		int i = 0;
		while ((c = getch()) != '\r')
		{
    
			password[i] = c;
			i++;
			putchar('*');

		}
		printf("\n");
		password[i] = '\0';

		cnt++;
	} while (Read_user_login(L) == 0 && cnt < 3);
}

int Read_user(USER* L)
{
    
	FILE* fp = fopen("user.txt", "r");

	if (fp == NULL)
	{
    
		return 0;
	}

	USER st;
	USER* s = NULL;
	USER* t = L;

	while (fscanf(fp, "%s %s", st.id, st.password) != EOF)
	{
    
		s = (USER*)malloc(sizeof(USER));
		*s = st;

		//  The tail interpolation 
		t->next = s;
		t = s;
		t->next = NULL;
	}

	fclose(fp);	//  Remember to close after opening the file 

	return 1;
}

//  User login file read 
int Read_user_login(USER* L)
{
    
	USER* q = L->next;
	while (q != NULL)
	{
    
		if ((strcmp(q->id, username) == 0) && (strcmp(q->password, password)) == 0)
		{
    
			printf(" Landing successful \n");
			getch();
			system("cls");
			flag = 1;
			return 1;
		}
		q = q->next;
	}
	printf("【 System 】 Wrong user name or password , Please re-enter \n");
	getch();
	system("pause");

	return 0;
}

//  User registration 
int user_logon(USER* L)
{
    
	FILE* pf = fopen("user.txt", "w");

	if (pf == NULL)
	{
    
		return 0;
	}

	USER st;

	printf(" Please enter a user name :");
	scanf("%s", st.id);
	printf(" Please input a password :");
	scanf("%s", st.password);

	Add1(&b, st);

	USER* p = L->next;

	while (p != NULL)
	{
    
		fprintf(pf, "%s %s\n", p->id, p->password);
		p = p->next;
	}

	fclose(pf);

	system("cls");
	printf(" Registered successfully !\n");
}

//  Insert 
void Add1(USER* L, USER e)
{
    
	//  The first interpolation 
	USER* p = L;
	USER* s = (USER*)malloc(sizeof(USER));
	*s = e;

	s->next = p->next;
	p->next = s;
}

//  Read the file 
int Read_FILE(NODE* L)
{
    
	FILE* pfRead = fopen("ticket.txt", "r");
	NODE st;
	NODE* s = NULL;
	NODE* t = L;

	if (pfRead == NULL)
	{
    
		return 0;
	}

	while (fscanf(pfRead, "%s %s %d %s %s %s %d %d %d", st.name, st.type, &st.time, st.day, st.start, st.site, &st.price, &st.num, &st.id) != EOF)
	{
    
		//  Read the seat table 
		for (int i = 1; i <= 10; i++)
		{
    
			for (int j = 1; j <= 10; j++)
			{
    
				fscanf(pfRead, "%d ", &st.seat[i][j]);
			}
			fscanf(pfRead, "\n");
		}

		s = (NODE*)malloc(sizeof(NODE));
		*s = st;

		//  The tail interpolation 
		t->next = s;
		t = s;
		t->next = NULL;
	}

	fclose(pfRead);	//  Remember to close after opening the file 

	return 1;
}

//  Save the file 
int Save_FILE(NODE* L)
{
    
	FILE* pfWrite = fopen("ticket.txt", "w");
	if (pfWrite == NULL)
	{
    
		return 0;
	}

	NODE* p = L->next;

	while (p != NULL)
	{
    
		fprintf(pfWrite, "%s %s %d %s %s %s %d %d %d\n", p->name, p->type, p->time, p->day, p->start, p->site, p->price, p->num, p->id);
		//  Save the seat table 
		for (int i = 1; i <= 10; i++)
		{
    
			for (int j = 1; j <= 10; j++)
			{
    
				fprintf(pfWrite, "%d ", p->seat[i][j]);
			}
			fprintf(pfWrite, "\n");
		}

		p = p->next;
	}

	//  Remember to close after opening the file 
	fclose(pfWrite);

	return 1;
}

//  Add movies 
void Add_Printf()
{
    
	system("cls");

	NODE st;
	printf("【 System 】 Please enter the relevant information of the new movie :\n");

	printf(" name :");
	scanf("%s", st.name);
	printf(" type :");
	scanf("%s", st.type);
	printf(" Duration :");
	scanf("%d", &st.time);
	printf(" date :");
	scanf("%s", st.day);
	printf(" Starting time :");
	scanf("%s", st.start);
	printf(" place :");
	scanf("%s", st.site);
	printf(" Price :");
	scanf("%d", &st.price);
	printf(" Number :");
	scanf("%d", &st.num);
	printf(" Number :");
	scanf("%d", &st.id);
	
	for (int i = 1; i <= 10; i++)
	{
    
		for (int j = 1; j <= 10; j++)
		{
    
			st.seat[i][j] = 0;
		}
	}

	Add(&list, st);
}

void Add(NODE* L, NODE e)
{
    
	//  The first interpolation 
	NODE* p = L;
	NODE* s = (NODE*)malloc(sizeof(NODE));
	*s = e;

	s->next = p->next;
	p->next = s;

	Save_FILE(L);
}

//  Delete movie 
void Delete_Printf(NODE* L)
{
    
	system("cls");

	int id;
	node* p;

	printf("【 System 】 Please enter the number of the movie you want to delete :");
	scanf("%d", &id);
	NODE* st = Search_id(id, L);
	p = st;

	if (st == NULL)
	{
    
		printf(" The movie cannot be found !\n");
		return;
	}

	st = st->next;
	printf("_________________________________________________________________________________________________________\n");
	printf("|\t name \t\t| type \t| Duration \t| date \t\t| Starting time \t| place \t| Price \t| Number \t| Number \t |\n");
	printf("_________________________________________________________________________________________________________\n");
	printf("_________________________________________________________________________________________________________\n");
	printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t|%d\t |\n", st->name, st->type, st->time, st->day, st->start, st->site, st->price, st->num, st->id);
	printf("_________________________________________________________________________________________________________\n");

	Delete(p);

	//  Save information 
	Save_FILE(L);
}

void Delete(NODE* s)
{
    
	NODE* t = s->next;

	s->next = t->next;
	t->next = NULL;

	free(t);
}

//  Modify the movie 
void Fix(NODE* L)
{
    
	system("cls");

	int id;
	printf("【 System 】 Please enter the number of the movie you want to modify :");
	scanf("%d", &id);

	NODE* st = Search_id(id, L);

	if (st == NULL)
	{
    
		printf(" Unable to find the movie !\n");
		return;
	}

	st = st->next;

	int choice = 0;
	while (1)
	{
    
		system("cls");

		//  Output the movie information to be modified once 
		printf("_________________________________________________________________________________________________________\n");
		printf("|\t name \t\t| type \t| Duration \t| date \t\t| Starting time \t| place \t| Price \t| Number \t| Number \t|\n");
		printf("_________________________________________________________________________________________________________\n");
		printf("_________________________________________________________________________________________________________\n");
		printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t|%d\t |\n", st->name, st->type, st->time, st->day, st->start, st->site, st->price, st->num, st->id);
		printf("_________________________________________________________________________________________________________\n");
		printf("_________________________________________________________________________________________________________\n");
		
		printf("|\t Modify name  ---- 1\t|\n");
		printf("|\t Modification type  ---- 2\t|\n");
		printf("|\t Modification duration  ---- 3\t|\n");
		printf("|\t modification date  ---- 4\t|\n");
		printf("|\t Modify the start time  ---- 5\t|\n");
		printf("|\t Location modification  ---- 6\t|\n");
		printf("|\t Revise the price  ---- 7\t|\n");
		printf("|\t Modify quantity  ---- 8\t|\n");
		printf("|\t Change the number  ---- 9\t|\n");
		printf("|\t sign out  ---- 0\t|\n");
		printf("________________________________\n");

		printf("【 System 】 Please enter the information to be modified :");
		scanf("%d", &choice);

		switch (choice)
		{
    
		case 1:
			printf("【 System 】 Please enter name :");
			scanf("%s", st->name);
			break;
		case 2:
			printf("【 System 】 Please enter the type :");
			scanf("%s", st->type);
			break;
		case 3:
			printf("【 System 】 Please enter the duration :");
			scanf("%d", &st->time);
			break;
		case 4:
			printf("【 System 】 Please enter the date :");
			scanf("%s", st->day);
			break;
		case 5:
			printf("【 System 】 Please enter the start time :");
			scanf("%s", st->start);
			break;
		case 6:
			printf("【 System 】 Please enter the location :");
			scanf("%s", st->site);
			break;
		case 7:
			printf("【 System 】 Please enter the price :");
			scanf("%d", &st->price);
			break;
		case 8:
			printf("【 System 】 Please enter the quantity :");
			scanf("%d", &st->num);
			break;
		case 9:
			printf("【 System 】 Please enter the number :");
			scanf("%d", &st->id);
			break;
		case 0:
			break;
		}
		printf(" Continue to modify the movie information ?(Yes:1 / No:0):");
		scanf("%d", &choice);
		if (choice == 0)
		{
    
			break;
		}
	}

	//  After modification, the information of the film 
	printf("_________________________________________________________________________________________________________\n");
	printf("|\t name \t\t| type \t| Duration \t| date \t\t| Starting time \t| place \t| Price \t| Number \t| Number \t|\n");
	printf("_________________________________________________________________________________________________________\n");
	printf("_________________________________________________________________________________________________________\n");
	printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t|%d\t |\n", st->name, st->type, st->time, st->day, st->start, st->site, st->price, st->num, st->id);
	printf("_________________________________________________________________________________________________________\n");

	//  Save information 
	Save_FILE(L);
}

//  Query movie 
void Search_Printf(NODE* L)
{
    
	system("cls");

	int choice = 0;
	printf(" Query by name  ---- 1\n");
	printf(" Search by type  ---- 2\n");
	printf(" Query by number  ---- 3\n");
	printf("【 System 】 Please enter query method :");
	scanf("%d", &choice);

	node* st;

	if (choice == 1)
	{
    
		char name[N];
		int cnt = 0;

		printf("【 System 】 Please enter the movie name to query :");
		scanf("%s", name);

		cnt = Search_allname(name, L);

		if (cnt == 0)
		{
    
			printf(" Cannot find this type of movie !\n");
		}
	}
	else if (choice == 2)
	{
    
		char type[N];
		int cnt = 0;

		printf("【 System 】 Please enter the movie type to query :");
		scanf("%s", type);

		cnt = Search_type(type, L);

		if (cnt == 0)
		{
    
			printf(" Cannot find this type of movie !\n");
		}
	}
	else if (choice == 3)
	{
    
		int id;

		printf("【 System 】 Please enter the movie number to query :");
		scanf("%d", &id);

		st = Search_id(id, L);

		if (st == NULL)
		{
    
			printf(" Check no one !\n");
		}
		else
		{
    
			st = st->next;

			printf("_________________________________________________________________________________________________________\n");
			printf("|\t name \t\t| type \t| Duration \t| date \t\t| Starting time \t| place \t| Price \t| Number \t| Number \t |\n");
			printf("_________________________________________________________________________________________________________\n");
			printf("_________________________________________________________________________________________________________\n");
			printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t|%d\t |\n", st->name, st->type, st->time, st->day, st->start, st->site, st->price, st->num, st->id);
			printf("_________________________________________________________________________________________________________\n");
		}
	}
}

//  Find by name 
int Search_allname(char name[], NODE* L)
{
    
	int cnt = 0;

	node* p = L;

	while (p->next != NULL)
	{
    
		p = p->next;

		if (strcmp(name, p->name) == 0)
		{
    
			cnt++;

			if (cnt == 1)
			{
    
				printf("_________________________________________________________________________________________________________\n");
				printf("|\t name \t\t| type \t| Duration \t| date \t\t| Starting time \t| place \t| Price \t| Number \t| Number \t |\n");
				printf("_________________________________________________________________________________________________________\n");
			}
			printf("_________________________________________________________________________________________________________\n");
			printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t|%d\t |\n", p->name, p->type, p->time, p->day, p->start, p->site, p->price, p->num, p->id);
			printf("_________________________________________________________________________________________________________\n");
		}

	}
	return cnt;
}

//  Find the first by name 
NODE* Search_name(char name[], NODE* L)
{
    
	NODE* p = L;

	while (p->next != NULL)
	{
    
		if (strcmp(name, p->next->name) == 0)
		{
    
			return p;
		}
		p = p->next;
	}
	return NULL;
}

//  Search by number 
NODE* Search_id(int id, NODE* L)
{
    
	NODE* p = L;

	while (p->next != NULL)
	{
    
		if (p->next->id == id)
		{
    
			return p;
		}
		p = p->next;
	}
	return NULL;
}

//  Find by type 
int Search_type(char type[], NODE* L)
{
    
	int cnt = 0;

	node* p = L;

	while (p->next != NULL)
	{
    
		p = p->next;

		if (strcmp(type, p->type) == 0)
		{
    
			cnt++;

			if (cnt == 1)
			{
    
				printf("_________________________________________________________________________________________________________\n");
				printf("|\t name \t\t| type \t| Duration \t| date \t\t| Starting time \t| place \t| Price \t| Number \t| Number \t |\n");
				printf("_________________________________________________________________________________________________________\n");
			}
			printf("_________________________________________________________________________________________________________\n");
			printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t|%d\t |\n", p->name, p->type, p->time, p->day, p->start, p->site, p->price, p->num, p->id);
			printf("_________________________________________________________________________________________________________\n");
		}
		
	}

	return cnt;
}

//  Show movie 
void Print(NODE* L)
{
    
	system("cls");

	node* p = L->next;
	Print_Printf();

	if (p != NULL)
	{
    
		while (p != NULL)
		{
    
			printf("_________________________________________________________________________________________________________\n");
			printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t|%d\t |\n", p->name, p->type, p->time, p->day, p->start, p->site, p->price, p->num, p->id);
			printf("_________________________________________________________________________________________________________\n");
			p = p->next;
		}
	}
}

void Print_Printf()
{
    
	printf("_________________________________________________________________________________________________________\n");
	printf("|\t name \t\t| type \t| Duration \t| date \t\t| Starting time \t| place \t| Price \t| Number \t| Number \t |\n");
	printf("_________________________________________________________________________________________________________\n");
}

//  Sort movies 
void Sort(NODE* L)
{
    
	system("cls");

	int choice = 0;
	printf(" Sort according to the duration from large to small  ---- 1\n");
	printf(" Sort according to the duration from small to large  ---- 2\n");
	printf(" Sort by date in descending order  ---- 3\n");
	printf(" Sort by date from small to large  ---- 4\n");
	printf(" Sort according to the price from large to small  ---- 5\n");
	printf(" Sort according to the price from small to large  ---- 6\n");
	printf(" Sort by quantity from large to small  ---- 7\n");
	printf(" Sort by quantity from small to large  ---- 8\n\n");
	printf("【 System 】 Please select sort by :");
	scanf("%d", &choice);

	int flag = 0;
	for (node* p = L->next; p != NULL; p = p->next)
	{
    
		for (node* q = p; q != NULL; q = q->next)
		{
    
			switch (choice)
			{
    
			case 1:
				if (!cmp_big_time(*p, *q))
				{
    
					flag = 1;
				}
				break;
			case 2:
				if (!cmp_small_time(*p, *q))
				{
    
					flag = 1;
				}
				break;
			case 3:
				if (!cmp_big_day(*p, *q))
				{
    
					flag = 1;
				}
				break;
			case 4:
				if (!cmp_small_day(*p, *q))
				{
    
					flag = 1;
				}
				break;
			case 5:
				if (!cmp_big_price(*p, *q))
				{
    
					flag = 1;
				}
				break;
			case 6:
				if (!cmp_small_price(*p, *q))
				{
    
					flag = 1;
				}
				break;
			case 7:
				if (!cmp_big_num(*p, *q))
				{
    
					flag = 1;
				}
				break;
			case 8:
				if (!cmp_small_num(*p, *q))
				{
    
					flag = 1;
				}
				break;
			}
			if (flag == 1)
			{
    
				//  Exchange data fields 
				node t = *p;
				*p = *q;
				*q = t;
				//  Handle pointer fields 
				t.next = p->next;
				p->next = q->next;
				q->next = t.next;
				flag = 0;
			}
		}
	}
	printf("【 System 】 Sort success !\n");
}

//  The duration varies from large to small 
int cmp_big_time(NODE e1, NODE e2)
{
    
	return e1.time > e2.time;
}

//  Date from big to small 
int cmp_big_day(NODE e1, NODE e2)
{
    
	return strcmp(e1.day, e2.day) >= 0 ? 1 : 0;
}

//  The price ranges from big to small 
int cmp_big_price(NODE e1, NODE e2)
{
    
	return e1.price > e2.price;
}

//  The quantity ranges from large to small 
int cmp_big_num(NODE e1, NODE e2)
{
    
	return e1.num > e2.num;
}

//  From small to large 
int cmp_small_time(NODE e1, NODE e2)
{
    
	return e1.time < e2.time;
}

//  Date from small to large 
int cmp_small_day(NODE e1, NODE e2)
{
    
	return strcmp(e1.day, e2.day) < 0 ? 1 : 0;
}

//  The price increases from small to large 
int cmp_small_price(NODE e1, NODE e2)
{
    
	return e1.price < e2.price;
}

//  From small to large 
int cmp_small_num(NODE e1, NODE e2)
{
    
	return e1.num < e2.num;
}

//  File save ticket information 
int Save_TICKET(TICKET* L)
{
    
	FILE* pfWrite = fopen("ticket1.txt", "w");
	if (pfWrite == NULL)
	{
    
		return 0;
	}

	TICKET* p = L->next;

	while (p != NULL)
	{
    
		fprintf(pfWrite, "%s %s %d %s %s %s %d %d %s %d %d %d\n", p->name, p->type, p->time, p->day, p->start, p->site, p->price, p->id, p->username, p->x, p->y, p->istake);
		p = p->next;
	}

	//  Remember to close after opening the file 
	fclose(pfWrite);

	return 1;
}

//  Read ticket information 
int Read_TICKET(TICKET* L)
{
    
	FILE* pfRead = fopen("ticket1.txt", "r");
	TICKET st;
	TICKET* s = NULL;
	TICKET* t = L;

	if (pfRead == NULL)
	{
    
		return 0;
	}

	while (fscanf(pfRead, "%s %s %d %s %s %s %d %d %s %d %d %d\n", st.name, st.type, &st.time, st.day, st.start, st.site, &st.price, &st.id, st.username, &st.x, &st.y, &st.istake) != EOF)
	{
    
		s = (TICKET*)malloc(sizeof(TICKET));
		*s = st;

		//  The tail interpolation 
		t->next = s;
		t = s;
		t->next = NULL;
	}

	fclose(pfRead);	//  Remember to close after opening the file 

	return 1;
}

//  Ticket purchase 
void Buy_ticket()
{
    
	do {
    
		Sort(&list);
		system("pause");
		Print(&list);
	} while (Buy_ticket_Printf() == 0);
}

int Buy_ticket_Printf()
{
    
	TICKET s; //  Record ticket information 

	int id;
	printf("【 System 】 Please enter the number of the movie you want to buy :");
	scanf("%d", &id);

	system("cls");

	node* st = Search_id(id, &list);

	if (st == NULL)
	{
    
		printf("【 System 】 Unable to find the movie !\n");

		int choice;
		printf("【 System 】 Please choose whether you want to continue to purchase tickets ?(Yes:1 / No:0):");
		scanf("%d", &choice);
		
		if (choice == 1)
			return 0;
		else if (choice == 0)
			return 1;
		else
		{
    
			printf(" Input error \n");
			system("pause");
			return 1;
		}
	}

	st = st->next;
	printf("【 System 】 The information of the film is as follows :\n");
	printf("_________________________________________________________________________________________________________\n");
	printf("|\t name \t\t| type \t| Duration \t| date \t\t| Starting time \t| place \t| Price \t| Number \t| Number \t |\n");
	printf("_________________________________________________________________________________________________________\n");
	printf("_________________________________________________________________________________________________________\n");
	printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t|%d\t |\n", st->name, st->type, st->time, st->day, st->start, st->site, st->price, st->num, st->id);
	printf("_________________________________________________________________________________________________________\n");

	printf("【 System 】 The seat diagram is as follows :(■ Indicates that... Has been reserved ,□ Indicates that... Is not booked )\n");

	printf(" ");
	for (int i = 1; i <= 10; i++)
	{
    
		printf("%3d", i);
	}
	printf("\n");

	for (int i = 1; i <= 10; i++)
	{
    
		printf("%4d", i);
		for (int j = 1; j <= 10; j++)
		{
    
			if (st->seat[i][j] == 0)
				printf(" □");
			else
				printf(" ■");
		}
		printf("\n");
	}

	int a;
	printf("【 System 】 Please select the quantity you want to buy :");
	scanf("%d", &a);

	for (int i = 0; i < a; i++)
	{
    
		printf("【 System 】 Please choose the seat number you want to buy :\n");
		int x, y;
		printf(" That's ok (1-10):");
		scanf("%d", &x);
		printf(" Column (1-10):");
		scanf("%d", &y);

		if (st->seat[x][y] == 0)
		{
    
			st->seat[x][y] = 1;
			st->num = st->num - 1;
		}
		else
		{
    
			printf("【 System 】 Booking failed , The seat has been reserved \n");

			int choice;
			printf("【 System 】 Please choose whether you want to continue to purchase tickets ?(Yes:1 / No:0):");
			scanf("%d", &choice);

			if (choice == 1)
				return 0;
			else if (choice == 0)
				return 1;
			else
			{
    
				printf(" Input error \n");
				system("pause");
				return 1;
			}
		}

		//  Record order information 
		strcpy(s.name, st->name);
		strcpy(s.type, st->type);
		s.time = st->time;
		strcpy(s.day, st->day);
		strcpy(s.start, st->start);
		strcpy(s.site, st->site);
		s.price = st->price;
		s.id = st->id;

		strcpy(s.username, username);
		s.x = x;
		s.y = y;
		s.istake = 0;

		Add2(&c, s);

		printf("【 System 】 The reservation is successful \n");
	}

	system("pause");
	system("cls");

	printf("【 System 】 Your order information is as follows :\n");
	printf("_________________________________________________________________________________________________\n");
	printf("|\t name \t\t| type \t| Duration \t| date \t\t| Starting time \t| place \t| Price \t| Number \t|\n");
	printf("_________________________________________________________________________________________________\n");
	printf("_________________________________________________________________________________________________\n");
	printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t|\n", st->name, st->type, st->time, st->day, st->start, st->site, st->price * a, a);
	printf("_________________________________________________________________________________________________\n");

	system("pause");

	Save_FILE(&list);
	return 1;
}

//  Save reservation information 
void Add2(TICKET* L, TICKET e)
{
    
	//  The first interpolation 
	TICKET* p = L;
	TICKET* s = (TICKET*)malloc(sizeof(TICKET));
	*s = e;

	s->next = p->next;
	p->next = s;

	Save_TICKET(L);
}

//  Ticket collection 
void Collect_ticket()
{
    
	system("cls");
	
	Print_ticket(&c);

	Save_TICKET(&c);
}

void Print_ticket(TICKET* L)
{
    
	TICKET* p = L->next;
	int cnt = 0, choice = 0;
	
	if (p != NULL)
	{
    
		while (p != NULL && strcmp(p->username, username) == 0 && p->istake==0)
		{
    
			printf("【 System 】 Your order is as follows :\n");
			Print_ticket_Printf();
			printf("______________________________________________________________________________________________________________________\n");
			printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t |%-10s|%d\t|%-5d|\n", p->name, p->type, p->time, p->day, p->start, p->site, p->price, p->id, p->username, p->x, p->y);
			printf("______________________________________________________________________________________________________________________\n");

			printf("【 System 】 Whether to collect tickets ?(Yes:1 / No:0):");
			scanf("%d", &choice);

			if (choice != 1)
			{
    
				if (choice != 0)
					printf("【 System 】 Input error !!!\n");
			}
			else
			{
    
				p->istake = 1;
				printf("【 System 】 Ticket collection succeeded !!!\n");
			}
			system("pause");

			p = p->next;

			cnt++;
		}
	}

	if (cnt == 0)
		printf("【 System 】 I'm sorry , You have no ticket at present .\n");
}

void Print_ticket_Printf()
{
    
	system("cls");
	printf("______________________________________________________________________________________________________________________\n");
	printf("|\t name \t\t| type \t| Duration \t| date \t\t| Starting time \t| place \t| Price \t| Number \t | Ticket buyer  | That's ok \t| Column  |\n");
	printf("______________________________________________________________________________________________________________________\n");
}

//  To refund a ticket 
void Return_ticket()
{
    
	system("cls");

	printf("【 System 】 Your order is as follows :\n");
	system("pause");
	Print_ticket1(&c);

	Save_TICKET(&c);
}

//  Print information 
void Print_ticket1(TICKET* L)
{
    
	TICKET* s = L;
	TICKET* p = NULL, * q = NULL;
	int cnt = 0, choice = 0;

	while (1)
	{
    
		q = Find_ticket(s, username);
		if (q == NULL)
			break;

		p = q;
		Print_ticket_Printf();
		printf("______________________________________________________________________________________________________________________\n");
		printf("|%-15s\t|%s\t|%d\t|%s\t|%s\t\t|%s\t|%d\t|%d\t |%-10s|%d\t|%-5d|\n", q->next->name, q->next->type, q->next->time, q->next->day, q->next->start, q->next->site, q->next->price, q->next->id, q->next->username, q->next->x, q->next->y);
		printf("______________________________________________________________________________________________________________________\n");

		printf("【 System 】 Is the ticket refunded ?(Yes:1 / No:0):");
		scanf("%d", &choice);

		if (choice != 1)
		{
    
			if (choice != 0)
				printf("【 System 】 Input error !!!\n");
			q = q->next;
		}
		else if(choice == 1)
		{
    
			NODE* r = Search_id(q->next->id, &list);
			r->next->num = r->next->num + 1;
			r->next->seat[q->next->x][q->next->y] = 0;
			printf("%d,%d\n", r->next->num, r->next->seat[p->next->x][p->next->y]);


			Save_FILE(&list);
			Delete_ticket(p);
		}
		system("pause");
		s = q;
		cnt++;
	}

	if (cnt == 0)
		printf("【 System 】 I'm sorry , You currently have no tickets to return .\n");
}

//  Find the precursor node 
TICKET* Find_ticket(TICKET* L, char username[])
{
    
	TICKET* p = L;

	while (p->next != NULL)
	{
    
		if (strcmp(username, p->next->username) == 0)
		{
    
			return p;
		}
		p = p->next;
	}
	return NULL;
}

//  Delete 
void Delete_ticket(TICKET* s)
{
    
	TICKET* t = s->next;

	s->next = t->next;
	t->next = NULL;

	free(t);
}

//  Exit the system 
void goodbye()
{
    
	system("cls");
	printf(" Welcome to use the cinema ticket management system next time !");
	exit(0);
}

summary

Finally finished writing the lesson design , It takes a long time , But it is also consolidated C Language knowledge , Hey , Mutual encouragement !

原网站

版权声明
本文为[WE-ubytt]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050342034863.html