-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuilding.cpp
106 lines (98 loc) · 2.64 KB
/
Building.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// Created by cartofiprajiti on 13.04.2023.
//
#include <memory>
#include "Building.h"
#include "Room.h"
#include "Office.h"
#include "LivingRoom.h"
#include "Bedroom.h"
#include "Toilet.h"
#include "Kitchen.h"
using namespace std;
Building::Building(){
nrrooms = 0;
nrBuildings++;
}
Building::~Building() = default;
void Building::readRoomOpt() const{
cout<<"Choose an option:\n"
"1) Office\n"
"2) Living Room\n"
"3) Bedroom\n"
"4) Toilet\n"
"5) Kitchen\n";
}
void Building::read(const shared_ptr<Building>& this1) {
cout<<"Name: "; getline(cin, name);
cout<<"Adress: "; getline(cin, adress);
cout<<"Area in meters square: "; cin>>area;
int nrfloors;
cout<<"Number of floors: "; cin>>nrfloors;
for(int i=0; i<nrfloors; i++){
std::cout<<"\n";
floors.emplace_back();
int nr;
cout<<"Number of rooms on the floor "<<i+1<<": "; cin>>nr;
nrrooms += nr;
for(int j=0; j<nr; j++) {
cout<<"\nRoom "<<j+1<<":\n";
int opt;
readRoomOpt();
cin>>opt;
shared_ptr<Room> q;
switch(opt) {
case 1: {
q = make_shared<Office>();
break;
}
case 2: {
q = make_shared<LivingRoom>();
break;
}
case 3: {
q = make_shared<Bedroom>();
break;
}
case 4: {
q = make_shared<Toilet>();
break;
}
case 5: {
q = make_shared<Kitchen>();
break;
}
default:
throw NotAValidRoom();
}
q->setBuilding(this1);
floors[i].push_back(q);
q->setRnumber(j+1);
q->read();
}
}
cout<<"\nNumber of parking lots: "; cin>>nrParkingLots;
cin.get();
}
void Building::print() const{
cout<<"Name: "<<name<<"\n";
cout<<"Area: "<<area<<"\n";
cout<<"Adress: "<<adress<<"\n";
cout<<"Number of rooms: "<<nrrooms<<"\n";
cout<<"Number of parking lots: "<<nrParkingLots<<"\n\n";
int i = 1;
for(const auto& floor: floors) {
cout<<"Floor "<<i++<<"\n\n";
for (const auto& room: floor)
room->print(), cout<<"\n";
}
}
int Building::getNrBuildings(){
return nrBuildings;
}
void Building::readBuildingOpt() {
cout<<"Choose an option:\n"
"1) House\n"
"2) Institution\n"
"3) Residence Hall\n";
}