Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : main project file.
- #include "stdafx.h"
- #include <conio.h>
- #include <iostream>
- using namespace std;
- using namespace System;
- struct registro
- {
- char tipop;
- int monto;
- };
- void genera_arreglos(registro *m1, int n)
- {
- int a;
- Random x;
- for (int i = 0; i < n; i++)
- {
- m1[i].monto = x.Next(50, 1501);
- a = x.Next(0, 2);
- if (a == 0) m1[i].tipop = 'R'; else m1[i].tipop = 'D';
- }
- }
- void imprime_arreglos(registro *m1, int n)
- {
- cout << "Operacion: \t";
- for (int i = 0; i < n; i++)
- {
- cout << m1[i].monto << ' ';
- }cout << endl<<endl;
- cout << "Monto: \t";
- for (int i = 0; i < n; i++)
- {
- cout << m1[i].tipop << ' ';
- }cout << endl<<endl;
- }
- void tipo_operacion_mayor(registro *m1, int n)
- {
- int cr = 0, cd = 0;
- for (int i = 0; i < n; i++)
- {
- if (m1[i].tipop == 'R')cr++; else cd++;
- }
- cout << "La operacion con la mayor cantidad de registros: ";
- if (cr > cd) cout << "el retiro."; else if (cd > cr) cout << "el deposito."; else cout << "son iguales.";
- cout << endl<<endl;
- }
- void promedio_De_retiros(registro *m1, int n)
- {
- int suma=0, prom=0;
- int cr = 0;
- for (int i = 0; i < n; i++)
- {
- if (m1[i].tipop == 'R') { cr++;suma = m1[i].monto + suma; }
- }prom += suma*1.0 / cr;
- cout << "El promedio de los retiros realizados es: " << prom << endl<<endl;
- }
- void ordena_arreglos(registro *m1, int n)
- {
- registro aux;
- for (int i = 0; i < n-1; i++)
- {
- for (int j = i+1; j < n; j++)
- {
- if (m1[i].monto == m1[j].monto)
- {
- if (m1[i].tipop > m1[j].tipop)
- {
- aux = m1[i];
- m1[i] = m1[j];
- m1[j] = aux;
- }
- }
- else
- if (m1[i].monto < m1[j].monto)
- {
- aux = m1[i];
- m1[i] = m1[j];
- m1[j] = aux;
- }
- }
- }
- imprime_arreglos(m1, n);
- }
- int main()
- {
- Random y;
- int n=y.Next(15,50);
- registro *v1 = new registro[n];
- genera_arreglos(v1,n);
- imprime_arreglos(v1, n);
- tipo_operacion_mayor(v1, n);
- promedio_De_retiros(v1, n);
- ordena_arreglos(v1, n);
- _getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment