⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 函数模块化 旅馆管理系统 未抄288.cpp

📁 我正在学习C编程
💻 CPP
字号:
#include<stdio.h>   /**/
#include<math.h>  //导入包含数学类库函数的头文件math.h

int showMenu();                   //声明显示菜单函数
int checkMenu();                  //声明核对菜单函数
void standardroom();              //声明标准房函数
void personalroom();              //声明单人房函数
void sumptuousroom();             //声明豪华房函数
void tf1(int days,int roomgrade); //声明标准房退房函数
void tf2(int days,int roomgrade); //声明单人间退房函数
void tf3(int days,int roomgrade); //声明豪华房退房函数
void quit();                      //声明退房函数


void main()                       //主函数
{
	printf("\n\t\t函数调用━━━━结构化编程:\n\n  一个函数实现一个功能,调用不同函数实现不同功能:\n");
	printf("───────────────────────────────────────\n");
	int userselect;               //定义"用户选择"变量
	printf("\n\t\t\t◆  欢迎光临XXXX旅馆  ◆\n\n");
	while(1)
	{
		userselect=showMenu();                          //调用showMenu()函数,用户输入选项编号
		if(userselect==1){standardroom();}              //调用标准房函数
		else if(userselect==2){personalroom();}         //调用单人间函数
			 else if(userselect==3){sumptuousroom();}   //调用豪华间函数
				  else if(userselect==4){quit();break;} //调用退房函数
					   else if(userselect==5){break;}
							else {printf("  请选择1~5之间的选项!\n"); continue;}
		printf("\n  欲入住吗?是则回车,否则输入‘空格’回车 ");
		getchar();
		if(getchar()==' '){break;}
		else {while(getchar()!='\n'){;}}
	}
}

int showMenu()    //定义显示菜单函数,返回整型值,无参数
{
	int select;   //定义"用户选择"变量

	printf("  本旅馆客房分③个等级: \n");
	printf("\t①标准房     ②单人间     ③豪华间     4)退房     5)退出系统\n"); 
	printf("\n  请客人输入希望入住的房间等级(1~3): ");
	scanf("%d",&select);
	return select;
}
int checkMenu(int select,int min,int max)    //定义核对菜单函数(多余?????没用上?),返回整型值,整型形参
{
	if(select<=max && select>=min){return 1;}//如选项编号在最小编号~最大编号之间,返回真1
	else {return 0;}                         //否则,选项编号在最小编号~最大编号之外,返回假0
}

void standardroom()                          //定义标准房函数
{
	printf("\n  ━━━━━━━◆ 标准房:日租金20元.请预付押金200元 ◆━━━━━━━\n");
}
void personalroom()                          //定义单人间函数
{
	printf("\n  ━━━━━━━▲ 单人间:日租金30元.请预付押金300元 ▲━━━━━━━\n");
}
void sumptuousroom()                         //定义豪华间函数
{
	printf("\n  ━━━━━━━★ 豪华间:日租金50元.请预付押金500元 ★━━━━━━━\n");
}
void tf1(int days,int roomgrade)             //定义标准房退房函数
{
	float x;   x=20*days-200;                //计算房租余额
	if(x<0){printf("  客人预付押金200元,应退还客人%.2f元\n",fabs(x));}
	else if(x==0){printf("  客人预付押金200元,刚好用完,余额0元\n");}
		 else if(x>0){printf("  客人预付押金200元,应补交房租%.2f元\n",fabs(x));}
}
void tf2(int days,int roomgrade)             //定义单人间退房函数
{
	float x;   x=30*days-300;                //计算房租余额
	if(x<0){printf("  客人预付押金300元,应退还客人%.2f元\n",fabs(x));}
	else if(x==0){printf("  客人预付押金300元,刚好用完,余额0元\n");}
		 else if(x>0){printf("  客人预付押金300元,应补交房租%.2f元\n",fabs(x));}
}
void tf3(int days,int roomgrade)             //定义豪华间退房函数
{
	float x;   x=50*days-500;                //计算房租余额
	if(x<0){printf("  客人预付押金500元,应退还客人%.2f元\n",fabs(x));}
	else if(x==0){printf("  客人预付押金500元,刚好用完,余额0元\n");}
		 else if(x>0){printf("  客人预付押金500元,应补交房租%.2f元\n",fabs(x));}
}
void quit()                                  //定义退房函数
{
	while(1)
	{
		int days,roomgrade; 
		printf("\n  请输入客人已入住总天数(总天数<=0时退出系统): ");   scanf("%d",&days);
		if(days<=0){break;}
		printf("  请输入客人入住的房间等级(1~3):  ");   
		printf("\n\t①标准房\t②单人间\t③豪华间\t4)退出系统\n"); 
		scanf("%d",&roomgrade);
		switch(roomgrade)
		{
			case 1:tf1(days,roomgrade);break; //调用标准房退房函数
			case 2:tf2(days,roomgrade);break; //调用单人间退房函数
			case 3:tf3(days,roomgrade);break; //调用豪华间退房函数
			case 4:goto end;
			default:printf("  请输入正确的房间等级(1~3)!\n");
		}
	}
	end:;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -