Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exam2.cpp
Go to the documentation of this file.
1 #include <fstream>
2 #include "hddm_x.hpp"
3 
4 int report(hddm_x::HDDM &xrec);
5 
6 int main()
7 {
8  hddm_x::HDDM xrec;
9  std::ofstream ofs("exam2.hddm");
10  hddm_x::ostream *ostr = new hddm_x::ostream(ofs);
11 
12  //ostr->setCompression(hddm_x::k_z_compression);
13 
14  for (int n=0; n<1000000; ++n) {
15  hddm_x::StudentList student = xrec.addStudents();
16  student().setName("Humphrey Gaston");
17  hddm_x::EnrolledList enrolled = student().addEnrolleds();
18  enrolled().setYear(2005);
19  enrolled().setSemester(2);
20  hddm_x::CourseList course = enrolled().addCourses(3);
21  course(0).setCredits(3);
22  course(0).setTitle("Beginning Russian");
23  course(0).addResults();
24  course(0).getResult().setGrade("A-");
25  course(0).getResult().setPass(true);
26  course(1).setCredits(1);
27  course(1).setTitle("Bohemian Poetry");
28  course(1).addResults();
29  course(1).getResult().setGrade("C");
30  course(1).getResult().setPass(1);
31  course(2).setCredits(4);
32  course(2).setTitle("Developmental Psychology");
33  course(2).addResults();
34  course(2).getResult().setGrade("B+");
35  course(2).getResult().setPass(true);
36  *ostr << xrec;
37  xrec.clear();
38  }
39  delete ostr;
40  ofs.close();
41 
42  // try reading it back in from the output file just written
43  std::ifstream ifs("exam2.hddm");
44  hddm_x::istream istr(ifs);
45  int count=0;
46  while (ifs.good()) {
47  istr >> xrec;
48  if (count/100000*100000 == count) {
49  std::cout << "event " << count << std::endl;
50  report(xrec);
51  }
52  ++count;
53  }
54  std::cout << "finished after " << count << " events read." << std::endl;
55  return 0;
56 }
57 
58 int report(hddm_x::HDDM &xrec)
59 {
60  hddm_x::CourseList courses = xrec.getCourses();
61  int total_courses = courses.size();
62  int total_enrolled = 0;
63  int total_credits = 0;
64  int total_passed = 0;
65  hddm_x::CourseList::iterator iter;
66  for (iter = courses.begin(); iter != courses.end(); ++iter) {
67  if (iter->getResult().getPass()) {
68  if (iter->getYear() > 1992) {
69  total_credits += iter->getCredits();
70  }
71  ++total_passed;
72  }
73  }
74  std::cout << courses().getName() << " enrolled in "
75  << total_courses << " courses "
76  << "and passed " << total_passed << " of them, " << std::endl
77  << "earning a total of " << total_credits
78  << " credits." << std::endl;
79  return 0;
80 }
int main(int argc, char *argv[])
Definition: gendoc.cc:6
int report(x_HDDM_t *tscript)
Definition: exam2.c:76