📄 room.cpp
字号:
#include "room.h"
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
room::room(int g, int b)
{
grade = g;
bedNumber = b;
customerNumber = 0;
ptrCustomer = new customer[b];
}
void room::setBedNumber(int b)
{
bedNumber = b;
delete []ptrCustomer;
ptrCustomer = new customer[b];
customerNumber = 0;
}
bool room::addCustomer(customer newCustomer)
{
ptrCustomer[customerNumber] = newCustomer;
customerNumber++;
return true;
}
bool room::canLiveIn(customer newCustomer)
{
if (!customerNumber)
return true;
if (customerNumber == bedNumber)
return false;
if (newCustomer.getCustomerSex() ==
ptrCustomer[0].getCustomerSex())
return true;
else
return false;
}
bool room::IDFindCustomer(string tmpID, customer &tmpCustomer)
{
int i;
for (i = 0; i < customerNumber; i++)
{
if (ptrCustomer[i].getCustomerID() == tmpID)
{
tmpCustomer = ptrCustomer[i];
return true;
}
}
return false;
}
bool room::delCustomer(string tmpID, customer &tmpCustomer)
{
int i, j;
for (i = 0; i < customerNumber; i++)
{
if (ptrCustomer[i].getCustomerID() == tmpID)
{
tmpCustomer = ptrCustomer[i];
for (j = i; j < customerNumber - 1; j++)
ptrCustomer[j] = ptrCustomer[j + 1];
customerNumber--;
return true;
}
}
return false;
}
bool room::nameFindCustomer(string tmpName, customer *ptrFindCustomer,
int &customerNum)
{
int i;
bool res = false;
for (i = 0; i < customerNumber; i++)
{
if (ptrCustomer[i].getCustomerName() == tmpName)
{
ptrFindCustomer[customerNum] = ptrCustomer[i];
customerNum++;
res = true;
}
}
return res;
}
void room::displayRoom()
{
int i, j;
for (i = 0; i < 20; i++)
cout << ' ';
cout << "房号为 " << (grade + 1) * 1000 + roomNumber + 1
<< "的房间住宿情况如下:\n\n";
for (i = 0; i < 20; i++)
cout << ' ';
cout << "此房间, 共有床位 " << bedNumber
<< "张. 已有房客" << customerNumber << "位\n\n";
for (i = 0; i < 20; i++)
cout << ' ';
cout << "房客 姓名\t性别\t入住时间\n\n";
for (j = 0; j < customerNumber; j++)
{
for (i = 0; i < 20; i++)
cout << ' ';
cout << " " << j + 1 << "\t" << ptrCustomer[j].getCustomerName()
<< " ";
if (ptrCustomer[j].getCustomerSex() == true)
cout << "男\t";
else
cout << "女\t";
Time tmpTime = ptrCustomer[j].getArriveTime();
tmpTime.display();
cout << "\n\n";
}
}
void room::outToFile(fstream &fp1)
{
int i;
for (i = 0; i < customerNumber; i++)
{
fp1 << ptrCustomer[i].getCustomerName() << ' ' << ptrCustomer[i].getCustomerSex()
<< ' ' << (grade + 1) * 1000 + roomNumber + 1 << ' '
<< ptrCustomer[i].getCustomerID() << ' ';
Time &tmpTime = ptrCustomer[i].getArriveTime();
fp1 << setw(2) << setfill('0') << tmpTime.getYear() << '/' << tmpTime.getMonth()
<< '/' << tmpTime.getDay() << ' ' << tmpTime.getHour() << ':' << tmpTime.getMinute()
<< endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -