-
Notifications
You must be signed in to change notification settings - Fork 0
/
terrains.cpp
156 lines (132 loc) · 4.61 KB
/
terrains.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
152
153
154
155
156
#include "terrains.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Constructor with type, length, and width
Terrain::Terrain(TypeTerrain type, int longueur, int largeur)
: type(type), longueur(longueur), largeur(largeur), nbPlacesReservees(0) {
initializeSeatingPlan(longueur, largeur); // Initialize seating plan based on terrain size
}
// Constructor with type, length, width, and reserved seats
Terrain::Terrain(TypeTerrain type, int longueur, int largeur, int nbPlacesReservees)
: type(type), longueur(longueur), largeur(largeur), nbPlacesReservees(nbPlacesReservees) {
initializeSeatingPlan(longueur, largeur); // Initialize seating plan based on terrain size
}
// Getter for type
TypeTerrain Terrain::getType() const {
return type;
}
// Getter for length
int Terrain::getLongueur() const {
return longueur;
}
// Getter for width
int Terrain::getLargeur() const {
return largeur;
}
// Getter for reserved seats
int Terrain::getNbPlacesReservees() const {
return nbPlacesReservees;
}
// Setter for length
void Terrain::setLongueur(int longueur) {
this->longueur = longueur;
initializeSeatingPlan(this->longueur, this->largeur); // Reinitialize seating plan
}
// Setter for width
void Terrain::setLargeur(int largeur) {
this->largeur = largeur;
initializeSeatingPlan(this->longueur, this->largeur); // Reinitialize seating plan
}
// Setter for reserved seats
void Terrain::setNbPlacesReservees(int nbPlacesReservees) {
this->nbPlacesReservees = nbPlacesReservees;
}
// Setter for all attributes except reserved seats
void Terrain::setTerrain(TypeTerrain type, int longueur, int largeur) {
this->type = type;
this->longueur = longueur;
this->largeur = largeur;
initializeSeatingPlan(longueur, largeur); // Reinitialize seating plan
}
// Setter for all attributes including reserved seats
void Terrain::setTerrain(TypeTerrain type, int longueur, int largeur, int nbPlacesReservees) {
this->type = type;
this->longueur = longueur;
this->largeur = largeur;
this->nbPlacesReservees = nbPlacesReservees;
initializeSeatingPlan(longueur, largeur); // Reinitialize seating plan
}
// Display terrain details
void Terrain::afficher() const {
cout << "Type de terrain: " << (type == DUR ? "Dur" : (type == TERRE_BATTUE ? "Terre battue" : "Gazon")) << endl;
cout << "Longueur: " << longueur << endl;
cout << "Largeur: " << largeur << endl;
cout << "Nombre de places réservées: " << nbPlacesReservees << endl;
}
#include "terrains.h"
#include <iostream>
Terrain::Terrain(TypeTerrain type, int longueur, int largeur)
: type(type), longueur(longueur), largeur(largeur) {}
void Terrain::initializeSeatingPlan(int rows, int cols) {
seatingPlan.resize(rows);
for (int i = 0; i < rows; ++i) {
seatingPlan[i].resize(cols, '.'); // Initialize with '.' for available seats
}
}
bool Terrain::isSeatAvailable(int row, int col) {
if (row < 0 || row >= seatingPlan.size() || col < 0 || col >= seatingPlan[0].size()) {
return false;
}
return seatingPlan[row][col] == '.'; // Check for '.' to indicate available
}
void Terrain::reserveSeat(int row, int col) {
if (isSeatAvailable(row, col)) {
seatingPlan[row][col] = 'X'; // Mark as reserved
}
}
void Terrain::releaseSeat(int row, int col) {
if (!isSeatAvailable(row, col)) {
seatingPlan[row][col] = '.'; // Mark as available
}
}
void Terrain::afficherSeatingPlan() const {
for (const auto& row : seatingPlan) {
for (char seat : row) {
cout << seat << " ";
}
cout << endl;
}
}
// GestionTerrains methods
// Add a terrain
void GestionTerrains::ajouterTerrain(Terrain terrain) {
terrains.push_back(terrain);
}
// Display all terrains
void GestionTerrains::afficherTerrains() {
for (const Terrain& terrain : terrains) {
terrain.afficher();
cout << endl;
}
}
// Remove a terrain
bool GestionTerrains::supprimerTerrain(TypeTerrain type, int longueur, int largeur) {
for (auto it = terrains.begin(); it != terrains.end(); ++it) {
if (it->getType() == type && it->getLongueur() == longueur && it->getLargeur() == largeur) {
terrains.erase(it);
return true; // Terrain found and deleted
}
}
return false; // Terrain not found
}
// Search for a terrain
Terrain* GestionTerrains::rechercherTerrain(TypeTerrain type, int longueur, int largeur) const {
for (const auto& terrain : terrains) {
if (terrain.getType() == type && terrain.getLongueur() == longueur && terrain.getLargeur() == largeur) {
return const_cast<Terrain*>(&terrain);
}
}
return nullptr;
}