C Course Settings/Hotel Room Management System/Included Source Code

C Course Setup/Hotel Room Management System/Supplied Source Code/Array Implementation

//If you miss something, others will get it. Just as you get it, others will miss it.

Two weeks of C language course design is over, which is a process from the initial idea of a program to the final writing of code debugging code.Completely make a product prototype, exercise the ability of programming and actual combat, reflecting the actual application of learning C.

Below is my experience sharing of this lesson setting process and the open source of the code.
Course title: Hotel room management system.

1. Title requirements

Design "Hotel Room Management System" software to meet the following requirements:
(1) The information involved in the system is:
Customer information includes: number, name, gender, origin, ID number, date of birth, age, nationality, residence, work unit, etc.
(2) Room information includes: room number, room grade, price, availability, etc.
(3) Check-in information includes: customer number, customer name, check-in date, check-out date, etc.
(4) Service information includes service item number, item name, fee, etc.
(2) The system can realize: information browsing function;Query function: Query by room number, name and stay time;Delete and modify information.

This management system is implemented using structured arrays or chain tables to store information, and its basic functions are approximately the same.For the basic operation source code of single-chain lists, see the following article:
Basic operation source code of single-chain list and basic learning idea of data structure

2. Product Requirements

This management system is applicable to the management of room resources and customer information in all kinds of small and medium-sized hotels, and has realized the information management of hotels. The system mainly includes basic information setup, query statistics management, and the function of opening and checking out rooms.

Compiler software: Compiler software used in this program: microsoft visual C++ 6.0

3. Functional requirements

3.1 Administrator Logon System

 (1)Initialize Administrator Login Account and Password
 (2)Administrator Enter Login Password
 (3)Enter the system interface to complete functions such as check-in and check-out information query    

3.2 Registration of Customer Information Systems

(1)Register customer name, gender, ID number, etc.
(2)Record customer reservation days and prepaid room charges
(3)Show room number for successful customer registration
(4)Select a room and automatically change room status information

Because housing and customer information involves many types of data, an array of structures is used to store information.You can record related data with a file.

3.3 Room Information and Customer Information Query

(1)Query room status 
(2)Find by customer name: Find the customer's room number and customer information
(3)Find by Customer ID Number: Find the customer's room number and customer information

Encapsulation of 3.4 Opening Function

(1)Dynamic memory allocation initializes new customer information
(2)Record customer reservation days and prepaid room charges
(3)Show the successful room number of the customer and add one to the number of customers
(4)Change room status information

Encapsulation of 3.5 Check Out Function

(1)Calculate actual consumption based on actual housing time
(2)Change room status and reduce number of customers by one
(3)Show check out success and free this memory space

4. Detailed design

4.1 Principal Function (main)

Entry to run this program

4.2 Logon Functions

[Function] Administrators enter the correct account and password at the same time to log in to the system interface

4.3 Information Entry Function

Enter customer information

4.4 Enter system functions

[Function] Enter the system interface for function selection

4.5 Information Query Function

[Function] Query customer information and room status information

Encapsulation of 4.6 Opening Function

[Function] Select rooms of the type required for customers and modify room status

Encapsulation of 4.7 Check Out Function

[Function] Check out and modify room status

5. System Testing

Login interface
Only when the user enters the correct user name and password at the same time, can he enter the system, as shown in the figure:


If the input is wrong, please re-enter the prompt!Figure:

System Main Interface
Users successfully enter the system interface, and can choose the functions they need to achieve to achieve the interaction between users and the system.Figure:

Check-in and Selection Interface
Enter customer information, select room type and number of days to reserve.Figure:

When the input information is complete and correct, there will be the amount to be paid and the room number to be accommodated, which makes the room open successfully.Figure:

Query hotel room status
Print out the occupied and unoccupied room numbers and output them on the screen in ten rooms as a row, as shown in the following figure:

Find customer information by customer name, as shown in Fig.

Find customer information by customer ID number, as shown in the figure:

Check-out interface
(1) Enter the name and ID number of the check-out customer
(2) Enter the actual number of housing days
(3) Return the actual consumption amount
Figure:

6. References

