Dev - C++ - sobre las elecciones

 
Vista:

sobre las elecciones

Publicado por diana (1 intervención) el 01/06/2018 00:19:21
hola,necesito un programa en c++ sobre las elecciones,como por ejemplo cuantas personas votaron por el candidato o cuantos votos tiene cada uno, o si eres apto para votar.
POR FAVOR AYUDENME ME HARIAN DE GRAN UTILIDAD.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Rojas

sobre las elecciones

Publicado por Rojas (5 intervenciones) el 02/06/2018 03:10:15
Hola, yo la verdad soy novata, pero hace poco hice un codigo parecido a esto que pides, te lo dejo, espero te funcione.
Eso sí te advierto que tiene sus errores:
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include<iostream>
#include"Coleccion.h"
using namespace std;
 
int main (int argc, char *argv[]) {
	int c;
	int t;
 
	Coleccion ELECCION_PROCESO1_2018;
	cout<<"Cuantos candidatos participan en estas eleciones? ";
	cin>>c;
	ELECCION_PROCESO1_2018.setCantidad(c);
	cout<<endl<<"Cuantos electores iran a votar en estas eleciones? ";
	cin>>t;
	ELECCION_PROCESO1_2018.setTotalElectores(t);
	cout<<endl<<"Los votos fueron: "<<endl;
	ELECCION_PROCESO1_2018.NumerosRand(t);
	cout<<endl;
	cout<<ELECCION_PROCESO1_2018.toString()<<endl;
	cout<<"El candidato en la posicion "<<ELECCION_PROCESO1_2018.mayorVotos()<<" obtuvo el mayor numero de votos."<<endl<<endl;
	ELECCION_PROCESO1_2018.igualar(); ELECCION_PROCESO1_2018.ordenaAscendente();
	cout<<ELECCION_PROCESO1_2018.toStringOrdenado()<<endl;
	cout<<ELECCION_PROCESO1_2018.toStringMayor()<<endl;
	cout<<endl<<"Hay ganador (0=No / 1=Si): "<<ELECCION_PROCESO1_2018.hayGanador()<<endl;
	cout<<endl<<"El abstencionismo de las elecciones fue de: "<<ELECCION_PROCESO1_2018.abstencionismo()<<endl<<endl;
	ELECCION_PROCESO1_2018.declaracionGanador();//Aquí no entiendo porque me imprime el if y el else al mismo tiempo.
 
#include<iostream>
#include<sstream>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
using namespace std;
 
//Punto #1
class Coleccion{
private:
	int vector[100];
	int vec[100];
	int tam;
	int can;
	int total;
 
public:
	//Punto #2
	Coleccion(){
		can=0;
		tam=100;
		for(int i=0;i<tam;i++)
		{
			vector[i]=0;
		}
	}
 
	Coleccion(int n){
		can=0;
		tam= n;
		for(int i=0;i< tam;i++)
			vector[i]=0;
	}
 
	void setCantidad(int can){
		if ((can < this->tam)&&(can >= 0))
			this->can = can;
	}
 
	void setTotalElectores(int total){
		this->total = total;
	}
 
	int getCantidad(){
		return can;
	}
 
	int getTotalElectores(){
		return total;
	}
 
	int getTamano(){
		return tam;
	}
 
	~Coleccion(){
		cout<<endl<<"~Proceso terminado~"<<endl;
	}
 
	//Punto #3
	void NumerosRand(int total){
		for(int i=0;i<can;i++){
			if(total>0 && i<can){
			srand(time(NULL));
			vector[i]=rand()%total+1;
			total-=vector[i];
			}
		cout<<vector[i]<<" ";
		}
	}
 
	//Punto #4
	string toString(){
		stringstream s;
		s<<endl<< "<<Votos>>"<<endl;
 
		for(int i=0;i<can;i++) {
			s<< "El candidato "<<i+1<<" tiene: "<<vector[i]<<" votos"<<endl;
		}
		return s.str();
	}
 
	//Punto #5
	int mayorVotos(){
	    int mayor=vector[0];
		int posicion=1;
		for(int i=1; i<can; i++){
			if(mayor<vector[i]){
				mayor=vector[i];
				posicion+=i;
			}
		return posicion;
		}
	}
 
	//Punto #6
	void igualar(){
		int j=0;
		for(int i=0;i<can;i++){
			vec[j]=vector[i];
			j++;
		}
	}
 
	void ordenaAscendente(){
	  int aux;
		for (int i=can-1; i>0; i--){
			for(int j=0; j<i; j++){
				if(vec[j] > vec[j+1]){
					aux = vec[j];
					vec[j] = vec[j+1];
					vec[j+1] = aux;
				}
			}
		}
	}
 
	string toStringOrdenado(){
		stringstream s;
		s<<endl<< "<<Votos en orden ascendente>>"<<endl;
 
		for(int j=0;j<can;j++){
			s<<"Los votos del candidato "<<j+1<<" son: "<<vec[j]<<endl;
		}
		return s.str();
	}
 
	//Punto #7
	string toStringMayor(){
		stringstream s;
		s<<endl<< "<<Posiciones con el 30% o mas del total de los votos>>"<<endl;
 
		for(int i=0;i<can;i++){
			if(vector[i]>=total*0.3){
				s<<i+1<<" / ";
			}
		}
		return s.str();
	}
 
	//Punto #8
	bool hayGanador(){
		int i=0;
		if(vector[i]>=total*0.4){
			return true;
		}
		else {
			return false;
		}
	}
 
	//Punto #9
	int totalVotos() {
		int suma=0;
		for(int i=0; i<can; i++)
			suma += vector[i];
		return suma;
	}
 
	int abstencionismo(){
		return getTotalElectores()-totalVotos();
	}
 
	//Punto #10
	int declaracionGanador(){
		int mayor2=0;
		int j=0;
			if(hayGanador()==true){
				cout<<"El ganador es el candidato: "<<mayorVotos()<<endl;
			}
			else{
				for(int i=0;i<can;i++){
					if(vec[j=can-2]==vector[i])
						mayor2=i+1;
				}
			}
		cout<<endl<<"Los dos participantes que van a la segunda ronda son: "<<mayorVotos()<<" y "<<mayor2<<"."<<endl;
	}
 
	string toStringCompara(){
		stringstream s;
		s<<endl<<"<<Datos de la eleccion>>"<<endl;
		s<<"Cantidad: "<<can<<endl;
		s<<"Total de votos: "<<totalVotos()<<endl;
		s<<"Candidato ganador: "<<mayorVotos()<<endl;
		s<<"Abstencionismo: "<<abstencionismo()<<endl;
		return s.str();
	}
 
};

Igual no esta en el lenguaje que necesitas, si es así espero lo puedas traducir.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar