GUIA
C++
🧮 Ejercicio 43 — Sumatoria
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;
int main() {
int a, b, k;
double suma = 0;
cout << "Ingrese el valor de a: ";
cin >> a;
cout << "Ingrese el valor de b: ";
cin >> b;
if (a > b) {
cout << "Error: a debe ser menor o igual que b.\n";
} else {
for (k = a; k <= b; k++) {
if (k == 5) {
cout << "Se omite k = 5 (division por cero)\n";
continue;
}
suma += (pow(k, 3) + pow(k, k)) / (k - 5.0);
}
cout << "\nLa sumatoria es: " << suma << endl;
}
getch();
return 0;
}
🐟 Ejercicio 44 — Control de pesca
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
float limite, pesca, total = 0;
cout << "Ingrese el limite maximo permitido (kg): ";
cin >> limite;
while (true) {
cout << "Ingrese los kg pescados (0 para terminar): ";
cin >> pesca;
if (pesca == 0) {
cout << "Fin del registro.\n";
break;
} else if (pesca < 0) {
cout << "Error: valor negativo no valido.\n";
continue;
}
total += pesca;
cout << "Total acumulado: " << total << " kg\n";
if (total > limite) {
cout << "ALERTA: Se ha sobrepasado el limite legal!\n";
break;
}
}
cout << "\nTotal pescado: " << total << " kg\n";
getch();
return 0;
}
Ejercicio 45 — Restaurante (Propina 10%)
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
float valor, subtotal, propina, total;
int mesa;
for (mesa = 1; mesa <= 15; mesa++) {
subtotal = 0;
cout << "\nMesa " << mesa << endl;
while (true) {
cout << "Ingrese valor del pedido (0 para terminar): ";
cin >> valor;
if (valor == 0) break;
subtotal += valor;
}
propina = subtotal * 0.10f;
total = subtotal + propina;
cout << "Subtotal: " << subtotal
<< " | Propina: " << propina
<< " | Total: " << total << endl;
}
getch();
return 0;
}
💰 Ejercicio 46 — Ganancia de ventas
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
int codigo;
float precio, ganancia, totalGanancia = 0;
while (true) {
cout << "Ingrese codigo del articulo (0 para terminar): ";
cin >> codigo;
if (codigo == 0) break;
cout << "Ingrese precio del articulo: ";
cin >> precio;
if (precio < 5000)
ganancia = precio * 0.15f;
else if (precio <= 12000)
ganancia = precio * 0.20f;
else
ganancia = precio * 0.30f;
totalGanancia += ganancia;
cout << "Ganancia del articulo: " << ganancia << endl;
}
cout << "\nGanancia total del mes: " << totalGanancia << endl;
getch();
return 0;
}
📘 Ejercicio 47 — Promedio de estudiantes
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
int n, i, j, numNotas, aprob = 0, reprob = 0;
float nota, suma, prom, promGeneral = 0;
cout << "Ingrese numero de estudiantes: ";
cin >> n;
for (i = 1; i <= n; i++) {
suma = 0;
cout << "\nEstudiante " << i << endl;
cout << "Numero de notas: ";
cin >> numNotas;
for (j = 1; j <= numNotas; j++) {
cout << "Nota " << j << ": ";
cin >> nota;
suma += nota;
}
prom = suma / numNotas;
promGeneral += prom;
cout << "Promedio: " << prom << endl;
if (prom >= 3.0)
aprob++;
else
reprob++;
}
cout << "\nAprobados: " << aprob
<< "\nReprobados: " << reprob
<< "\nPromedio general: " << promGeneral / n << endl;
getch();
return 0;
}
🎓 Ejercicio 48 — Definitiva ponderada (25%, 35%, 40%)
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
int n, i;
float n1, n2, n3, def;
float sumaAprob = 0, sumaReprob = 0;
int aprob = 0, reprob = 0;
cout << "Ingrese numero de estudiantes: ";
cin >> n;
for (i = 1; i <= n; i++) {
cout << "\nEstudiante " << i << endl;
cout << "Nota 1: "; cin >> n1;
cout << "Nota 2: "; cin >> n2;
cout << "Nota 3: "; cin >> n3;
def = n1 * 0.25f + n2 * 0.35f + n3 * 0.40f;
cout << "Definitiva: " << def << endl;
if (def >= 3.0) {
aprob++;
sumaAprob += def;
} else {
reprob++;
sumaReprob += def;
}
}
if (aprob > 0)
cout << "\nPromedio aprobados: " << sumaAprob / aprob;
if (reprob > 0)
cout << "\nPromedio reprobados: " << sumaReprob / reprob;
getch();
return 0;
}