宾馆房间客人类
#include<bits/stdc++.h>
using namespace std;
class HotelRoom{
private:
static int totalRooms;
int id;
string guestname;
public:
HotelRoom(int id, const string& guest):id(id),guestname(guest){
totalRooms++;
}
static int getTotalRooms(){
return totalRooms;
}
void showInfo() const{
cout<<"房间号:"<<id<<", 入住客人:"<<guestname<<endl;
}
~HotelRoom(){
totalRooms--;
}
};
int HotelRoom::totalRooms = 0;
int main(){
{
HotelRoom room1(101,"Taylor");
HotelRoom room2(212,"Ryan");
room1.showInfo();
room2.showInfo();
cout << "当前订房数: " << HotelRoom::getTotalRooms() << endl;
}
cout << "当前订房数: " << HotelRoom::getTotalRooms() << endl;
return 0;
}