-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hotel.cpp
86 lines (68 loc) · 2.06 KB
/
Hotel.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
#include "Hotel.h" //les bibliothèques <vector>,<string>,"Chambre" sont incluses dans "Hotel.h"
#include <iostream>
Hotel::Hotel():m_id(identifiant_auto_str()){
}
Hotel::Hotel(std::string nom, std::string ville, std::vector<Chambre> chambre):
m_nom(nom),
m_ville(ville),
m_chambres(chambre),
m_id(identifiant_auto_str()){
}
std::string Hotel::getId() const{
return m_id;
}
std::string Hotel::getNom() const{
return m_nom;
}
std::string Hotel::getVille() const{
return m_ville;
}
std::vector<Chambre> Hotel::getChambre() const{
return m_chambres;
}
void Hotel::setId(std::string id){
m_id = id;
}
void Hotel::setNom(std::string nom){
m_nom = nom;
}
void Hotel::setVille(std::string ville){
m_ville = ville;
}
void Hotel::setChambre(std::vector<Chambre> chambre){
for (long unsigned int i=0; i<chambre.size(); i++)
m_chambres.push_back(chambre[i]);
}
void Hotel::addChambre(Chambre chambre){
m_chambres.push_back(chambre);
}
void Hotel::addNChambres(){
long unsigned int N;
std::cout << "Entrer le nombre de chambres: "<< std::endl;
std::cin >> N;
Chambre chambre;
for(long unsigned int i=0; i<N; i++){
chambre.saisieClavier(); //Saisir les informations de la chambre à partir du clavier
addChambre(chambre); // équivalent à: m_chambres.push_back(chambre);
}
}
//On utilisera les setters dans cette fonction afin d'afficher toutes ses infos
void Hotel::affichage() const{
long unsigned int j;
std::cout << "------------ L'Hotel: ------------"<< std::endl;
std::cout << "------------\t"<< getNom()<<"\t------------"<< std::endl;
std::cout << "\t ID: " << getId()<< std::endl;
std::cout << "\t Ville: "<< getVille() << std::endl;
std::cout << "\t Liste des chambres de l'hotel: " << std::endl;
j=0;
for(Chambre& i:getChambre() ){ //passage par référence afin d'éviter de copier
std::cout << "---- Chambre "<<j+1<<" -----\n";
i.affichage(); // affichage() est une méthode de la classe Chambre
std::cout <<"\n";
j++;
}
}
std::string Hotel::identifiant_auto_str(){
static int index=0;
index++;
return getNom() + std::to_string(index-1);}