#include <iostream>
using namespace std;
#define MAX_ALUMNOS 100
#define MAX_NOTAS 30
class Curso {
string nombres[MAX_ALUMNOS];
int notas[MAX_ALUMNOS,MAX_NOTAS];
int cant_notas[MAX_ALUMNOS];
float promedios[MAX_ALUMNOS];
int cant_alumnos;
public:
Curso() {
cant_alumnos = 0;
}
void CargarDato(string nombre, int nota) {
int i;
for (i=0; i<cant_alumnos; i++) {
if (nombres[i]==nombre) {
notas[i,cant_notas[i]]]=nota;
cant_notas[i]++;
break;
}
}
if (i==cant_alumnos) {
nombres[cant_alumnos] = nombre;
notas[cant_alumnos,0] = nota;
cant_notas[cant_alumnos] = 1;
cant_alumnos++;
}
}
void CalcularPromedios() {
for (int i=0; i<cant_alumnos; i++) {
float suma = 0;
for (int j=0;j<cant_notas[i];j++) {
suma+=notas[i,j];
}
promedios[i]=suma/cant_notas[i];
}
}
int CantidadAlumnos() {
return cant_alumnos;
}
int CantidadNotas(int i) {
return cant_notas[i];
}
float VerPromedio(int i) {
return promedios[i];
}
string VerNombre(int i) {
return nombres[i];
}
float VerNota(int i, int j) {
return notas[i,j];
}
};
void main() {
Curso oCurso;
string nombre;
int nota;
cout<<"Ingrese el nombre: ";
getline(cin,nombre);
while (nombre!="") {
cout<<"Ingrese la nota: ";
cin>>nota;
cin.ignore(255,'\n');
oCurso.CargarDato(nombre,nota);
cout<<"Ingrese el nombre: ";
getline(cin,nombre);
}
//oCurso.CargarDato("Torvalds, Linus", 10);
//oCurso.CargarDato("Gates, William",7);
//oCurso.CargarDato("Allen, Paul",8);
//oCurso.CargarDato("Wozniack, Steve",4);
//oCurso.CargarDato("Norton, Peter",4);
//oCurso.CargarDato("Jobs, Steve",8);
//oCurso.CargarDato("Stallman, Richard",10);
//oCurso.CargarDato("Gates, William",4);
//oCurso.CargarDato("Allen, Paul",6);
//oCurso.CargarDato("Wozniack, Steve", 9);
//oCurso.CargarDato("Torvalds, Linus", 9);
//oCurso.CargarDato("Stallman, Richard",8);
//oCurso.CargarDato("Norton, Peter",2);
//oCurso.CargarDato("Stallman, Richard",10);
//oCurso.CargarDato("Wozniack, Steve",10);
//oCurso.CargarDato("Jobs, Steve",9);
oCurso.CalcularPromedios();
cout<<endl<<" Nombre Promedio"<<endl;
cout<<setprecision(2)<<fixed<<setfill('_');
for (int i=0;i<oCurso.CantidadAlumnos();i++) {
cout<<setfill(' ')<<right<<setw(3)<<i+1<<"__"
<<setfill('_')<<left<<setw(20)<<oCurso.VerNombre(i)
<<right<<setw(6)<<oCurso.VerNota(i)<<endl;
}
}
|