forked from josemariasola/StringNAndBlockStream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlockStreamDriver.cpp
45 lines (36 loc) · 1.09 KB
/
BlockStreamDriver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* BlockStreamDriver.cpp
Escribe y lee archivo de registros, y muestra los cursos de
primer año con cantidad de alumnos mayor a 25.
2015-11-08 - 2018-06-30
Esp. Ing. José María Sola
Profesor
UTN FRBA */
#include <iostream>
#include "BlockStream.h"
int main(){
struct Curso{
char especialidad;
int codigo;
int nivel;
int alumnos;
double promedio;
};
constexpr auto filename{"cursos"};
std::ofstream out{filename, std::ios::binary};
WriteBlock(out, Curso{'K', 1051, 1, 29, 7.8});
WriteBlock(out, Curso{'R', 4152, 4, 41, 6.6});
WriteBlock(out, Curso{'K', 2051, 1, 22, 6.7});
WriteBlock(out, Curso{'K', 2011, 1, 26, 7.9});
out.close();
std::ifstream in{filename, std::ios::binary};
for(Curso curso; ReadBlock(in, curso) ;)
if( curso.nivel == 1 and curso.alumnos > 25 )
std::cout
<< "Especialidad: " << curso.especialidad << ", "
<< " Código: " << curso.codigo << ", "
<< " Nivel: " << curso.nivel << ", "
<< " Alumnos: " << curso.alumnos << ", "
<< " Promedio: " << curso.promedio << '\n'
<< '\n';
in.close();
}