-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainf.cpp
More file actions
136 lines (119 loc) · 3.59 KB
/
mainf.cpp
File metadata and controls
136 lines (119 loc) · 3.59 KB
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
#include "mammoth.cpp"
void calling(const unsigned opcao, vecVeh &vehtor) {
typedef void (*action)(vecVeh &);
const action actions[] = {
&createCar, ©ExtCar, &deleteCar, &getStatus, &tiraTeima,
&setInterns, &setTurbos, &setIntake, &setExaust, &setECUnit,
&setTransm, &setSuspens, &setChassis, &exitProgram
};
(*actions[opcao])(vehtor);
}
void createCar(vecVeh &vehtor) {
unsigned type;
system("cls||clear");
while (1) {
string input;
cout << "1 - O novo veiculo e uma F150\n"
<< "2 - O novo veiculo e uma Mammoth\n"
<< "3 - O novo veiculo e uma Corvette\n"
<< "4 - O novo veiculo e uma 911 GT2\n"
<< "5 - O novo veiculo e um Carro\n"
<< "Qual tipo de veiculo voce quer? ";
getline(cin, input);
stringstream stream(input);
if (stream >> type &&
Vehicle::verCreate(type)) break;
system("cls||clear");
cout << "Digite um dos tipos especificados!\n";
}
vehtor.push_back(Vehicle::create(type));
system("cls||clear");
cout << "Carro adicionado com sucesso!\n";
}
void copyExtCar(vecVeh &vehtor) {
if (notexts("copiar", vehtor)) return;
const unsigned escolha = getEscolha(vehtor);
vehtor.push_back(vehtor[escolha]->clone());
system("cls||clear");
cout << "Carro adicionado com sucesso!\n";
}
void deleteCar(vecVeh &vehtor) {
if (notexts("deletar", vehtor)) return;
const unsigned escolha = getEscolha(vehtor);
delete vehtor[escolha];
vehtor.erase(vehtor.begin() + escolha);
system("cls||clear");
cout << "Carro deletado com sucesso!\n";
}
void getStatus(vecVeh &vehtor) {
if (notexts("mostrar", vehtor)) return;
const unsigned escolha = getEscolha(vehtor);
system("cls||clear");
cout << *vehtor[escolha];
}
void tiraTeima(vecVeh &vehtor) {
if (notexts("tirar-teima", vehtor)) return;
vehtor[getEscolha(vehtor)]->tiraTeima();
}
void setInterns(vecVeh &vehtor) {
if (notexts("modificar", vehtor)) return;
vehtor[getEscolha(vehtor)]->setInterns();
}
void setTurbos(vecVeh &vehtor) {
if (notexts("modificar", vehtor)) return;
vehtor[getEscolha(vehtor)]->setTurbos();
}
void setIntake(vecVeh &vehtor) {
if (notexts("modificar", vehtor)) return;
vehtor[getEscolha(vehtor)]->setIntake();
}
void setExaust(vecVeh &vehtor) {
if (notexts("modificar", vehtor)) return;
vehtor[getEscolha(vehtor)]->setExaust();
}
void setECUnit(vecVeh &vehtor) {
if (notexts("modificar", vehtor)) return;
vehtor[getEscolha(vehtor)]->setECUnit();
}
void setTransm(vecVeh &vehtor) {
if (notexts("modificar", vehtor)) return;
vehtor[getEscolha(vehtor)]->setTransm();
}
void setSuspens(vecVeh &vehtor) {
if (notexts("modificar", vehtor)) return;
vehtor[getEscolha(vehtor)]->setSuspens();
}
void setChassis(vecVeh &vehtor) {
if (notexts("modificar", vehtor)) return;
vehtor[getEscolha(vehtor)]->setChassis();
}
void exitProgram(vecVeh &vehtor) {
for (Vehicle *elem : vehtor) delete elem;
vehtor.~vector();
system("clear||cls");
cout << "Ate a proxima vez!\n";
exit(0);
}
const unsigned getEscolha(vecVeh &vehtor) {
system("cls||clear");
while (1) {
string input; unsigned escolha, i = 0;
for (Vehicle *elem : vehtor)
cout << i++ << " - " << elem << "\n";
cout << "Qual opcao voce escolhe? ";
getline(cin, input);
stringstream stream(input);
if (stream >> escolha &&
escolha < vehtor.size()) return escolha;
system("cls||clear");
cout << "Digite um veiculo especificado!\n";
}
}
const bool notexts(const char *action, vecVeh &vehtor) {
if (!vehtor.size()) {
system("cls||clear");
cout << "Nao ha carros para " << action << "!\n";
return 1;
}
return 0;
}