-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPays.cpp
More file actions
114 lines (109 loc) · 2.57 KB
/
Pays.cpp
File metadata and controls
114 lines (109 loc) · 2.57 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
#include <iostream>
#include <string>
#include <list>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <map>
#include <cassert>
#include <sstream>
#include <QMessageBox>
#include "Pays.hh"
#include "Parti.hh"
///////////////////////////////////////////////////////////////////////////////
std::string Pays::creer_nom()
{
int i = 0;
int nbLignes = 0;
std::string ligne;
std::string contenu = "!";
std::ifstream fichier("nom_pays.txt", std::ios::in);
if(fichier)
{
while(std::getline(fichier, ligne)){
nbLignes++;
}
//retour debut fichier
fichier.clear();
fichier.seekg(0,std::ios::beg);
// Affiche nom aléatoire
int n = rand()%(nbLignes) +1;
while(i < n){
std::getline(fichier, contenu);
i++;
}
fichier.close();
}else
{
//printf("ERROR le fichier de nom n'existe pas!!!\n");
QMessageBox::information(0,"ERREUR","le fichier de nom n'existe pas!!!");
exit(-1);
}
return contenu;
}
///////////////////////////////////////////////////////////////////////////////
std::map<Parti, int> Pays::creer_partis(int n)
{
assert(n>0);
std::map<Parti,int> partis;
while(partis.size() < (unsigned)n)
{
partis.insert(std::make_pair(Parti(), rand()%10000+10000));
}
return partis;
}
///////////////////////////////////////////////////////////////////////////////
Pays::Pays(int n)
:_nom(creer_nom())
,_partis(creer_partis(n))
{
_nbHab=0;
for(const auto& iter : _partis)
{
_nbHab+= iter.second;
}
}
///////////////////////////////////////////////////////////////////////////////
bool Pays::operator<(const Pays & p) const
{
return this->_nom < p._nom;
}
///////////////////////////////////////////////////////////////////////////////
void Pays::sondage()
{
return;
}
///////////////////////////////////////////////////////////////////////////////
std::string Pays::display() const
{
std::ostringstream oss;
oss << std::endl;
oss << "Pays : " << this->_nom << std::endl;
oss << "Nombre d'habitants : " << this->_nbHab << std::endl;
for(const auto& it : _partis)
{
oss <<it.first.display();
oss << "Nombre d'adherants : " << it.second << std::endl;
}
oss << std::endl;
return oss.str();
}
std::string Pays::get_nom()const
{
return this->_nom;
}
std::string Pays::get_basic()const
{
return "";
}
int Pays::get_nbhab()
{
return this->_nbHab;
}
std::map<Parti, int> Pays::get_partis() const
{
return this->_partis;
}
Pays::~Pays()
{
}