Xavistian

Ejercicio 2

Jun 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. // ConsoleApplication1.cpp : main project file.
  2.  
  3. #include "stdafx.h"
  4. #include <conio.h>
  5. #include <iostream>
  6. using namespace std;
  7. using namespace System;
  8.  
  9. struct registro
  10. {
  11.     char tipop;
  12.     int monto;
  13. };
  14.  
  15. void genera_arreglos(registro *m1, int n)
  16. {
  17.     int a;
  18.     Random x;
  19.     for (int i = 0; i < n; i++)
  20.     {
  21.         m1[i].monto = x.Next(50, 1501);
  22.         a = x.Next(0, 2);
  23.         if (a == 0) m1[i].tipop = 'R'; else m1[i].tipop = 'D';
  24.     }
  25. }
  26. void imprime_arreglos(registro *m1, int n)
  27. {
  28.     cout << "Operacion: \t";
  29.     for (int i = 0; i < n; i++)
  30.     {
  31.         cout << m1[i].monto << ' ';
  32.     }cout << endl<<endl;
  33.     cout << "Monto: \t";
  34.     for (int i = 0; i < n; i++)
  35.     {
  36.         cout << m1[i].tipop << ' ';
  37.     }cout << endl<<endl;
  38. }
  39. void tipo_operacion_mayor(registro *m1, int n)
  40. {
  41.     int cr = 0, cd = 0;
  42.     for (int i = 0; i < n; i++)
  43.     {
  44.         if (m1[i].tipop == 'R')cr++; else cd++;
  45.     }
  46.     cout << "La operacion con la mayor cantidad de registros: ";
  47.     if (cr > cd) cout << "el retiro."; else if (cd > cr) cout << "el deposito."; else cout << "son iguales.";
  48.     cout << endl<<endl;
  49. }
  50. void promedio_De_retiros(registro *m1, int n)
  51. {
  52.     int suma=0, prom=0;
  53.     int cr = 0;
  54.     for (int i = 0; i < n; i++)
  55.     {
  56.         if (m1[i].tipop == 'R') { cr++;suma = m1[i].monto + suma; }
  57.     }prom += suma*1.0 / cr;
  58.     cout << "El promedio de los retiros realizados es: " << prom << endl<<endl;
  59. }
  60. void ordena_arreglos(registro *m1, int n)
  61. {
  62.     registro aux;
  63.     for (int i = 0; i < n-1; i++)
  64.     {
  65.         for (int j = i+1; j < n; j++)
  66.         {
  67.             if (m1[i].monto == m1[j].monto)
  68.             {
  69.                 if (m1[i].tipop > m1[j].tipop)
  70.                 {
  71.                     aux = m1[i];
  72.                     m1[i] = m1[j];
  73.                     m1[j] = aux;
  74.                 }
  75.             }
  76.             else
  77.             if (m1[i].monto < m1[j].monto)
  78.             {
  79.                 aux = m1[i];
  80.                 m1[i] = m1[j];
  81.                 m1[j] = aux;
  82.             }
  83.         }
  84.     }
  85.     imprime_arreglos(m1, n);
  86. }
  87. int main()
  88. {
  89.     Random y;
  90.     int n=y.Next(15,50);
  91.     registro *v1 = new registro[n];
  92.  
  93.     genera_arreglos(v1,n);
  94.     imprime_arreglos(v1, n);
  95.     tipo_operacion_mayor(v1, n);
  96.     promedio_De_retiros(v1, n);
  97.     ordena_arreglos(v1, n);
  98.     _getch();
  99.     return 0;
  100. }
Add Comment
Please, Sign In to add comment