-
Notifications
You must be signed in to change notification settings - Fork 0
/
Facture_TP2_Maher.cpp
151 lines (134 loc) · 4.11 KB
/
Facture_TP2_Maher.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <iostream>
using namespace std;
class ElementFacturable {
virtual int calculateTaxes(int numNights, int meals) = 0;
virtual int calculateTaxes(bool spa, bool gym) = 0;
};
class FacturableParUnite: public ElementFacturable {
public:
int calculateTaxes(int numNights, int meals) {
int tax = 0;
tax = (numNights * 100 * 13 / 100) + (meals * 20 * 13 / 100);
return tax;
}
int calculateTaxes(bool spa, bool gym) {
return 0;
}
};
class FacturableFraisFixe: public ElementFacturable {
public:
int calculateTaxes(bool spa, bool gym) {
int tax = 0;
if(spa == true) {
tax += (75 * 15 / 100);
}
if(gym == true) {
tax += (50 * 15 / 100);
}
return tax;
}
int calculateTaxes(int numNights, int meals) {
int tax = 0;
return tax;
}
};
class App {
int numNights;
int meals;
bool spa;
bool gym;
public:
void displayMenu() {
cout << "\n";
cout << "1. Ajouter des nuitées\n";
cout << "2. Ajouter des repas\n";
cout << "3. Ajouter un accès au spa\n";
cout << "4. Ajouter un accès au gym\n";
cout << "5. Afficher la facture et quitter\n";
cout << "Faites votre choix: \n";
cout << "\n";
}
void processChoice(int choice) {
int tmpNumMeals = 0;
int tmpNumNights = 0;
switch(choice) {
case 1:
if(numNights > 0) {
throw std::invalid_argument("Nuits déjà ajoutées à la facture");
} else {
cin >> tmpNumNights;
if(tmpNumNights <= 0) {
throw std::invalid_argument("La valeur d’entrée doit être supérieure à 0");
} else {
numNights = tmpNumNights;
}
}
break;
case 2:
cin >> tmpNumMeals;
if(tmpNumMeals <= 0) {
throw std::invalid_argument("La valeur d’entrée doit être supérieure à 0");
} else {
meals = tmpNumMeals;
}
break;
case 3:
if(spa == false) {
spa = true;
} else {
throw std::invalid_argument("Accès au spa déjà ajouté à la facture");
}
break;
case 4:
if(gym == false) {
gym = true;
} else {
throw std::invalid_argument("Accès au gymnase déjà ajouté à la facture");
}
break;
case 5:
break;
default:
cout << "Choix Invalid \n";
}
}
public:
void runProg() {
int choice = 0;
while(choice != 5) {
try {
displayMenu();
cin >> choice;
processChoice(choice);
}
catch(const std::invalid_argument& e) {
cout << e.what() << endl;
}
}
int tax = 0;
FacturableParUnite parUnit;
tax += parUnit.calculateTaxes(numNights, meals);
FacturableFraisFixe fixed;
tax += parUnit.calculateTaxes(spa, gym);
cout << "Total Nuitées: " << numNights << endl;
cout << "Total Repas: " << meals << endl;
cout << "Acces au Spa: " << spa << endl;
cout << "Access au Gym: " << gym << endl;
cout << "Taxes: " << tax << endl;
int total = numNights * 100 + meals * 20;
if(spa == true) {
total += 75;
}
if(gym == true) {
total += 50;
}
total += tax;
cout << "Total: " << total;
}
};
int main()
{
App obj;
obj.runProg();
return 0;
}