Advertisement
rihardmarius

corte de control

Dec 13th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int legajo, nota, materia, fecha, a=0, c=0, legajo_ant;
  9.     ifstream input ("alumnos por examen.txt");
  10.     ofstream output ("promedios.txt");
  11.  
  12.     if (not input.is_open() or not output.is_open())
  13.     {
  14.         cout << "Archivo no encontrado." << endl;
  15.         return 1;
  16.     }
  17.  
  18.     input >> legajo >> nota >> materia >> fecha;            // lee
  19.  
  20.     while (input.good())                                    // chequea
  21.     {
  22.         legajo_ant = legajo;                                // actualiza
  23.         while (input.good() and (legajo_ant == legajo))     // chequea
  24.         {
  25.             a = a + nota;                                   // suma
  26.             c++;                                            //cuenta
  27.             input >> legajo >> nota >> materia >> fecha;    // lee
  28.         }
  29.         output << legajo_ant << ' ' << a/c << '\n';         // escribe
  30.         a = 0;                                              // resetea
  31.         c = 0;                                              // resetea
  32.     }
  33.  
  34.     if (input.bad())
  35.         std::cout << "I/O error while reading\n";
  36.     else if (input.eof())
  37.         std::cout << "End of file reached successfully\n";
  38.     else if (input.fail())
  39.         std::cout << "Non-integer data encountered\n";
  40.  
  41.  
  42.     /*
  43.     input >> legajo >> nota >> materia >> fecha;
  44.     legajo_ant = legajo;
  45.     while (input.good())
  46.     {
  47.         while (input.good() and (legajo_ant == legajo))
  48.         {
  49.             a = a + nota;
  50.             c++;
  51.             legajo_ant = legajo;
  52.             input >> legajo >> nota >> materia >> fecha;
  53.         }
  54.         output << legajo_ant << ' ' << a/c << '\n';
  55.         a = 0;
  56.         c = 0;
  57.         legajo_ant = legajo;
  58.     }*/
  59.     return 0;
  60. }
  61.  
  62.  
  63.  
  64. /*
  65. input >> legajo >> nota >> materia >> fecha;
  66.     do {
  67.         legajo_ant = legajo;
  68.         do {
  69.             a = a + nota;
  70.             c++;
  71.  
  72.             input >> legajo >> nota >> materia >> fecha;
  73.         } while (input.good() and legajo == legajo_ant);
  74.  
  75.         output << legajo_ant << ' ' << a/c << '\n';
  76.         a = 0;
  77.         c = 0;
  78.  
  79.  
  80.     } while (input.good());
  81. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement