Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. /*
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <ctime>
  5.  
  6. using namespace System;
  7. using namespace std;
  8.  
  9. struct Votantes
  10. {
  11. long dni;
  12. short voto;
  13. };
  14.  
  15. void Spawn_votantes(Votantes *arreglo)
  16. {
  17. for (int i = 0; i < 100; ++i)
  18. {
  19. arreglo[i].dni = rand() % 1000000 + 10000000;
  20. arreglo[i].voto = rand() % 3 + 1;
  21. }
  22. }
  23.  
  24. void cant_votantes(Votantes *arreglo, int *a, int *b, int *c)
  25. {
  26. *a = 0;
  27. *b = 0;
  28. *c = 0;
  29. for (int i = 0; i < 100; i++)
  30. {
  31. if (arreglo[i].voto == 1)
  32. {
  33. (*a)++;
  34. }
  35. else if (arreglo[i].voto == 2)
  36. {
  37. (*b)++;
  38. }
  39. else if (arreglo[i].voto == 3)
  40. {
  41. (*c)++;
  42. }
  43. }
  44. }
  45.  
  46. void ganador(int c1, int c2)
  47. {
  48. if (c1 > c2)
  49. {
  50. cout << "Gana el A" << endl;
  51. }
  52. else if (c2 > c1)
  53. {
  54. cout << "Gana el B" << endl;
  55. }
  56. else
  57. {
  58. cout << "Empataron" << endl;
  59. }
  60. }
  61.  
  62. void viejo(Votantes *arreglo)
  63. {
  64. long menor = arreglo[0].dni;
  65. int p = 0;
  66. for (int i = 0; i < 100; i++)
  67. {
  68. if (arreglo[i].dni < menor)
  69. {
  70. menor = arreglo[i].dni;
  71. p + 1;
  72. }
  73. }
  74. cout << "El dni mas logevo es: " << menor << endl;
  75. cout << "Su posicion es: " << p << endl;
  76. }
  77.  
  78. void mostrar(Votantes *arreglo)
  79. {
  80. for (int i = 0; i < 100; i++)
  81. {
  82. cout << i << " -> " << arreglo[i].dni << " - " << arreglo[i].voto << endl;
  83. }
  84. }
  85.  
  86. int main()
  87. {
  88. int c1, c2, c3;
  89. srand(time(0));
  90. Votantes *arreglo = new Votantes[100];
  91. Spawn_votantes(arreglo);
  92. cant_votantes(arreglo, &c1, &c2, &c3);
  93.  
  94. cout << "Op 1: " << c1 << endl;
  95. cout << "Op 2: " << c2 << endl;
  96. cout << "Op 3: " << c3 << endl;
  97.  
  98. ganador(c1, c2);
  99. viejo(arreglo);
  100. mostrar(arreglo);
  101. _getch();
  102. }
  103. */
  104.  
  105. #include <iostream>
  106. #include <conio.h>
  107. #include <ctime>
  108.  
  109. using namespace System;
  110. using namespace std;
  111.  
  112. struct Clientes
  113. {
  114. char cliente;
  115. int tramite;
  116. int tiempo;
  117. };
  118.  
  119. void Spawn_c(Clientes *Vec, int c)
  120. {
  121. for (int i = 1; i < c; i++)
  122. {
  123. Vec[i].cliente = rand() % 2 == 0 ? 'v' : 'N';
  124. Vec[i].tramite = rand() % 5 + 1;
  125. Vec[i].tiempo = rand() % 600 + 60;
  126. /*
  127. if (Vec[i].cliente == 'V')
  128. {
  129. cout << "VIP";
  130. }
  131. else
  132. {
  133. cout << "Normal";
  134. }
  135. */
  136. }
  137. }
  138.  
  139. void Mayor_frec(Clientes *Vec, int c)
  140. {
  141. int cV = 0;
  142. int cN = 0;
  143.  
  144. for (int i = 0; i < c; i++)
  145. {
  146. if (Vec[i].cliente == 'V')
  147. {
  148. cV++;
  149. }
  150. else
  151. {
  152. cN++;
  153. }
  154. }
  155. if (cV > cN)
  156. {
  157. cout << "Los usuarios VIP van seguido" << endl;
  158. }
  159. else if (cN > cV)
  160. {
  161. cout << "Los usuarios NORMALES van seguido" << endl;
  162. }
  163. else
  164. {
  165. cout << "Ambos van seguido";
  166. }
  167. }
  168.  
  169. int N_tram(Clientes *Vec, int c)
  170. {
  171. float x = 0;
  172. float prom = 0;
  173. for (int i = 0; i < c; i++)
  174. {
  175. if (Vec[i].tramite == 'V')
  176. {
  177. x++;
  178. prom += Vec[i].tramite;
  179. }
  180. }
  181. return prom/x;
  182. }
  183.  
  184. void mayor(Clientes *Vec, int c)
  185. {
  186. int m = Vec[0].tiempo;
  187. int p = 0;
  188. for (int i = 0; i < c; i++)
  189. {
  190. if (Vec[i].tiempo > m)
  191. {
  192. m = Vec[i].tiempo;
  193. p = i;
  194. }
  195. }
  196. cout << "El mayor es: " << m << "El tipo: " << Vec[p].cliente << "El numero de tramites: " << Vec[p].tramite << endl;
  197. }
  198.  
  199. int main()
  200. {
  201. srand(time(0));
  202. int c = rand() % 41 + 10;
  203. Clientes *Vec = new Clientes[c];
  204. Spawn_c(Vec, c);
  205. Mayor_frec(Vec, c);
  206. N_tram(Vec, c);
  207. mayor(Vec, c);
  208. _getch();
  209. return 0;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement