-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
186 lines (127 loc) · 5.42 KB
/
main.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <iostream>
#include <string>
#include <stdexcept>
#include <fstream>
#include "Competicao.h"
#include "Equipe.h"
#include "Modalidade.h"
#include "Competicao.h"
#include "CompeticaoSimples.h"
#include "CompeticaoMultimodalidades.h"
#include "PersistenciaDeCompeticao.h"
using namespace std;
int main()
{
try {
string sn, nomeCompeticao, sm;
cout << "Deseja carregar uma competicao (s/n)? ";
cin >> sn;
if(sn == "n") {
int quantidadeEquipes;
cout << endl;
cout << "Informe a quantidade de equipes: ";
cin >> quantidadeEquipes;
Equipe** equipes = new Equipe*[quantidadeEquipes]; //TODAS AS EQUIPES PARTICIPANTES DA COMPETICAO
for(int i = 0; i < quantidadeEquipes; i++) {
string nomeEquipe;
cout << "Informe o nome da equipe " << i+1 <<": ";
cin >> nomeEquipe;
equipes[i] = new Equipe(nomeEquipe);
}
cout << endl;
cout << "Informe o nome da competicao: ";
cin >> nomeCompeticao;
cout << "Competicao simples (s) ou multimodalidades (m): ";
cin >> sm;
cout << endl;
if(sm == "s") { //COMPETICAO SIMPLES
string nomeModalidade;
cout << "Informe o nome da modalidade: ";
cin >> nomeModalidade;
Modalidade* modalidade = new Modalidade(nomeModalidade, equipes, quantidadeEquipes);
cout << "Tem resultado (s/n): ";
cin >> sn;
if(sn == "s") {
Equipe** participantesModalidade = new Equipe*[quantidadeEquipes];
for(int i = 0; i < quantidadeEquipes; i++) {
int colocada;
cout << "Informe a equipe " << i+1 <<"a colocada: ";
cin >> colocada;
participantesModalidade[i] = equipes[colocada-1];
}
modalidade->setResultado(participantesModalidade);
}
cout << endl;
CompeticaoSimples* competicaoSimples = new CompeticaoSimples(nomeCompeticao, equipes, quantidadeEquipes, modalidade);
cout << "Deseja salvar a competicao (s/n)? ";
cin >> sn;
if(sn == "s") {
string nomeArquivo;
cout << "Digite o nome do arquivo: ";
cin >> nomeArquivo;
cout << endl;
PersistenciaDeCompeticao* persistencia = new PersistenciaDeCompeticao();
persistencia->salvar(nomeArquivo, competicaoSimples);
}
cout << endl;
competicaoSimples->imprimir();
}
if(sm == "m") { //COMPETICAO MULTIMODALIDADES
int quantidadeModalidades;
cout << "Informe a quantidade de modalidades: ";
cin >> quantidadeModalidades;
CompeticaoMultimodalidades* competicaoMulti = new CompeticaoMultimodalidades(nomeCompeticao, equipes, quantidadeEquipes);
for(int i = 0; i < quantidadeModalidades; i++) {
string nomeModalidade;
cout << "Informe o nome da modalidade " << i+1 << ": ";
cin >> nomeModalidade;
cout << "Tem resultado (s/n): ";
cin >> sn;
Modalidade* modalidade = new Modalidade(nomeModalidade, equipes, quantidadeEquipes);
if(sn == "s") {
Equipe** participantesModalidade = new Equipe*[quantidadeEquipes];
for(int j = 0; j < quantidadeEquipes; j++) {
int colocada;
cout << "Informe a equipe " << j+1 <<"a colocada: ";
cin >> colocada;
participantesModalidade[j] = equipes[colocada-1];
}
modalidade->setResultado(participantesModalidade);
}
competicaoMulti->adicionar(modalidade);
cout << endl;
}
cout << "Deseja salvar a competicao (s/n)? ";
cin >> sn;
cout << endl;
if(sn == "s") {
string nomeArquivo;
cout << "Digite o nome do arquivo: ";
cin >> nomeArquivo;
cout << endl;
PersistenciaDeCompeticao* persistencia = new PersistenciaDeCompeticao();
persistencia->salvar(nomeArquivo, competicaoMulti);
}
competicaoMulti->imprimir();
}
}
else {
string nomeArquivo;
cout << "Digite o nome do arquivo: ";
cin >> nomeArquivo;
cout << endl;
PersistenciaDeCompeticao* persistente = new PersistenciaDeCompeticao();
Competicao* competicaoSM = persistente->carregar(nomeArquivo);
competicaoSM->imprimir();
}
return 0;
}
catch (invalid_argument* e) {
cout << "Erro: " << e->what();
delete e;
}
catch (logic_error* e) {
cout << "Erro: " << e->what();
delete e;
}
}