Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const int CANT_FILAS = 10;
- const int CANT_COLUMNAS = 4;
- void mostrarTodo(int[CANT_FILAS][CANT_COLUMNAS]);
- void mostrarPromedios(int[CANT_FILAS][CANT_COLUMNAS]);
- int mejorCalificacion(int[CANT_FILAS][CANT_COLUMNAS], int);
- int peorCalificacion(int[CANT_FILAS][CANT_COLUMNAS], int);
- int maximo(int[]);
- int minimo(int[]);
- void mostrarMenu(int&);
- int encontrarAlumnoPorLegajo(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS], int legajo);
- void cargarNotas(int[CANT_FILAS][CANT_COLUMNAS]);
- int main(){
- cout << setprecision(2) << fixed << showpoint;
- int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS];
- cargarNotas(notasPorLegajo);
- int eleccion = 0;
- mostrarMenu(eleccion);
- while(eleccion != 0){
- int legajo = 0;
- switch(eleccion){
- case 1:
- mostrarTodo(notasPorLegajo);
- break;
- case 2:
- mostrarPromedios(notasPorLegajo);
- break;
- case 3:
- cout << "Ingrese el numero de legajo: ";
- cin >> legajo;
- cout << "La mejor calificacion del alumno con legajo " << legajo << " es: " << mejorCalificacion(notasPorLegajo, legajo) << endl;
- break;
- case 4:
- cout << "Ingrese el numero de legajo: ";
- cin >> legajo;
- cout << "La peor calificacion del alumno con legajo " << legajo << " es: " << peorCalificacion(notasPorLegajo, legajo) << endl;
- break;
- case 0:
- return 0;
- break;
- default:
- cout << "Por favor, elija una opcion valida." << endl;
- break;
- }
- cout << endl;
- mostrarMenu(eleccion);
- }
- return 0;
- }
- void mostrarTodo(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS]){
- for(int fila = 0; fila < CANT_FILAS; fila++){
- cout << "Legajo " << notasPorLegajo[fila][0] << ": " << endl;
- for(int col = 1; col < CANT_COLUMNAS; col++){
- cout << " Nota " << col << ": " << notasPorLegajo[fila][col] << endl;
- }
- }
- }
- void mostrarPromedios(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS]){
- float suma = 0.f;
- for(int fila = 0; fila < CANT_FILAS; fila++){
- cout << "Legajo " << notasPorLegajo[fila][0] << ": " << endl;
- for(int col = 1; col < CANT_COLUMNAS; col++){
- suma += notasPorLegajo[fila][col];
- }
- cout << " Promedio: " << suma / 3 << endl;
- suma = 0.f;
- }
- }
- int mejorCalificacion(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS], int legajo){
- int indiceFila = encontrarAlumnoPorLegajo(notasPorLegajo, legajo);
- int notas[3];
- for(int i = 0; i < CANT_COLUMNAS-1; i++){
- notas[i] = notasPorLegajo[indiceFila][i+1];
- }
- return maximo(notas);
- }
- int peorCalificacion(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS], int legajo){
- int indiceFila = encontrarAlumnoPorLegajo(notasPorLegajo, legajo);
- int notas[3];
- for(int i = 0; i < CANT_COLUMNAS-1; i++){
- notas[i] = notasPorLegajo[indiceFila][i+1];
- }
- return minimo(notas);
- }
- int maximo(int notas[CANT_COLUMNAS-1]){
- int posicion = 0;
- int maximo = notas[0];
- for(int i = 1; i < 3; i++){
- if(notas[i] > maximo){
- posicion = i;
- maximo = notas[i];
- }
- }
- return maximo;
- }
- int minimo(int notas[]){
- int j = 0;
- while(j <= (CANT_COLUMNAS-1)-1 && notas[j] == 0){
- j++;
- }
- int minimo = notas[j];
- int posicion = j;
- for(j+1; j < 3; j++){
- if(notas[j] != 0 && notas[j] < minimo){
- posicion = j;
- minimo = notas[j];
- }
- }
- return minimo;
- }
- void mostrarMenu(int& eleccion){
- cout << "Escriba: " << endl
- << "(1) Para ver todas las notas de cada alumno." << endl
- << "(2) Para ver los promedios de cada alumno." << endl
- << "(3) Para ver la mejor nota de un alumno." << endl
- << "(4) Para ver la peor nota de un alumno." << endl
- << "(0) Para salir." << endl;
- cin >> eleccion;
- }
- int encontrarAlumnoPorLegajo(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS], int legajo){
- int indiceFila = 0;
- int iterador = 0;
- bool encontrado = false;
- while(!encontrado && iterador < CANT_FILAS){
- if(notasPorLegajo[iterador][0] == legajo){
- indiceFila = iterador;
- encontrado = true;
- }
- iterador++;
- }
- return indiceFila;
- }
- void cargarNotas(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS]){
- cout << "Ingrese: " << endl;
- for(int fila = 0; fila < CANT_FILAS; fila++){
- cout << "Legajo del alumno " << fila+1 << ": " << endl;
- cin >> notasPorLegajo[fila][0];
- for(int col = 1; col < CANT_COLUMNAS; col++){
- cout << "Nota " << col << ": ";
- cin >> notasPorLegajo[fila][col];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement