Skip to content

Commit

Permalink
format: reformat for clang conformity
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeng committed Jan 28, 2025
1 parent bf83150 commit f6f24dd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
40 changes: 21 additions & 19 deletions exercises/concept/making-the-grade/.meta/exemplar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,51 @@
// Round down all provided student scores.
std::vector<int> round_down_scores(std::vector<double> student_scores) {
std::vector<int> rounded{};
for(int i{}; i < student_scores.size(); ++i)
for (int i{}; i < student_scores.size(); ++i)
rounded.emplace_back(student_scores.at(i));
return rounded;
}


// Count the number of failing students out of the group provided.
int count_failed_students(std::vector<int> student_scores) {
int counter{};
for(int i{}; i < student_scores.size(); ++i) {
if (student_scores.at(i) < 41)
++counter;
for (int i{}; i < student_scores.size(); ++i) {
if (student_scores.at(i) < 41) ++counter;
}
return counter;
}

// Create a list of grade thresholds based on the provided highest grade.
std::array<int, 4> letter_grades(int highest_score) {
std::array<int, 4> grades{};
for(int i{}, lower_threshold{41}, step_size{(highest_score - 40) / 4};
i < 4; ++i) {
for (int i{}, lower_threshold{41}, step_size{(highest_score - 40) / 4};
i < 4; ++i) {
grades.at(i) = lower_threshold + step_size * i;
}
return grades;
}

// Organize the student's rank, name, and grade information in ascending order.
std::vector<std::string> student_ranking(std::vector<int> student_scores, std::vector<std::string> student_names) {
std::vector<std::string> student_ranking(
std::vector<int> student_scores, std::vector<std::string> student_names) {
std::vector<std::string> ranking{};
for(int i{}; i < student_scores.size(); ++i) {
ranking.emplace_back(std::to_string(i + 1) + ". " + student_names.at(i) + ": " + std::to_string(student_scores.at(i)));
}

for (int i{}; i < student_scores.size(); ++i) {
ranking.emplace_back(std::to_string(i + 1) + ". " +
student_names.at(i) + ": " +
std::to_string(student_scores.at(i)));
}

return ranking;
}

// Create a string that contains the name of the first student to make a perfect score on the exam.
std::string perfect_score(std::vector<int> student_scores, std::vector<std::string> student_names) {
// Create a string that contains the name of the first student to make a perfect
// score on the exam.
std::string perfect_score(std::vector<int> student_scores,
std::vector<std::string> student_names) {
std::vector<std::string> ranking{};
for(int i{}; i < student_scores.size(); ++i) {
if (student_scores.at(i) == 100)
return student_names.at(i);
}

for (int i{}; i < student_scores.size(); ++i) {
if (student_scores.at(i) == 100) return student_names.at(i);
}

return "";
}
10 changes: 6 additions & 4 deletions exercises/concept/making-the-grade/making_the_grade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ std::vector<int> round_down_scores(std::vector<double> student_scores) {
return {};
}


// Count the number of failing students out of the group provided.
int count_failed_students(std::vector<int> student_scores) {
// TODO: Implement count_failed_students
Expand All @@ -22,13 +21,16 @@ std::array<int, 4> letter_grades(int highest_score) {
}

// Organize the student's rank, name, and grade information in ascending order.
std::vector<std::string> student_ranking(std::vector<int> student_scores, std::vector<std::string> student_names) {
std::vector<std::string> student_ranking(
std::vector<int> student_scores, std::vector<std::string> student_names) {
// TODO: Implement student_ranking
return {};
}

// Create a string that contains the name of the first student to make a perfect score on the exam.
std::string perfect_score(std::vector<int> student_scores, std::vector<std::string> student_names) {
// Create a string that contains the name of the first student to make a perfect
// score on the exam.
std::string perfect_score(std::vector<int> student_scores,
std::vector<std::string> student_names) {
// TODO: Implement perfect_score
return "";
}
17 changes: 11 additions & 6 deletions exercises/concept/making-the-grade/making_the_grade_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,20 @@ TEST_CASE("Rank one student", "[task_4]") {

TEST_CASE("Rank several student", "[task_4]") {
vector<int> grades{100, 98, 92, 86, 70, 68, 67, 60};
vector<string> names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"};
vector<string> expected{"1. Rui: 100", "2. Betty: 98", "3. Joci: 92", "4. Yoshi: 86",
"5. Kora: 70", "6. Bern: 68", "7. Jan: 67", "8. Rose: 60"};
vector<string> names{"Rui", "Betty", "Joci", "Yoshi",
"Kora", "Bern", "Jan", "Rose"};
vector<string> expected{"1. Rui: 100", "2. Betty: 98", "3. Joci: 92",
"4. Yoshi: 86", "5. Kora: 70", "6. Bern: 68",
"7. Jan: 67", "8. Rose: 60"};
vector<string> actual = student_ranking(grades, names);

REQUIRE(expected == actual);
}

TEST_CASE("No perfect score", "[task_5]") {
vector<int> grades{11, 34, 92, 23, 70, 76, 67, 60};
vector<string> names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"};
vector<string> names{"Rui", "Betty", "Joci", "Yoshi",
"Kora", "Bern", "Jan", "Rose"};
string expected{""};
string actual = perfect_score(grades, names);

Expand All @@ -101,7 +104,8 @@ TEST_CASE("No perfect score", "[task_5]") {

TEST_CASE("One perfect score", "[task_5]") {
vector<int> grades{11, 34, 92, 23, 70, 76, 67, 100};
vector<string> names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"};
vector<string> names{"Rui", "Betty", "Joci", "Yoshi",
"Kora", "Bern", "Jan", "Rose"};
string expected{"Rose"};
string actual = perfect_score(grades, names);

Expand All @@ -110,7 +114,8 @@ TEST_CASE("One perfect score", "[task_5]") {

TEST_CASE("Several perfect scores", "[task_5]") {
vector<int> grades{11, 100, 92, 23, 70, 100, 67, 100};
vector<string> names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"};
vector<string> names{"Rui", "Betty", "Joci", "Yoshi",
"Kora", "Bern", "Jan", "Rose"};
string expected{"Betty"};
string actual = perfect_score(grades, names);

Expand Down

0 comments on commit f6f24dd

Please sign in to comment.