Skip to content

Commit 3ed3e88

Browse files
author
Tyler Boyd
committed
Changes to come closer to spec
1 parent f92e5db commit 3ed3e88

File tree

6 files changed

+157
-36
lines changed

6 files changed

+157
-36
lines changed

compile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
g++ source/* -o mark

include/student.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ using namespace std;
88
class Student {
99
public:
1010
vector<Mark> OAs;
11-
Mark final_mark;
11+
vector<Mark> Exams;
12+
vector<Mark> Summatives;
13+
Mark final_mark();
14+
Mark final_mark(int units);
15+
Mark term_mark(int units);
16+
Mark term_mark();
17+
Mark exam_mark();
18+
Mark summative_mark();
1219
char* Type;
1320
char* a;
1421
};

mark

76.9 KB
Binary file not shown.

output.csv

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
last;first name;4;3;3;3-;4-;3+;79.1667
4+
last;first name;3;4+;4;4;4+;5;90.8333
5+
last;first name;2;4-;4-;4+;4+;3+;83.8333
6+
last;first name;4;4-;4;4+;4+;4+;91.6667
7+
last;first name;4+;4+;4;4+;4+;4-;92.5
8+
last;first name;4;2;3+;4-;4;4-;82.1667
9+
last;first name;4;4+;4+;4+;4+;5;95
10+
last;first name;4;4-;4+;4+;4+;4+;92.5
11+
last;first name;4;4+;4+;4+;4+;4+;94.1667
12+
last;first name;4-;4;4+;4+;4+;5;93.3333
13+
last;first name;4-;3+;4-;4;4+;4;87.1667
14+
last;first name;4;3;4-;4-;4;4;85.8333
15+
last;first name;4;3-;4;4;3+;3;82.5
16+
last;first name;R;4-;4-;4+;5;5;83.3333
17+
last;first name;5;4;4+;4+;4+;4+;95
18+
last;first name;3+;3;3+;4+;4+;4-;84.3333
19+
last;first name;2;4;4-;3+;3+;4;81
20+
last;first name;4+;4;4+;4+;4+;5;95
21+
last;first name;5;4+;5;5;4+;4+;97.5
22+
last;first name;5;3;4;4+;4+;5;92.5
23+
last;first name;4+;1-;3;1+;R;1-;61.1667
24+
last;first name;4+;4+;4+;4+;4+;5;95.8333
25+
last;first name;4+;3+;4+;4+;4+;5;93

source/main.cpp

+25-35
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,10 @@ int main() {
1212
vector<vector<char*>*>* prows = csv->rows();
1313

1414
int rows = prows->size();
15-
16-
rows = prows->size();
17-
cout << "Rows: " << rows << endl;
18-
19-
if(rows == 0)
20-
{
21-
cout << "No rows found in CSV file...aborting" << endl;
22-
return 1;
23-
}
24-
2515
int columns = prows->at(0)->size();
26-
cout << "Columns: " << columns << endl;
2716

28-
if(columns == 0)
29-
{
30-
cout << "No columns found in CSV file...aborting" << endl;
31-
return 2;
32-
}
33-
34-
// PRINT ALL DATA IN MEMORY
35-
// for(int row = 0; row < rows; row++)
36-
// {
37-
// vector<char*>* columns = prows->at(row);
38-
// for(int column = 0; column < columns->size(); column++)
39-
// {
40-
// cout << columns->at(column);
41-
// if(column + 1 < columns->size())
42-
// cout << ";";
43-
// }
44-
// cout << endl;
45-
// }
46-
47-
cout << "\n\nHeaders found:\n\n";
4817
vector<char*> *headers = csv->headers();
18+
4919
for(int row = 0; row < prows->size(); row++)
5020
{
5121
Student *new_student = new Student;
@@ -60,22 +30,42 @@ int main() {
6030
{
6131
new_student->OAs.push_back(Mark(columns->at(col)));
6232
}
33+
else if(strncmp(headers->at(col), "E", 1) == 0)
34+
{
35+
new_student->Exams.push_back(Mark(columns->at(col)));
36+
}
37+
else if(strncmp(headers->at(col), "S", 1) == 0)
38+
{
39+
new_student->Summatives.push_back(Mark(columns->at(col)));
40+
}
6341
}
6442
students.push_back(new_student);
6543
}
6644

6745
for(int i=0; i<students.size(); i++)
6846
{
6947
Student* student = students.at(i);
70-
float sum = 0.0f;
48+
// float sum = 0.0f;
7149
cout << "Student # " << i << endl;
7250
for(int ioa = 0; ioa < student->OAs.size(); ioa++)
7351
{
74-
sum += student->OAs.at(ioa).to_int();
52+
// sum += student->OAs.at(ioa).to_int();
7553
cout << "O.A: " << student->OAs.at(ioa).to_int() << endl;
7654
}
77-
float average = sum / float(student->OAs.size());
78-
cout << "Average mark: " << average << endl << endl << endl;
55+
for(int ie = 0; ie < student->Exams.size(); ie++)
56+
{
57+
int exmark = student->Exams.at(ie).to_int();
58+
if(exmark < 0)
59+
cout << "Exam: Absent" << endl;
60+
else
61+
cout << "Exam: " << exmark << endl;
62+
}
63+
for(int is = 0; is < student->Summatives.size(); is++)
64+
{
65+
cout << "Summative: " << student->Summatives.at(is).to_int() << endl;
66+
}
67+
// float average = sum / float(student->OAs.size());
68+
cout << "First 3 terms mark: " << student->term_mark(3).to_int() << endl << endl << endl;
7969
}
8070

8171
ofstream outfile("output.csv");

source/student.cpp

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#include "../include/student.h"
2+
3+
Mark Student::final_mark()
4+
{
5+
float term_mark = this->term_mark().to_int();
6+
float exam_mark = this->exam_mark().to_int();
7+
float summative_mark = this->summative_mark().to_int();
8+
9+
float final = term_mark * 0.7f + exam_mark * 0.2f + summative_mark * 0.1f;
10+
return Mark(int(final + 0.5f));
11+
}
12+
13+
Mark Student::final_mark(int units)
14+
{
15+
16+
}
17+
18+
Mark Student::term_mark()
19+
{
20+
int n_oas = OAs.size();
21+
float term_mark = 0.0f;
22+
if(n_oas > 0)
23+
{
24+
for(int i=0; i < n_oas; i++)
25+
{
26+
term_mark += float(OAs.at(i).to_int());
27+
}
28+
term_mark /= n_oas;
29+
}
30+
return Mark(int(term_mark + 0.5f));
31+
}
32+
33+
Mark Student::term_mark(int units)
34+
{
35+
int max_oas = OAs.size();
36+
float term_mark = 0.0f;
37+
for(int i=0; i<units && i<max_oas; i++)
38+
{
39+
term_mark += float(OAs.at(i).to_int());
40+
}
41+
if(units > max_oas)
42+
{
43+
if(max_oas > 0)
44+
return Mark(int(term_mark/float(max_oas) + 0.5f));
45+
else
46+
return Mark(0);
47+
}
48+
if(units > 0)
49+
return Mark(int(term_mark/float(units) + 0.5f));
50+
else
51+
return Mark(0);
52+
}
53+
54+
Mark Student::exam_mark()
55+
{
56+
float exam_mark = 0.0f;
57+
int n_exams = Exams.size();
58+
if(n_exams > 0)
59+
{
60+
int exams_present = 0;
61+
for(int i=0; i < n_exams; i++)
62+
{
63+
if(Exams.at(i).to_int() >= 0)
64+
{
65+
exam_mark += float(Exams.at(i).to_int());
66+
exams_present++;
67+
}
68+
}
69+
if(exams_present > 0)
70+
exam_mark /= float(exams_present);
71+
else
72+
exam_mark = 0;
73+
}
74+
return Mark(int(exam_mark + 0.5f));
75+
}
76+
77+
Mark Student::summative_mark()
78+
{
79+
float summative_mark = 0.0f;
80+
int n_summatives = Summatives.size();
81+
if(n_summatives > 0)
82+
{
83+
int summatives_present = 0;
84+
for(int i=0; i < n_summatives; i++)
85+
{
86+
if(Summatives.at(i).to_int() >= 0)
87+
{
88+
summative_mark += float(Summatives.at(i).to_int());
89+
summatives_present++;
90+
}
91+
}
92+
if(summatives_present > 0)
93+
summative_mark /= float(summatives_present);
94+
else
95+
summative_mark = 0;
96+
}
97+
return Mark(int(summative_mark + 0.5f));
98+
}

0 commit comments

Comments
 (0)