[1] Tan Haoqiang. C Programming (Third Edition). Tsinghua University Press. 2005
[2] He Qin Ming Yan Hui. C Language Programming. Higher Education Press. 2008
[3] Chen Qiang. C Language Core Development Technology From Development to Mastery. University of Electronics Industry Press. 2006
[4] Yan Weimin, Wu Weimin. Data Structure (C Language Edition). Tsinghua University Press. 2007
[5] Tuesday Qiang. New C Program Design. Tsinghua University Press. 2011
[6] Deng Wenhua. Data Structure Experiments and Training Tutorials. Tsinghua University Press. 2011

7. Source Code

//Structures, arrays of structures, pointers to arrays of structures, function encapsulation.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#Include<malloc.h>//dynamic memory allocation
void init_room();
void enter();
void start();
void check_in();
void check_out();
void change();
void search();
void add(struct Customer* cs);

int i = 0;
int pay = 0;

struct Room
{
	int number;
	int grade;
	int price;
	int status;
};

struct Customer
{
	char name[10];
	char sex[2];
	char ID[19];
	char addr[10];
	char birth[10];
	char nation[10];
	char place[10];//Residence
	char work[10];//Work unit 
	int pay;
	int day;
	int room_number;
};

struct Room room[60];
struct Customer* customer[60];

int main()
{
	system("mode con cols=130 lines=50");
    system("color 0A");
	init_room();
	enter();
	while (1)
	{
		start();
	}
	return 0;
}

//Initialize sixty rooms
void init_room()
{
	int j = 101, k;
	for (k = 0; k < 20; k++)
	{
		room[k].number = j++;
		room[k].grade = 1;//Single room 
		room[k].price = 150;
		room[k].status = 0;
	}
	j = 201, k;
	for (k = 20; k < 40; k++)
	{
		room[k].number = j++;
		room[k].grade = 2;//Double room 
		room[k].price = 200;
		room[k].status = 0;
	}
	j = 301, k;
	for (k = 40; k < 60; k++)
	{
		room[k].number = j++;
		room[k].grade = 3;//Family room 
		room[k].price = 300;
		room[k].status = 0;
	}
}

//Logon function
void enter()
{
	char administrator[10] = "123";
	char password[20] = "000";
	char name[10];
	char code[20];
	printf("\n\n\n\n");
	printf("\t\t\t\t--------------------------------------------------\n");
	printf("\t\t\t\t|                                                 |\n");
	printf("\t\t\t\t-------------Welcome to Hotel Room Management System-------------\n");
	printf("\t\t\t\t|                                                 |\n");
	printf("\t\t\t\t--------------------------------------------------\n");
	printf("\n\n");
	printf("\t\t\t\t Account number:");
	scanf("%s", name);
	printf("\t\t\t\t Password:");
	scanf("%s", code);
	while ((strcmp(name, administrator) != 0) || (strcmp(code, password) != 0))
	{
		printf("\t\t\t\t Incorrect input, please re-enter!\n");
		printf("\t\t\t\t Account number:");
		scanf("%s", name);
		printf("\t\t\t\t Password:");
		scanf("%s", code);
	}
	printf("\t\t\t\t Press any key to login!\n");
}

//System Entry
void start()
{
	int choice;
	system("pause");
	system("cls");
	printf("1->Opening 2->Check out 3->Information Query 4->Modify Information 5->Exit System\n");	
	printf("Please enter your choice:");
	scanf("%d", &choice);
	while (choice != 1 && choice != 2 && choice != 3 && choice != 4&&choice!=5)
	{
		printf("Invalid option input, please re-enter:\n");
		printf("1->Opening 2->Check out 3->Information Query 4->Modify Information 5->Exit System\n");	
		printf("Please enter your choice:\n");
		scanf("%d", &choice);
	}
	switch (choice)
	{
	case 1:
		check_in();
		break;
	case 2:
		check_out();
		break;
	case 3:
		search();
		break;
	case 4:
		change();
		break;
	case 5:
		exit(0);
		break;
	default:
		break;
	}
}

