AlenAntonelli

Estructura dinámica de Promedios

Jun 24th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct Planilla
  7. {
  8.     vector<  pair < string, vector<int> >  > Alu; ///Lista de adyacencia
  9.     int N, C;
  10.     void Ingreso()
  11.     {
  12.         cout<<"Cantidad de alumnos: "; cin>>C;
  13.         cout<<"Cantidad de notas por alumno: "; cin>>N;
  14.         Alu.resize(C);
  15.         ///adj = vector <vector <int> > (nodos+1, vector <int> (arista+1, 5));
  16.  
  17.         for(int i=0; i<C; i++)
  18.         {
  19.             string nombre;
  20.             cin>>nombre;
  21.             Alu[i].first=nombre;
  22.             for(int j=0; j<N; j++)
  23.             {
  24.                 float aux;
  25.                 cin>>aux;
  26.                 Alu[i].second.push_back(aux);
  27.             }
  28.         }
  29.     }
  30.     void Proceso()
  31.     {
  32.         for(int i=0; i<C; i++)
  33.         {
  34.             float sum=0, prom;
  35.             for(int j=0; j<N; j++)
  36.                 sum+=Alu[i].second[j];
  37.             prom=sum/N;
  38.             Alu[i].second.push_back(prom);
  39.         }
  40.     }
  41.     void Salida()
  42.     {
  43.         cout<<endl<<endl;
  44.         for(int i=0; i<C; i++)
  45.         {
  46.             float sum=0;
  47.             cout<<Alu[i].first<<" => ";
  48.             for(int j=0; j<N; j++)
  49.                 cout << Alu[i].second[j]<<" ";
  50.             cout<<"= "<<Alu[i].second[N]<<endl;
  51.         }
  52.     }
  53. };
  54. int main ()
  55. {
  56.     Planilla P;
  57.     P.Ingreso();
  58.     P.Proceso();
  59.     P.Salida();
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment