







Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!








Ejercicio 2: #include
float cliP = 0, cliV = 0; float sumaP = 0, sumaV = 0; for (int i = 0; i < N; i++) { if (A[i].torden == 'P') { cliP++; sumaP += A[i].cantpub; } if (A[i].torden == 'V') { cliV++; sumaV += A[i].cantpub; } } cout << "Cantidad Publicidad Pauta: " << sumaP / cliP << endl; cout << "Cantidad Publicidad Locucion: " << sumaV / cliV << endl;
} void reporte_4(orden* A, int N) { orden aux; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) if (A[i].hora < A[j].hora) { aux = A[i]; A[i] = A[j]; A[j] = aux; } } } void main() { int N; do { cout << "Ingrese el numero de ordenes:"; cin >> N; } while (N < 0 || N > 25); orden* Arreglo = new orden[N]; generar_datos(Arreglo, N); imprimir(Arreglo, N); reporte_1(Arreglo, N); reporte_3(Arreglo, N); reporte_4(Arreglo, N); imprimir(Arreglo, N); getch(); }
Ejercicio 2: #include
#include<conio.h>
if (aux == 0) A[i].cliente = 'N';
else A[i].cliente = 'J';
aux = dado.Next(0, 2);
if (aux == 0) A[i].tipo = 'P';
else A[i].tipo = 'V';
aux = dado.Next(0, 3);
if (aux == 0) A[i].tipo = 'M';
else
if (aux == 1)A[i].tipo = 'T';
else A[i].tipo = 'N';
A[i].cantidad = dado.Next(1, 11);
}
}
void imprimir_Datos(Orden* A, int N)
{ for (int i = 0; i < N; i++)
cout << A[i].cliente << " " << A[i].tipo << " "
<< A[i].horario << " " << A[i].cantidad << endl;
}
void reporte_1(Orden* A, int N)
{
int cont = 0; float porc;
for (int i = 0; i < N; i++)
if (A[i].cliente == 'N')
cont++;
porc = cont * 100 / N;
cout << "Porc cliente natural : " << cont * 100.0 / N << endl;
cout << "Porc cliente juridica : " << 100-porc << endl;
}
void reporte_2(Orden* A, int N)
{ int cm = 0, ct = 0, cn = 0;
for (int i = 0; i < N; i++)
{
if (A[i].horario == 'M') cm++;
if (A[i].horario == 'T') ct++;
if (A[i].horario == 'N') cn++;
}
if (cm >= ct && cm >= cn) cout << "Mañana" << endl;
if (ct >= cm && ct >= cn) cout << "Tarde" << endl;
if (cn >= cm && cn >= ct) cout << "Noche" << endl;
}
void reporte_3(Orden* A, int N)
{ int cP = 0, sumaP = 0, cV = 0, sumaV = 0;
for (int i = 0; i < N; i++)
{ if (A[i].tipo == 'P')
{ cP++;
sumaP = sumaP + A[i].cantidad;
}
if (A[i].tipo == 'V')
{ cV++;
sumaV = sumaV + A[i].cantidad;
}
}
#include "iostream" #include "conio.h" using namespace std; using namespace System; struct Usuarios { char prov; char genero; int nsatis; int edad; }; void genera_y_muestra_arreglo(Usuarios* A, int N) { Random x; char prov[3] = { 'L', 'A','P' }; char genero[2] = { 'M', 'F' }; for (int i = 0; i < N; i++) { A[i].prov = prov[x.Next(0, 3)]; A[i].genero = genero[x.Next(0, 2)]; A[i].nsatis = x.Next(1, 3); A[i].edad = x.Next(18, 91); } for (int i = 0; i < N; i++) cout << A[i].prov << " " << A[i].genero << " " << A[i].nsatis << " " << A[i].edad << endl; } void calcula_maximo_y_minimo(Usuarios* A, int N) { int max = A[0].edad; int min = A[0].edad; for (int i = 1; i < N; i++) { if (A[i].edad > max) max = A[i].edad; if (A[i].edad < min) min = A[i].edad; } cout << "La maxima edad es: " << max << endl; cout << "La minima edad es: " << min << endl; } void porcentaje_por_nivel(Usuarios* A, int N) { float satis = 0; for (int i = 0; i < N; i++) if (A[i].nsatis == 1)satis++; cout << "Porcentaje personas satisfechas es:" << satis * 100 / N << endl; cout << "Porcentaje personas insatisfechas es:" << (N - satis) * 100.0 / N << endl; } void promedio_por_provincia(Usuarios* A, int N) { int suma1 = 0, suma2 = 0, suma3 = 0; int c1 = 0, c2 = 0, c3 = 0; for (int i = 0; i < N; i++) switch (A[i].prov)
case 'L' : suma1 += A[i].edad; c1++;break; case 'A' : suma2 += A[i].edad; c2++;break; case 'P' : suma3 += A[i].edad; c3++; } cout << "Promedio por provincia de Lima:" << suma1 / c1 << endl; cout << "Promedio por provincia de Arequipa:" << suma2 / c2 << endl; cout << "Promedio por provincia de Piura:" << suma3 / c3 << endl; } void ordenar_y_mostrar(Usuarios* A, int N) { Usuarios aux; for (int i = 0;i < N - 1;i++) for (int j = i + 1;j < N;j++) if (A[i].edad < A[j].edad) { aux = A[i]; A[i] = A[j]; A[j] = aux; } for (int i = 0; i < N; i++) cout << A[i].edad << ' '; } void main()
{ int N;
do { cout << "Ingrese N : ";
cin >> N;
} while (N < 0 || N>45);
Usuarios* Arreglo = new Usuarios[N]; genera_y_muestra_arreglo(Arreglo, N); calcula_maximo_y_minimo(Arreglo, N); porcentaje_por_nivel(Arreglo, N); promedio_por_provincia(Arreglo, N); ordenar_y_mostrar(Arreglo, N); getch();
Resolucion del profe: #include "iostream"
#include "conio.h"
using namespace std;
using namespace System;
struct persona
cout << "La menor edad es:" << mini << endl;
}
void porcentaje_por_nivel(persona* V, int N)
{ int sat = 0;
for (int i = 0; i < N; i++)
if (V[i].satis == 1)
sat++;
cout << "porcentaje satisfechos " << sat * 100.0 / N << endl;
cout << "porcentaje insatisfechos " << (N-sat) * 100.0 / N << endl;
}
void promedio_por_provincia(persona * V, int N)
{ int suma1 = 0, suma2 = 0, suma3 = 0;
int c1 = 0, c2 = 0, c3 = 0;
for (int i = 0; i < N; i++)
switch (V[i].prov)
{
case 'L': suma1 += V[i].edad; c1++; break;
case 'A': suma2 += V[i].edad; c2++; break;
case 'P': suma3 += V[i].edad; c3++;
}
cout << "\nPromedio edad lima: " << suma1 / c1;
cout << "\nPromedio edad arequipa: " << suma2 / c2;
cout << "\nnPromedio edad piura: " << suma3 / c3;
}
void ordenar_descendente_y_mostrar(persona* V, int n)
{ persona aux;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (V[i].edad < V[j].edad)
{ aux = V[i];
V[i] = V[j];
V[j] = aux;
}
for (int i = 0; i < n; i++)
cout << V[i].prov << " " << V[i].gene << " "
<< V[i].satis << " " << V[i].edad << " " << endl;
}
void main()
{
int N;
do {
cout << "ingrese N:";
cin >> N;
} while (N <= 0 || N> 45);
persona * Arreglo = new persona[N];
generar_y_mostrar_arreglo(Arreglo, N);
calcula_maxymini(Arreglo, N);
porcentaje_por_nivel(Arreglo, N);
promedio_por_provincia(Arreglo, N);
ordenar_descendente_y_mostrar(Arreglo, N);
getch();
Pregunta 2 caso C: #include "iostream" #include "conio.h" using namespace std; using namespace System; struct Usuarios
suma1 += A[i].observadas;c1++; suma2 += A[i].infectadas;c2++; suma3 += A[i].recuperadas;c3++; } cout << "Promedio de observados:" << suma1 / c1 << endl; cout << "Promedio de infectados:" << suma2 / c2 << endl; cout << "Promedio de recuperados:" << suma3 / c3 << endl; } void ordenar_y_mostrar(Usuarios* A, int N) { Usuarios aux; for (int i = 0;i < N - 1;i++) for (int j = i + 1;j < N;j++) if (A[i].infectadas < A[j].infectadas) { aux = A[i]; A[i] = A[j]; A[j] = aux; } for (int i = 0; i < N; i++) cout << A[i].infectadas << ' '; }
void main()
{ int N;
do { cout << "Ingrese N : ";
cin >> N;
} while (N < 0 || N>30);
Usuarios* Arreglo = new Usuarios[N]; genera_y_muestra_arreglo(Arreglo, N); calcula_maximo_y_minimo(Arreglo, N); cantidad_por_caso(Arreglo, N); promedio_por_caso(Arreglo, N); ordenar_y_mostrar(Arreglo, N); getch();
}