1
1
#include " ../include/harrizcsv.h"
2
2
#include " ../include/mark.h"
3
3
#include " ../include/student.h"
4
+ #include " ../include/resource.h"
4
5
5
6
using namespace std ;
6
7
7
- int main () {
8
+ int main (int argc, char **argv)
9
+ {
10
+ char *lpFn = new char [1024 ];
11
+ char *only = new char [256 ];
12
+ char *exclude = new char [256 ];
13
+ char *outputFn = new char [1024 ];
14
+
15
+ strcpy (lpFn, " data/SCHS21-1.csv" );
16
+ strcpy (outputFn, " data/output.csv" );
17
+
18
+ int n_terms = 0 ;
19
+ char c;
20
+ while ((c = getopt (argc, argv, " :f:n:e:i" )) != -1 )
21
+ {
22
+ switch (c)
23
+ {
24
+ case ' f' :
25
+ strncpy (lpFn, optarg , 256 );
26
+ break ;
27
+ case ' n' :
28
+ sscanf (optarg , " %d" , &n_terms);
29
+ break ;
30
+ case ' e' :
31
+ strncpy (exclude, optarg , 256 );
32
+ break ;
33
+ case ' i' :
34
+ strncpy (only, optarg , 256 );
35
+ break ;
36
+ case ' ?' :
37
+ if (optopt == ' f' || optopt == ' n' || optopt == ' e' || optopt == ' i' )
38
+ fprintf (stderr, " Option -%c requires an argument.\n " , optopt );
39
+ else
40
+ fprintf (stderr, " Unknown option %c.\n " , optopt );
41
+ return 1 ;
42
+ default :
43
+ break ;
44
+ }
45
+ }
46
+
47
+ printf (" file path: \" %s\"\n " , lpFn);
48
+ printf (" only: \" %s\"\n " , only);
49
+ printf (" exclude: \" %s\"\n " , exclude);
50
+ printf (" n_terms: %d\n " , n_terms);
51
+
8
52
HarrizCSV* csv = new HarrizCSV ();
9
- csv->read (" data/SCHS21-1.csv " );
53
+ csv->read (lpFn );
10
54
vector<Student*> students;
11
55
12
56
vector<vector<char *>*>* prows = csv->rows ();
@@ -39,17 +83,30 @@ int main() {
39
83
new_student->Summatives .push_back (Mark (columns->at (col)));
40
84
}
41
85
}
42
- students.push_back (new_student);
86
+ char * full_name = new char [1024 ];
87
+ strcpy (full_name, new_student->Type );
88
+ strcat (full_name, new_student->a );
89
+
90
+ bool add = true ;
91
+ if (strlen (only))
92
+ {
93
+ add = strstr (full_name, only) == 0 ;
94
+ }
95
+ if (strlen (exclude))
96
+ {
97
+ if (strstr (full_name, exclude) == 0 )
98
+ add = false ;
99
+ }
100
+ if (add)
101
+ students.push_back (new_student);
43
102
}
44
103
45
104
for (int i=0 ; i<students.size (); i++)
46
105
{
47
106
Student* student = students.at (i);
48
- // float sum = 0.0f;
49
- cout << " Student # " << i << endl;
107
+ cout << " Student name: " << student->Type << " " << student->a << endl;
50
108
for (int ioa = 0 ; ioa < student->OAs .size (); ioa++)
51
109
{
52
- // sum += student->OAs.at(ioa).to_int();
53
110
cout << " O.A: " << student->OAs .at (ioa).to_int () << endl;
54
111
}
55
112
for (int ie = 0 ; ie < student->Exams .size (); ie++)
@@ -64,26 +121,73 @@ int main() {
64
121
{
65
122
cout << " Summative: " << student->Summatives .at (is).to_int () << endl;
66
123
}
67
- // float average = sum / float(student->OAs.size());
68
- cout << " First 3 terms mark: " << student->term_mark (3 ).to_int () << endl << endl << endl;
124
+ if (n_terms > 0 ) {
125
+ cout << " Term mark: " << student->term_mark (n_terms).to_int () << endl;
126
+ cout << " Final mark: " << student->final_mark (n_terms).to_int () << endl << endl << endl;
127
+ }
128
+ else {
129
+ cout << " Term mark: " << student->term_mark ().to_int () << endl;
130
+ cout << " Final mark: " << student->final_mark ().to_int () << endl << endl << endl;
131
+ }
69
132
}
70
133
71
- ofstream outfile (" output.csv " );
134
+ ofstream outfile (outputFn );
72
135
73
- outfile << endl << endl;
136
+ int n_summatives = students.at (0 )->Summatives .size ();
137
+ int n_exams = students.at (0 )->Exams .size ();
138
+ if (n_terms > 0 ) {
139
+ outfile << " First name" << " ;" << " Last name" << " ;" ;
140
+ for (int i=0 ; i<n_terms; i++)
141
+ outfile << " O.A" << i+1 << " ;" ;
142
+ for (int i=0 ; i<n_summatives; i++)
143
+ outfile << " Summative #" << i+1 << " ;" ;
144
+ for (int i=0 ; i<n_exams; i++)
145
+ outfile << " Exam #" << i+1 << " ;" ;
74
146
75
- for (int i=0 ; i<students.size (); i++)
147
+ outfile << " ;;Term mark (" << n_terms << " terms);Final mark" << endl;
148
+
149
+ for (int i=0 ; i<students.size (); i++)
150
+ {
151
+ Student* student = students.at (i);
152
+ outfile << student->Type << " ;" << student->a << " ;" ;
153
+ for (int iterm = 0 ; iterm < n_terms && iterm < student->OAs .size (); iterm++)
154
+ outfile << student->OAs .at (iterm).to_int () << " ;" ;
155
+ for (int isum = 0 ; isum < n_summatives; isum++)
156
+ outfile << student->Summatives .at (isum).to_int () << " ;" ;
157
+ for (int iex = 0 ; iex < n_exams; iex++)
158
+ outfile << student->Exams .at (iex).to_int () << " ;" ;
159
+ outfile << " ;;" << student->term_mark (n_terms).to_int () << " ;" ;
160
+ outfile << student->final_mark (n_terms).to_int ();
161
+ outfile << endl;
162
+ }
163
+ }
164
+ else
76
165
{
77
- Student* student = students.at (i);
78
- float sum = 0 .0f ;
79
- outfile << student->Type << " ;" << student->a ;
80
- for (int ioa = 0 ; ioa < student->OAs .size (); ioa++)
166
+ n_terms = students.at (0 )->OAs .size ();
167
+ outfile << " First name" << " ;" << " Last name" << " ;" ;
168
+ for (int i=0 ; i<n_terms; i++)
169
+ outfile << " O.A" << i+1 << " ;" ;
170
+ for (int i=0 ; i<n_summatives; i++)
171
+ outfile << " Summative #" << i+1 << " ;" ;
172
+ for (int i=0 ; i<n_exams; i++)
173
+ outfile << " Exam #" << i+1 << " ;" ;
174
+
175
+ outfile << " ;;Term mark (all terms);Final mark" << endl;
176
+
177
+ for (int i=0 ; i<students.size (); i++)
81
178
{
82
- sum += student->OAs .at (ioa).to_int ();
83
- outfile << " ;" << student->OAs .at (ioa).to_string ();
179
+ Student* student = students.at (i);
180
+ outfile << student->Type << " ;" << student->a << " ;" ;
181
+ for (int iterm = 0 ; iterm < student->OAs .size (); iterm++)
182
+ outfile << student->OAs .at (iterm).to_int () << " ;" ;
183
+ for (int isum = 0 ; isum < n_summatives; isum++)
184
+ outfile << student->Summatives .at (isum).to_int () << " ;" ;
185
+ for (int iex = 0 ; iex < n_exams; iex++)
186
+ outfile << student->Exams .at (iex).to_int () << " ;" ;
187
+ outfile << " ;;" << student->term_mark (n_terms).to_int () << " ;" ;
188
+ outfile << student->final_mark (n_terms).to_int ();
189
+ outfile << endl;
84
190
}
85
- float average = sum / float (student->OAs .size ());
86
- outfile << " ;" << average << endl;
87
191
}
88
192
89
193
outfile.close ();
0 commit comments