//Encapsulation of Opening Function
void check_in()
{
	int choice, day;
	customer[i] = (struct Customer*)malloc(sizeof(struct Customer));
	add(customer[i]);
	printf("1->Single room 150/Interval 2->Double room 200/Interval 3->Home room 300/between\n");
	printf("Please select room type:");
	scanf("%d", &choice);
	printf("Please enter the number of days to stay:");
	scanf("%d", &day);
	customer[i]->day = day;
	switch (choice)
	{
		int n;
	case 1:
		for (n = 0; n < 20; n++)
		{
			if (room[n].status == 0)
			{
				pay = 150 * day;
				printf("Please collect%d The room rate\n", pay);
				printf("Room number is:%d\n", room[n].number);
				customer[i]->pay = pay;
				customer[i]->room_number = room[n].number;
				room[n].status = 1;
			}
			break;
		}
		break;
	case 2:
		for (n = 20; n < 40; n++)
		{
			if (room[n].status == 0)
			{
				pay = 200 * day;
				printf("Please collect%d The room rate\n", pay);
				printf("Room number is:%d\n", room[n].number);
				customer[i]->pay = pay;
				customer[i]->room_number = room[n].number;
				room[n].status = 1;
			}
			break;
		}
		break;
	case 3:
		for (n = 40; n < 60; n++)
		{
			if (room[n].status == 0)
			{
				pay = 200 * day;
				printf("Please collect%d The room rate\n", pay);
				printf("Room number is:%d\n", room[n].number);
				customer[i]->pay = pay;
				customer[i]->room_number = room[n].number;
				room[n].status = 1;
			}
			break;
		}
		break;
	}
	++i;
}

//Encapsulation of check-out settlement function
void check_out()
{
	char name2[10], ID2[19];
	int k, day2, room_number, day, standard,choice;
	printf("Please enter the name of the customer who checked out:");
	scanf("%s", name2);
	printf("Please enter the ID number of the customer who checked out:");
	scanf("%s", ID2);
	printf("Please enter the number of days the customer will live:\n");
    scanf("%d", &day2);
	for (k = 0; k < i; k++)
	{
		if ((strcmp(customer[k]->ID, ID2) == 0) && (strcmp(customer[k]->name, name2) == 0))
		{
			room_number = customer[k]->room_number;
			day = (customer[k]->day) - day2;
			standard = room_number / 100;
			switch (standard)
			{
			case 1:
				printf("The customer's room number is%d :For single room,150 yuan per day\n",room_number);
				printf("Actual housing consumption %d Yuan Integer!\n", day2 * 150);
				printf("\n");
				if (day2 * 150 < pay)
					printf("Please return to this customer %d Yuan Integer!\n", day * 150);
				if (day2 * 150 > pay)
					printf("Please reimburse the customer for housing %d Yuan Integer!\n", day2 * 150 - pay);

				printf("Total money spent is%d\n", day2 * 150);
				break;
			case 2:
				printf("The customer's room number is%d :For double room,200 yuan per day\n",room_number);
				printf("Actual housing consumption %d Yuan Integer!\n", day2 * 200);
				printf("\n");
				if (day2 * 200 < pay)
					printf("Please return to this customer %d Yuan Integer!\n", day * 150);
				if (day2 * 200 > pay)
					printf("Please reimburse the customer for housing %d Yuan Integer!\n", day2 * 200 - pay);

				printf("Total money spent is%d\n", day2 * 200);
				break;
			case 3:
				printf("Customer No. 1 has a room number of%d :For a family room,300 yuan per day\n",room_number);
				printf("Actual housing consumption %d Yuan Integer!\n", day2 * 300);
				printf("\n");
				if (day2 * 300 < pay)
					printf("Please return to this customer %d Yuan Integer!\n", day * 300);
				if (day2 * 150 > pay)
					printf("Please reimburse the customer for housing %d Yuan Integer!\n", day2 * 300 - pay);

				printf("Total money spent is%d\n", day2 * 300);
				break;
			}

			printf("Clear check-out accounting,Press 1: ");
			scanf("%d", &choice);
			if (choice == 1)
			{
				int j;
				for (j = 0; j < 80; j++)
				{
					if (room[j].number == customer[k]->room_number)
						room[j].status = 0;
				}
				--i;
				for (j = 0; j < i; j++)
				{
					customer[j] = customer[j + 1];
				}
				free(customer[i]);
				printf("Check out successful!");
			}
		}
	}
}

//Encapsulation of Information Query Functions
void search()
{
	int choice;
	char name3[10];
	char id3[19];
	printf("1->Room Information Query\n2->Customer Information Query\n");
	printf("Please enter your choice:");
	fflush(stdin);
	scanf("%d", &choice);
	if (choice == 1)
	{
		int k, count1 = 0, count2 = 0;
		printf("Unoccupied rooms have:\n");
		for (k = 0; k < 60; k++)
		{
			if (room[k].status == 0)
			{
				printf("%d", room[k].number);
				count1++;
				printf("  ");
			}
			if (count1 % 10 == 0)
			{
				printf("\n");
			}

		}
		printf("\n");
		printf("The occupants'rooms are:\n");
		for (k = 0; k < 60; k++)
		{
			if (room[k].status != 0)
			{
				printf("%d", room[k].number);
				count2++;
			}
			else
				return;
			if (count2 % 10 == 0)
			{
				printf("\n");
			}
		}
		printf("\n");
	}
	else if (choice == 2)
	{
		int choice2 ,j;
		printf("1->Find by name:\n2->Find by ID number\n:");
		printf("Please enter your choice:");
		scanf("%d",&choice2);
		switch (choice2)
		{
		case 1:
			printf("Please enter the customer's name: \n");
			scanf("%s", name3);
			for (j = 0; j < i; j++)
			{
				if (strcmp(customer[j]->name, name3) == 0)
				{
					printf("%s Housing information for:\n", name3);
					printf("Room number is: %d\n",customer[j]->room_number);
					printf("Full name:%s\n",customer[j]->name);
					printf("ID card No.:%s\n",customer[j]->ID);
					printf("Origin:%s\n",customer[j]->addr);


				}
			}
			break;
		case 2:
			
			printf("Please enter the customer's ID: \n");
			scanf("%s", id3);
			for (j = 0; j < i; j++)
			{
				if (strcmp(customer[j]->ID, id3) == 0)
				{
					printf("%s Housing information for:\n", customer[j]->name);
					printf("Room number is: %d\n", customer[j]->room_number);
					printf("Full name:%s\n",customer[j]->name);
					printf("ID card No.:%s\n",customer[j]->ID);
					printf("Origin:%s\n",customer[j]->addr);
				}
			}
			break;
		}
	}
	else
	{
		printf("Input is inappropriate!");
	}
}


//Encapsulate Add Customer Information Function
void add(struct Customer* cs)
{
	printf("Please enter the customer's name:");
	scanf("%s",cs->name);
	printf("Please enter gender:");
	scanf("%s", cs->sex);
	printf("Please enter your ID number:");
	scanf("%s", cs->ID);
	printf("Please enter your origin:");
	scanf("%s", cs->addr);
	//printf("Please enter the year of birth:");
	//scanf("%s", cs->birth);
	//printf("Please enter nationality:");
	//scanf("%s",cs->nation);
	//printf("Please enter your residence:");
	//scanf("%s", cs->place);
	//printf("Please enter work unit:");
	//scanf("%s", cs->work);
}


//Modify Customer Information Function Encapsulation
void change()
{
	char name4[10];
	int k,choice;
	char name5[10],sex5[2],ID5[19],addr5[10];
	printf("Please enter the name of the customer you want to modify:\n");
	scanf("%s",&name4);
	for(k=0;k<i;k++)
	{
			if(strcmp(customer[k]->name,name4)==0)
			{
			        printf("1->Name 2->Gender 3->ID Number 4->Origin\n");
					printf("Please select the customer information you want to modify:\n");
					scanf("%d",&choice);
					switch(choice)
					{
					case 1:
						printf("Please enter your modified name:");
						scanf("%s",&name5);
						strcpy(customer[k]->name,name5);
						//customer[i]->name=name5;
						break;
					case 2:
						printf("Please enter the modified gender:");
						scanf("%s",&sex5);
						strcpy(customer[k]->sex,sex5);
						break;
					case 3:
						printf("Please enter the modified ID number:");
						scanf("%s",&ID5);
						strcpy(customer[k]->ID,ID5);
						break;
					case 4:
						printf("Please enter the modified origin:");
						scanf("%s",&addr5);
						strcpy(customer[k]->addr,addr5);
						break;
					}
					printf("Successful modification!");
			}
			else
			{
				printf("Input Error!");
				return ;
			}
	}
}

Tags: data structure Algorithm C Visual Studio Code

Posted by bagsobrands on Fri, 16 Jul 2021 03:29:57 +0930