Advertisement
Guest User

c9e4

a guest
Jun 12th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. const int CANT_FILAS = 10;
  7. const int CANT_COLUMNAS = 4;
  8.  
  9. void mostrarTodo(int[CANT_FILAS][CANT_COLUMNAS]);
  10. void mostrarPromedios(int[CANT_FILAS][CANT_COLUMNAS]);
  11. int mejorCalificacion(int[CANT_FILAS][CANT_COLUMNAS], int);
  12. int peorCalificacion(int[CANT_FILAS][CANT_COLUMNAS], int);
  13. int maximo(int[]);
  14. int minimo(int[]);
  15. void mostrarMenu(int&);
  16. int encontrarAlumnoPorLegajo(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS], int legajo);
  17. void cargarNotas(int[CANT_FILAS][CANT_COLUMNAS]);
  18.  
  19.  
  20. int main(){
  21.     cout << setprecision(2) << fixed << showpoint;
  22.    
  23.     int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS];
  24.     cargarNotas(notasPorLegajo);
  25.    
  26.     int eleccion = 0;
  27.    
  28.     mostrarMenu(eleccion);
  29.    
  30.     while(eleccion != 0){
  31.         int legajo = 0;
  32.         switch(eleccion){
  33.             case 1:
  34.                 mostrarTodo(notasPorLegajo);
  35.                 break;
  36.             case 2:
  37.                 mostrarPromedios(notasPorLegajo);
  38.                 break;
  39.             case 3:
  40.                 cout << "Ingrese el numero de legajo: ";
  41.                 cin >> legajo;
  42.                 cout << "La mejor calificacion del alumno con legajo " << legajo << " es: " << mejorCalificacion(notasPorLegajo, legajo) << endl;
  43.                 break;
  44.             case 4:
  45.                 cout << "Ingrese el numero de legajo: ";
  46.                 cin >> legajo;
  47.                 cout << "La peor calificacion del alumno con legajo " << legajo << " es: " << peorCalificacion(notasPorLegajo, legajo) << endl;
  48.                 break;
  49.             case 0:
  50.                 return 0;
  51.                 break;
  52.             default:
  53.                 cout << "Por favor, elija una opcion valida." << endl;
  54.                 break;
  55.         }
  56.         cout << endl;
  57.        
  58.         mostrarMenu(eleccion);
  59.     }
  60.    
  61.     return 0;
  62. }
  63.  
  64. void mostrarTodo(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS]){
  65.     for(int fila = 0; fila < CANT_FILAS; fila++){
  66.         cout << "Legajo " << notasPorLegajo[fila][0] << ": " << endl;
  67.         for(int col = 1; col < CANT_COLUMNAS; col++){
  68.             cout << "   Nota " << col << ": " << notasPorLegajo[fila][col] << endl;
  69.         }
  70.     }
  71. }
  72.  
  73. void mostrarPromedios(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS]){
  74.     float suma = 0.f;
  75.    
  76.     for(int fila = 0; fila < CANT_FILAS; fila++){
  77.         cout << "Legajo " << notasPorLegajo[fila][0] << ": " << endl;
  78.         for(int col = 1; col < CANT_COLUMNAS; col++){
  79.             suma += notasPorLegajo[fila][col];
  80.         }
  81.         cout << "   Promedio: " << suma / 3 << endl;
  82.         suma = 0.f;
  83.     }
  84. }
  85.  
  86. int mejorCalificacion(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS], int legajo){
  87.     int indiceFila = encontrarAlumnoPorLegajo(notasPorLegajo, legajo);
  88.     int notas[3];
  89.    
  90.     for(int i = 0; i < CANT_COLUMNAS-1; i++){
  91.         notas[i] = notasPorLegajo[indiceFila][i+1];
  92.     }
  93.    
  94.     return maximo(notas);  
  95. }
  96.  
  97. int peorCalificacion(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS], int legajo){
  98.     int indiceFila = encontrarAlumnoPorLegajo(notasPorLegajo, legajo);
  99.     int notas[3];
  100.    
  101.     for(int i = 0; i < CANT_COLUMNAS-1; i++){
  102.         notas[i] = notasPorLegajo[indiceFila][i+1];
  103.     }
  104.  
  105.     return minimo(notas);  
  106. }
  107.  
  108. int maximo(int notas[CANT_COLUMNAS-1]){
  109.     int posicion = 0;
  110.     int maximo = notas[0];
  111.    
  112.     for(int i = 1; i < 3; i++){
  113.         if(notas[i] > maximo){
  114.             posicion = i;
  115.             maximo = notas[i];
  116.         }
  117.     }
  118.    
  119.     return maximo;
  120. }
  121.  
  122. int minimo(int notas[]){
  123.     int j = 0;
  124.    
  125.     while(j <= (CANT_COLUMNAS-1)-1 && notas[j] == 0){
  126.         j++;
  127.     }
  128.    
  129.     int minimo = notas[j];
  130.     int posicion = j;
  131.    
  132.     for(j+1; j < 3; j++){
  133.         if(notas[j] != 0 && notas[j] < minimo){
  134.             posicion = j;
  135.             minimo = notas[j];
  136.         }
  137.     }
  138.    
  139.     return minimo;
  140. }
  141.  
  142. void mostrarMenu(int& eleccion){
  143.     cout << "Escriba: " << endl
  144.          << "(1) Para ver todas las notas de cada alumno." << endl
  145.          << "(2) Para ver los promedios de cada alumno." << endl
  146.          << "(3) Para ver la mejor nota de un alumno." << endl
  147.          << "(4) Para ver la peor nota de un alumno." << endl
  148.          << "(0) Para salir." << endl;
  149.     cin >> eleccion;
  150. }
  151.  
  152. int encontrarAlumnoPorLegajo(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS], int legajo){
  153.     int indiceFila = 0;
  154.     int iterador = 0;
  155.     bool encontrado = false;
  156.    
  157.     while(!encontrado && iterador < CANT_FILAS){
  158.        
  159.         if(notasPorLegajo[iterador][0] == legajo){
  160.             indiceFila = iterador;
  161.             encontrado = true;
  162.         }
  163.         iterador++;
  164.     }
  165.    
  166.     return indiceFila;
  167. }
  168.  
  169. void cargarNotas(int notasPorLegajo[CANT_FILAS][CANT_COLUMNAS]){
  170.     cout << "Ingrese: " << endl;
  171.    
  172.     for(int fila = 0; fila < CANT_FILAS; fila++){
  173.         cout << "Legajo del alumno " << fila+1 << ": " << endl;
  174.         cin >> notasPorLegajo[fila][0];
  175.        
  176.         for(int col = 1; col < CANT_COLUMNAS; col++){
  177.             cout << "Nota " << col << ": ";
  178.             cin >> notasPorLegajo[fila][col];
  179.         }
  180.     }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement