Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- int legajo, nota, materia, fecha, a=0, c=0, legajo_ant;
- ifstream input ("alumnos por examen.txt");
- ofstream output ("promedios.txt");
- if (not input.is_open() or not output.is_open())
- {
- cout << "Archivo no encontrado." << endl;
- return 1;
- }
- input >> legajo >> nota >> materia >> fecha; // lee
- while (input.good()) // chequea
- {
- legajo_ant = legajo; // actualiza
- while (input.good() and (legajo_ant == legajo)) // chequea
- {
- a = a + nota; // suma
- c++; //cuenta
- input >> legajo >> nota >> materia >> fecha; // lee
- }
- output << legajo_ant << ' ' << a/c << '\n'; // escribe
- a = 0; // resetea
- c = 0; // resetea
- }
- if (input.bad())
- std::cout << "I/O error while reading\n";
- else if (input.eof())
- std::cout << "End of file reached successfully\n";
- else if (input.fail())
- std::cout << "Non-integer data encountered\n";
- /*
- input >> legajo >> nota >> materia >> fecha;
- legajo_ant = legajo;
- while (input.good())
- {
- while (input.good() and (legajo_ant == legajo))
- {
- a = a + nota;
- c++;
- legajo_ant = legajo;
- input >> legajo >> nota >> materia >> fecha;
- }
- output << legajo_ant << ' ' << a/c << '\n';
- a = 0;
- c = 0;
- legajo_ant = legajo;
- }*/
- return 0;
- }
- /*
- input >> legajo >> nota >> materia >> fecha;
- do {
- legajo_ant = legajo;
- do {
- a = a + nota;
- c++;
- input >> legajo >> nota >> materia >> fecha;
- } while (input.good() and legajo == legajo_ant);
- output << legajo_ant << ' ' << a/c << '\n';
- a = 0;
- c = 0;
- } while (input.good());
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement