Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exam2.c
Go to the documentation of this file.
1 #include <hddm_x.h>
2 
3 int report(x_HDDM_t *tscript);
4 
5 int main()
6 {
7  x_iostream_t* fp;
8  x_HDDM_t* tscript;
9  x_Student_t* student;
10  x_Enrolleds_t* enrolleds;
11  x_Courses_t* courses;
12  x_Result_t* result;
13  string_t name;
14  string_t grade;
15  string_t course;
16  int i;
17 
18  fp = init_x_HDDM("exam2.hddm");
19  for (i=0;i<1000000;i++) {
20 
21  // first build the complete nodal structure for this record
22  tscript = make_x_HDDM();
23  tscript->student = student = make_x_Student();
24  student->enrolleds = enrolleds = make_x_Enrolleds(99);
25  enrolleds->mult = 1;
26  enrolleds->in[0].courses = courses = make_x_Courses(99);
27  courses->mult = 3;
28  courses->in[0].result = make_x_Result();
29  courses->in[1].result = make_x_Result();
30  courses->in[2].result = make_x_Result();
31 
32  // now fill in the attribute data for this record
33  name = (char*)malloc(30);
34  strcpy(name,"Humphrey Gaston");
35  student->name = name;
36  enrolleds->in[0].year = 2005;
37  enrolleds->in[0].semester = 2;
38  courses->in[0].credits = 3;
39  course = (char*)malloc(30);
40  courses->in[0].title = strcpy(course,"Beginning Russian");
41  grade = (char*)malloc(5);
42  courses->in[0].result->grade = strcpy(grade,"A-");
43  courses->in[0].result->Pass = 1;
44  courses->in[1].credits = 1;
45  course = (char*)malloc(30);
46  courses->in[1].title = strcpy(course,"Bohemian Poetry");
47  grade = (char*)malloc(5);
48  courses->in[1].result->grade = strcpy(grade,"C");
49  courses->in[1].result->Pass = 1;
50  courses->in[2].credits = 4;
51  course = (char*)malloc(30);
52  courses->in[2].title = strcpy(course,"Developmental Psychology");
53  grade = (char*)malloc(5);
54  courses->in[2].result->grade = strcpy(grade,"B+");
55  courses->in[2].result->Pass = 1;
56 
57  // now open a file and write this one record into it
58  flush_x_HDDM(tscript,fp);
59  }
60  close_x_HDDM(fp);
61 
62  // try reading it back in from the output file just written
63  fp = open_x_HDDM("exam2.hddm");
64  int count=0;
65  while ((tscript = read_x_HDDM(fp)) != 0) {
66  if (count/100000*100000 == count) {
67  printf("event %d\n", count);
68  report(tscript);
69  }
70  ++count;
71  }
72  printf("finished after %d events read.\n", count);
73  return 0;
74 }
75 
76 int report(x_HDDM_t *tscript)
77 {
78  x_Student_t* student = tscript->student;
79  x_Enrolleds_t* enrolleds = student->enrolleds;
80  x_Courses_t* courses = enrolleds->in[0].courses;
81  int total_courses = courses->mult;
82  int total_enrolled = 0;
83  int total_credits = 0;
84  int total_passed = 0;
85  int i;
86  for (i=0;i<total_courses;++i) {
87  if (courses->in[i].result->Pass) {
88  if (enrolleds->in[0].year > 1992) {
89  total_credits += courses->in[i].credits;
90  }
91  ++total_passed;
92  }
93  }
94  printf("%s enrolled in %d courses and passed %d of them,\n",
95  student->name, total_courses, total_passed);
96  printf("earning a total of %d credits.\n", total_credits);
97  return 0;
98 }
printf("string=%s", string)
int main(int argc, char *argv[])
Definition: gendoc.cc:6
int report(x_HDDM_t *tscript)
Definition: exam2.c:76