Laboratorio N°9
Ejemplo 1:
#include <iostream>
#include <string>
using namespace std;
class estudiante {
long int ci;
string nombre;
int edad;
double notas[4];
public:
estudiante();
void ingreso();
void imprimir();
void promedio();
double validar(double nota);
void validar_edad(int d);
};
estudiante::estudiante() {
ci = 0;
nombre = "";
edad = 0;
for(int i = 0; i < 4; i++)
notas[i] = 0;
void estudiante::validar_edad(int d) {
while(d <= 0 || d > 25) {
cout << "\nIngrese nuevamente la edad del alumno: ";
cin >> d;
edad = d;
}
}
double estudiante::validar(double nota) {
while(nota < 0 || nota > 100) {
cout << "\nIngrese nuevamente la nota: ";
cin >> nota;
return nota;
void estudiante::ingreso() {
cout << "Ingrese la cedula de identidad: ";
cin >> ci;
cout << "\nIngrese el Nombre: ";
cin >> nombre;
cout << "\nIngrese la edad: ";
cin >> edad;
validar_edad(edad);
for (int i = 0; i < 3; i++) {
cout << "\nIngrese la nota " << i+1 << ": ";
cin >> notas[i];
notas[i] = validar(notas[i]);
void estudiante::imprimir() {
cout << "\nCedula de identidad: " << ci;
cout << "\nNombre: " << nombre;
cout << "\nEdad: " << edad;
for (int i = 0; i <= 3; i++) {
if(i <= 2)
cout << "\nNota " << i+1 << ": " << notas[i];
else
cout << "\nPromedio: " << notas[i];
}
void estudiante::promedio() {
notas[3] = (notas[0] + notas[1] + notas[2]) / 3;
int main() {
estudiante a[3];
char op;
do {
cout << "\n\tPrograma para el ingreso de datos de alumnos.\n\n";
for (int i = 0; i < 2; i++) {
cout << "\nDatos del alumno: " << i+1 << endl;
a[i].ingreso();
a[i].promedio();
for (int j = 0; j < 2; j++) {
cout << "\n\nDatos del alumno: " << j+1 << endl;
a[j].imprimir();
cout << "\n\nDesea ejecutar nuevamente presione 'a'\nCaso contrario cualquier tecla: ";
cin >> op;
} while(op == 'a' || op == 'A');
cout << "\n \t\t\t FIN DEL PROGRAMA";
return 0;