Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Late night update! #54

Merged
merged 4 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions data/19120338.csv
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ MTH00040,3,7.5
BAA00103,2,8
CSC10008,4,8.5
,,
BAA00003,2,0
CSC10003,4,0
CSC10006,4,0
CSC10009,2,0
MTH00030,3,0
MTH00050,4,0
BAA00003,2,7
CSC10003,4,10
CSC10006,4,7
CSC10009,2,8.5
MTH00030,3,6.5
MTH00050,4,8
,,
CSC10007,4,0
CSC14003,4,0
CSC14007,4,0
CSC15005,4,0
CSC15006,4,0
MTH00035,4,0
50 changes: 5 additions & 45 deletions src/OutputHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void OutputHelper::printTable(
* If no data, don't print!
*
*/
if (tableData.size() == 0) {
if (tableData.size() <= 1) {
return;
}
hwangswan marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -140,7 +140,7 @@ void OutputHelper::printTable(
*
*/
if (_outputType & OutputConstants::FORMAT_TABLE) {
printTableFormat(tableData, true);
printTableFormat(tableData);
}

/**
Expand All @@ -152,51 +152,13 @@ void OutputHelper::printTable(
}
}

/**
* Print table, with conclusion
*
* @param const std::vector<std::vector<std::string>>&
* @param bool
*/
void OutputHelper::printTable(
const std::vector<std::vector<std::string>>& tableData,
bool conclusionIgnored) {
/**
* If no data, don't print!
*
*/
if (tableData.size() == 0) {
return;
}

/**
* Output in table format
* (without last conclusion row)
*
*/
if (_outputType & OutputConstants::FORMAT_TABLE) {
printTableFormat(tableData, false);
}


/**
* Output in CSV format
*
*/
if (_outputType & OutputConstants::FORMAT_CSV) {
printTableCSV(tableData);
}
}

/**
* Print a table, with format.
*
* @param const std::vector<std::vector<std::string>>&
* @param bool
*/
void OutputHelper::printTableFormat(
const std::vector<std::vector<std::string>>& tableData,
bool hasConclusion) {
const std::vector<std::vector<std::string>>& tableData) {
// Print table line (separator).
printSeparator();

Expand All @@ -211,10 +173,8 @@ void OutputHelper::printTableFormat(
printTableRow(tableData[i]);
}

// Print conclusion row.
if (hasConclusion) {
printSeparator();
}
// Print conclusion separating line.
printSeparator();

// Print last row.
printTableRow(tableData[tableData.size() - 1]);
Expand Down
11 changes: 1 addition & 10 deletions src/OutputHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ class OutputHelper {
* Print table in format.
*
* @param const std::vector<std::vector<std::string>>&
* @param bool (default = true: has conclusion)
*/
void printTableFormat(const std::vector<std::vector<std::string>>&, bool);
void printTableFormat(const std::vector<std::vector<std::string>>&);

public:
~OutputHelper();
Expand Down Expand Up @@ -112,13 +111,5 @@ class OutputHelper {
* @param const std::vector<std::vector<std::string>>>&
*/
void printTable(const std::vector<std::vector<std::string>>&);

/**
* Print the full table.
*
* @param const std::vector<std::vector<std::string>>>&
* @param bool (default = conclusion ignored)
*/
void printTable(const std::vector<std::vector<std::string>>&, bool);
};
#endif
48 changes: 38 additions & 10 deletions src/PersonalGPA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ PersonalGPA::PersonalGPA(
}

/**
* Return total credits
* Return total passed credits
*
* @return int
*/
int PersonalGPA::sumCredits() {
return _sumCredits;
int PersonalGPA::passedCredits() {
return _passedCredits;
}

/**
* Return total failed credits
*
* @return int
*/
int PersonalGPA::failedCredits() {
return _failedCredits;
}

/**
Expand All @@ -62,22 +71,39 @@ Grade PersonalGPA::resultGPA() {
}

/**
* Convert class to string vector.
* Convert passed list to string vector.
*
* @return std::vector<std::string>
*/
std::vector<std::string> PersonalGPA::toStringVector() {
std::vector<std::string> PersonalGPA::passedListToStringVector() {
std::vector<std::string> stringVector;

stringVector.push_back("Overall");
stringVector.push_back(std::to_string(_sumCredits));
stringVector.push_back(std::to_string(_passedCredits));
stringVector.push_back(_resultGPA.toString());
stringVector.push_back(_resultGPA.to4Scale().toString());
stringVector.push_back(_resultGPA.toAScale());

return stringVector;
}

/**
* Convert failed list to string vector
*
* @return std::vector<std::string>
*/
std::vector<std::string> PersonalGPA::failedListToStringVector() {
std::vector<std::string> stringVector;

stringVector.push_back("Overall");
stringVector.push_back(std::to_string(_failedCredits));
stringVector.push_back("None");
stringVector.push_back("None");
stringVector.push_back("None");

return stringVector;
}

/**
* Convert to vector of string vectors.
*
Expand All @@ -91,7 +117,7 @@ std::vector<std::vector<std::string>> PersonalGPA::toPassedVector() {
}

// Push overall.
resultVector.push_back(toStringVector());
resultVector.push_back(passedListToStringVector());

return resultVector;
}
Expand All @@ -108,6 +134,8 @@ std::vector<std::vector<std::string>> PersonalGPA::toFailedVector() {
resultVector.push_back(subject.toStringVector());
}

resultVector.push_back(failedListToStringVector());

return resultVector;
}

Expand Down Expand Up @@ -170,15 +198,15 @@ void PersonalGPA::addSubject(const Subject& subject) {
// If not passed, then insert into failed list.
if (!subject.passed()) {
_classesFailed.insert(subject);
_failedCredits += subject.credit();
return;
}

// Calculate new GPA.
_sumCredits += subject.credit();
_passedCredits += subject.credit();
_sumGrades += subject.grade() * subject.credit();
_resultGPA = _sumGrades / (1.0 * _sumCredits);
_resultGPA = _sumGrades / (1.0 * _passedCredits);

// Insert to passed list.
_classesPassed.insert(subject);
}

44 changes: 37 additions & 7 deletions src/PersonalGPA.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,26 @@
class PersonalGPA {
protected:
// Stores personal grades & credits.
int _sumCredits = 0;
Grade _sumGrades = 0.0;
Grade _resultGPA = 0.0;
int _passedCredits = 0;
int _failedCredits = 0;
Grade _sumGrades = 0.0;
Grade _resultGPA = 0.0;

// Stores classes passed / failed.
std::multiset<Subject> _classesPassed;
std::multiset<Subject> _classesFailed;

public:
/**
* Constructor for PersonalGPA
*
*/
PersonalGPA();

/**
* Destructor for PersonalGPA
*
*/
~PersonalGPA();

/**
Expand All @@ -45,11 +54,18 @@ class PersonalGPA {
PersonalGPA(const std::vector<Subject>&);

/**
* Return total credits
* Return total passed credits
*
* @return int
*/
int passedCredits();

/**
* Return total failed credits
*
* @return int
*/
int sumCredits();
int failedCredits();

/**
* Return sum grades.
Expand All @@ -66,11 +82,18 @@ class PersonalGPA {
Grade resultGPA();

/**
* Convert class to string vector.
* Convert passed list to string vector.
*
* @return std::vector<std::string>
*/
std::vector<std::string> toStringVector();
std::vector<std::string> passedListToStringVector();

/**
* Convert failed list to string vector.
*
* @return std::vector<std::string>>
*/
std::vector<std::string> failedListToStringVector();

/**
* Convert to vector of string vectors.
Expand All @@ -86,6 +109,13 @@ class PersonalGPA {
*/
std::vector<std::vector<std::string>> toFailedVector();

/**
* Return total credits
*
* @return int
*/
int getTotalPassedCredits();

/**
* Return total classes.
*
Expand Down
5 changes: 1 addition & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ int main(int argc, char* argv[]) {

// Print failed table.
OutputHelper::instance()
->printTable(
chumeochuixoong->toFailedVector(),
false
);
->printTable(chumeochuixoong->toFailedVector());
}

// And catch exceptions
Expand Down
2 changes: 2 additions & 0 deletions tests/output/0.out
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ Total failed classes: 6 (21.43%)
| BAA00003 | 2 | 0.00 | 0.00 | F |
| CSC10009 | 2 | 0.00 | 0.00 | F |
+------------+---------+--------------------+-------------------+-------------------+
| Overall | 19 | None | None | None |
+------------+---------+--------------------+-------------------+-------------------+
2 changes: 2 additions & 0 deletions tests/output/1.out
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ Total failed classes: 6 (21.43%)
| BAA00003 | 2 | 0.00 | 0.00 | F |
| CSC10009 | 2 | 0.00 | 0.00 | F |
+------------+---------+--------------------+-------------------+-------------------+
| Overall | 19 | None | None | None |
+------------+---------+--------------------+-------------------+-------------------+
2 changes: 2 additions & 0 deletions tests/output/2.out
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ Total failed classes: 3 (37.50%)
| CSC10006 | 4 | 0.00 | 0.00 | F |
| CSC10009 | 2 | 0.00 | 0.00 | F |
+------------+---------+--------------------+-------------------+-------------------+
| Overall | 10 | None | None | None |
+------------+---------+--------------------+-------------------+-------------------+
2 changes: 2 additions & 0 deletions tests/output/3.out
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ Total failed classes: 3 (12.00%)
| MTH00030 | 3 | 0.00 | 0.00 | F |
| BAA00003 | 2 | 0.00 | 0.00 | F |
+------------+---------+--------------------+-------------------+-------------------+
| Overall | 9 | None | None | None |
+------------+---------+--------------------+-------------------+-------------------+
1 change: 1 addition & 0 deletions tests/output/4.out
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ MTH00050,4,0.00,0.00,F
MTH00030,3,0.00,0.00,F
BAA00003,2,0.00,0.00,F
CSC10009,2,0.00,0.00,F
Overall,19,None,None,None
1 change: 1 addition & 0 deletions tests/output/5.out
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ MTH00050,4,0.00,0.00,F
MTH00030,3,0.00,0.00,F
BAA00003,2,0.00,0.00,F
CSC10009,2,0.00,0.00,F
Overall,19,None,None,None
1 change: 1 addition & 0 deletions tests/output/6.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ class code,credits,grade (10 - scale),grade (4 - scale),grade (A - scale)
CSC10003,4,0.00,0.00,F
CSC10006,4,0.00,0.00,F
CSC10009,2,0.00,0.00,F
Overall,10,None,None,None
1 change: 1 addition & 0 deletions tests/output/7.out
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ class code,credits,grade (10 - scale),grade (4 - scale),grade (A - scale)
MTH00050,4,0.00,0.00,F
MTH00030,3,0.00,0.00,F
BAA00003,2,0.00,0.00,F
Overall,9,None,None,None