题目:**
设计两个酒店管理员客房管理的类:一个是Person类,要求储存房号、客户姓名和身份证号的信息;另一个类是Client类,要求新增客户的订房、退房和消费金额等信息,并给出相关测试算法。
**
编程要求:
(1)具有订房功能:增添客户的信息到相应的房号。包括姓名、身份证号码、开房时间,预计订房的时间;
(2)具有退房功能:计算客户的消费时间以及其他的消费项目(如订餐服务),结算客户的消费金额;删除相应房号内的客户信息。
(3)输入有效性验证,假设酒店客房有一百间。
#include <iostream>
using std::cout, std::cin, std::endl;
//Person类用于存储客户姓名,身份证号,房号
class Person{
long long roomNumber, Idcard;
char name[21];
public:
void create(int i);
};
//Client用于存储客户订房,退房,房费
class Client{
double monetary = 0, StayTime;
char order;//判断是否订餐
bool Order = 0;
public:
void roomMassage(int); //记录房间消费信息
double Money(); //计算消费金额
};
void Person::create(int i){
cout << "Please send the name and IDcard:\n";
scanf("%s",name);
cin >> Idcard;
roomNumber = i+1;
}
void Client::roomMassage(int i){
cout << "How long do you want to make a reservation?(200RMB each day)\n";
cin >> StayTime;
cin.ignore();
cout << "Do you want to make a order of food?(50RMB each day)(Y/N)\n";
char order;
cin >> order;
if (order == 'Y') Order = 1;
}
double Client::Money(){
monetary = StayTime * 200;
if(Order != 0) monetary += StayTime * 50;
return monetary;
}
int main(void) {
int n;
cout << "How many rooms do you want to book?(One room for one person)" << endl;
cin >> n;
if(n > 100 || n <= 0) { cout << "Error!\n"; exit(0);} //只有一百间房
Person *p1 = new Person[n];//看我的魔幻操作
//新建房客
for(int i = 0; i < n; i++){
(*(p1+i)).create(i);
}
Client *p2 = new Client[n];
for(int i = 0; i < n; i++){
(*(p2+i)).roomMassage(i);
}
//判断是否退房
bool flag = 0;
char Flag;
cout << "Do you want to check out?(Y/N)";
cin >> Flag;
if(Flag == 'Y') flag = 1;
double total = 0; // total是全部费用
if(!flag){
int i = 0;
for(i = 0; i < n; i++){
total += (*(p2+i)).Money();
}
cout << "您一共消费 " << total <<" 元."<< endl <<"感谢您的入住!\n" << "期待您的下次光临!\n ";
}
//释放空间
delete []p1;
delete []p2;
return 0;
}
这个代码还是存在一些问题,比如不能全部实现题目要求,欢迎大家在评论区和我交流~