Skip to content

Commit bf3e4e5

Browse files
authored
feat: remove part 3 from making the grade (#937)
[no important files changed]
1 parent eee09fd commit bf3e4e5

File tree

5 files changed

+52
-114
lines changed

5 files changed

+52
-114
lines changed

exercises/concept/making-the-grade/.docs/hints.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,19 @@ Also being familiar with the following can help with completing the tasks:
2222

2323
- A results counter does need to be set up and _incremented_ -- you'll want to `return` the count of non-passing students when the loop terminates.
2424

25-
## 3. The "Best"
26-
27-
- - Having an empty `vector` to add the "best" marks to is helpful here.
28-
- `<vector>.emplace_back()` can help add things to the results `vector`.
29-
30-
## 4. Calculating Letter Grades
25+
## 3. Calculating Letter Grades
3126

3227
- These are _lower thresholds_. The _lower threshold_ for a "D" is a score of **41**, since an "F" is **<= 40**.
3328
- `static_cast<int>` without parameters should round off increments nicely.
3429
- You are expected to return an array, not a vector.
3530

36-
## 5. Matching Names to Scores
31+
## 4. Matching Names to Scores
3732

3833
- If both containers are the same length and sorted the same way, could you use the `index` from one to retrieve a `value` from the other?
3934
- `std::to_string(int)` can be used to convert a number to string.
4035
- Don't forget the follow the format of the example's output.
4136

42-
## 6. A "Perfect" Score
37+
## 5. A "Perfect" Score
4338

4439
- There may be or may not be a student with a score of 100, and you can't return an empty string without checking **all** scores.
4540
- The `control flow` statements `continue` and `break` may be useful here to move past unwanted values.

exercises/concept/making-the-grade/.docs/instructions.md

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,7 @@ count_failed_students({90,40,55,70,30,25,80,95,38,40});
4242
// => 5
4343
```
4444
45-
## 3. The "Best"
46-
47-
The teacher you're assisting wants to find the group of students who've performed "the best" on this exam.
48-
What qualifies as "the best" fluctuates, so you need to find the student scores that are **greater than or equal to** the current threshold.
49-
50-
Create the function `above_threshold()` taking `student_scores` (a `vector` of grades), and `threshold` (an `int`, the "top score" threshold) as parameters.
51-
This function should return a `vector` of all scores that are `>=` to `threshold`.
52-
53-
```cpp
54-
above_threshold({90,40,55,70,30,68,70,75,83,96}, 75);
55-
// => {90,75,83,96}
56-
```
57-
58-
## 4. Calculating Letter Grades
45+
## 3. Calculating Letter Grades
5946
6047
The teacher you're assisting likes to assign letter grades as well as numeric scores.
6148
Since students rarely score 100 on an exam, the "letter grade" lower thresholds are calculated based on the highest score achieved, and increment evenly between the high score and the failing threshold of **<= 40**.
@@ -96,7 +83,7 @@ The remaining score range, from 41 to the highest score, should be divided into
9683
- Divide this total range by 4 to get the size of each grade interval.
9784
- Add this interval size to 40 repeatedly to calculate the lower bounds for each letter grade.
9885

99-
## 5. Matching Names to Scores
86+
## 4. Matching Names to Scores
10087

10188
You have exam scores in descending order, and the respective student names (sorted in the order of their exam scores).
10289
You would like to match each student's name with their exam score and print out an overall class ranking.
@@ -114,7 +101,7 @@ student_ranking(student_scores, student_names)
114101
// {"1. Joci: 100", "2. Sara: 99", "3. Kora: 90", "4. Jan: 84", "5. Indra: 66", "6. Bern: 53", "7. Fred: 47"}
115102
```
116103
117-
## 6. A "Perfect" Score
104+
## 5. A "Perfect" Score
118105
119106
Although a "perfect" score of 100 is rare on an exam, it is interesting to know if at least one student has achieved it.
120107

exercises/concept/making-the-grade/.meta/exemplar.cpp

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,51 @@
55
// Round down all provided student scores.
66
std::vector<int> round_down_scores(std::vector<double> student_scores) {
77
std::vector<int> rounded{};
8-
for(int i{}; i < student_scores.size(); ++i)
8+
for (int i{}; i < student_scores.size(); ++i)
99
rounded.emplace_back(student_scores.at(i));
1010
return rounded;
1111
}
1212

13-
1413
// Count the number of failing students out of the group provided.
1514
int count_failed_students(std::vector<int> student_scores) {
1615
int counter{};
17-
for(int i{}; i < student_scores.size(); ++i) {
18-
if (student_scores.at(i) < 41)
19-
++counter;
16+
for (int i{}; i < student_scores.size(); ++i) {
17+
if (student_scores.at(i) < 41) ++counter;
2018
}
2119
return counter;
2220
}
2321

24-
// Determine how many of the provided student scores were 'the best' based on the provided threshold.
25-
std::vector<int> above_threshold(std::vector<int> student_scores, int threshold) {
26-
std::vector<int> above{};
27-
for(int i{}; i < student_scores.size(); ++i) {
28-
if (student_scores.at(i) >= threshold)
29-
above.emplace_back(student_scores.at(i));
30-
}
31-
32-
return above;
33-
}
34-
3522
// Create a list of grade thresholds based on the provided highest grade.
3623
std::array<int, 4> letter_grades(int highest_score) {
3724
std::array<int, 4> grades{};
38-
for(int i{}, lower_threshold{41}, step_size{(highest_score - 40) / 4};
39-
i < 4; ++i) {
25+
for (int i{}, lower_threshold{41}, step_size{(highest_score - 40) / 4};
26+
i < 4; ++i) {
4027
grades.at(i) = lower_threshold + step_size * i;
4128
}
4229
return grades;
4330
}
4431

4532
// Organize the student's rank, name, and grade information in ascending order.
46-
std::vector<std::string> student_ranking(std::vector<int> student_scores, std::vector<std::string> student_names) {
33+
std::vector<std::string> student_ranking(
34+
std::vector<int> student_scores, std::vector<std::string> student_names) {
4735
std::vector<std::string> ranking{};
48-
for(int i{}; i < student_scores.size(); ++i) {
49-
ranking.emplace_back(std::to_string(i + 1) + ". " + student_names.at(i) + ": " + std::to_string(student_scores.at(i)));
50-
}
51-
36+
for (int i{}; i < student_scores.size(); ++i) {
37+
ranking.emplace_back(std::to_string(i + 1) + ". " +
38+
student_names.at(i) + ": " +
39+
std::to_string(student_scores.at(i)));
40+
}
41+
5242
return ranking;
5343
}
5444

55-
// Create a string that contains the name of the first student to make a perfect score on the exam.
56-
std::string perfect_score(std::vector<int> student_scores, std::vector<std::string> student_names) {
45+
// Create a string that contains the name of the first student to make a perfect
46+
// score on the exam.
47+
std::string perfect_score(std::vector<int> student_scores,
48+
std::vector<std::string> student_names) {
5749
std::vector<std::string> ranking{};
58-
for(int i{}; i < student_scores.size(); ++i) {
59-
if (student_scores.at(i) == 100)
60-
return student_names.at(i);
61-
}
62-
50+
for (int i{}; i < student_scores.size(); ++i) {
51+
if (student_scores.at(i) == 100) return student_names.at(i);
52+
}
53+
6354
return "";
6455
}

exercises/concept/making-the-grade/making_the_grade.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,29 @@ std::vector<int> round_down_scores(std::vector<double> student_scores) {
88
return {};
99
}
1010

11-
1211
// Count the number of failing students out of the group provided.
1312
int count_failed_students(std::vector<int> student_scores) {
1413
// TODO: Implement count_failed_students
1514
return 0;
1615
}
1716

18-
// Determine how many of the provided student scores were 'the best' based on the provided threshold.
19-
std::vector<int> above_threshold(std::vector<int> student_scores, int threshold) {
20-
// TODO: Implement above_threshold
21-
return {};
22-
}
23-
2417
// Create a list of grade thresholds based on the provided highest grade.
2518
std::array<int, 4> letter_grades(int highest_score) {
2619
// TODO: Implement letter_grades
2720
return {};
2821
}
2922

3023
// Organize the student's rank, name, and grade information in ascending order.
31-
std::vector<std::string> student_ranking(std::vector<int> student_scores, std::vector<std::string> student_names) {
24+
std::vector<std::string> student_ranking(
25+
std::vector<int> student_scores, std::vector<std::string> student_names) {
3226
// TODO: Implement student_ranking
3327
return {};
3428
}
3529

36-
// Create a string that contains the name of the first student to make a perfect score on the exam.
37-
std::string perfect_score(std::vector<int> student_scores, std::vector<std::string> student_names) {
30+
// Create a string that contains the name of the first student to make a perfect
31+
// score on the exam.
32+
std::string perfect_score(std::vector<int> student_scores,
33+
std::vector<std::string> student_names) {
3834
// TODO: Implement perfect_score
3935
return "";
4036
}

exercises/concept/making-the-grade/making_the_grade_test.cpp

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -49,65 +49,29 @@ TEST_CASE("Count failed students (some failed)", "[task_2]") {
4949
REQUIRE(expected == actual);
5050
}
5151

52-
TEST_CASE("Test threshold (empty)", "[task_3]") {
53-
vector<int> input{};
54-
int threshold{98};
55-
vector<int> expected{};
56-
vector<int> actual = above_threshold(input, threshold);
57-
58-
REQUIRE(expected == actual);
59-
}
60-
61-
TEST_CASE("Test threshold (some above threshold)", "[task_3]") {
62-
vector<int> input{88, 29, 91, 64, 78, 43, 41, 77, 36, 50};
63-
int threshold{80};
64-
vector<int> expected{88, 91};
65-
vector<int> actual = above_threshold(input, threshold);
66-
67-
REQUIRE(expected == actual);
68-
}
69-
70-
TEST_CASE("Test threshold (none above threshold)", "[task_3]") {
71-
vector<int> input{88, 29, 91, 64, 78, 43, 41, 77, 36, 50};
72-
int threshold{99};
73-
vector<int> expected{};
74-
vector<int> actual = above_threshold(input, threshold);
75-
76-
REQUIRE(expected == actual);
77-
}
78-
79-
TEST_CASE("Test threshold (some on threshold)", "[task_3]") {
80-
vector<int> input{88, 29, 91, 64, 78, 43, 41, 77, 80, 80};
81-
int threshold{80};
82-
vector<int> expected{88, 91, 80, 80};
83-
vector<int> actual = above_threshold(input, threshold);
84-
85-
REQUIRE(expected == actual);
86-
}
87-
88-
TEST_CASE("Test letter grades: 100", "[task_4]") {
52+
TEST_CASE("Test letter grades: 100", "[task_3]") {
8953
int input{100};
9054
array<int, 4> expected{41, 56, 71, 86};
9155
array<int, 4> actual = letter_grades(input);
9256

9357
REQUIRE(expected == actual);
9458
}
95-
TEST_CASE("Test letter grades: 97", "[task_4]") {
59+
TEST_CASE("Test letter grades: 97", "[task_3]") {
9660
int input{97};
9761
array<int, 4> expected{41, 55, 69, 83};
9862
array<int, 4> actual = letter_grades(input);
9963

10064
REQUIRE(expected == actual);
10165
}
102-
TEST_CASE("Test letter grades: 81", "[task_4]") {
66+
TEST_CASE("Test letter grades: 81", "[task_3]") {
10367
int input{81};
10468
array<int, 4> expected{41, 51, 61, 71};
10569
array<int, 4> actual = letter_grades(input);
10670

10771
REQUIRE(expected == actual);
10872
}
10973

110-
TEST_CASE("Rank one student", "[task_5]") {
74+
TEST_CASE("Rank one student", "[task_4]") {
11175
vector<int> grades{82};
11276
vector<string> names{"Betty"};
11377
vector<string> expected{"1. Betty: 82"};
@@ -116,37 +80,42 @@ TEST_CASE("Rank one student", "[task_5]") {
11680
REQUIRE(expected == actual);
11781
}
11882

119-
TEST_CASE("Rank several student", "[task_5]") {
83+
TEST_CASE("Rank several student", "[task_4]") {
12084
vector<int> grades{100, 98, 92, 86, 70, 68, 67, 60};
121-
vector<string> names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"};
122-
vector<string> expected{"1. Rui: 100", "2. Betty: 98", "3. Joci: 92", "4. Yoshi: 86",
123-
"5. Kora: 70", "6. Bern: 68", "7. Jan: 67", "8. Rose: 60"};
85+
vector<string> names{"Rui", "Betty", "Joci", "Yoshi",
86+
"Kora", "Bern", "Jan", "Rose"};
87+
vector<string> expected{"1. Rui: 100", "2. Betty: 98", "3. Joci: 92",
88+
"4. Yoshi: 86", "5. Kora: 70", "6. Bern: 68",
89+
"7. Jan: 67", "8. Rose: 60"};
12490
vector<string> actual = student_ranking(grades, names);
12591

12692
REQUIRE(expected == actual);
12793
}
12894

129-
TEST_CASE("No perfect score", "[task_6]") {
95+
TEST_CASE("No perfect score", "[task_5]") {
13096
vector<int> grades{11, 34, 92, 23, 70, 76, 67, 60};
131-
vector<string> names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"};
97+
vector<string> names{"Rui", "Betty", "Joci", "Yoshi",
98+
"Kora", "Bern", "Jan", "Rose"};
13299
string expected{""};
133100
string actual = perfect_score(grades, names);
134101

135102
REQUIRE(expected == actual);
136103
}
137104

138-
TEST_CASE("One perfect score", "[task_6]") {
105+
TEST_CASE("One perfect score", "[task_5]") {
139106
vector<int> grades{11, 34, 92, 23, 70, 76, 67, 100};
140-
vector<string> names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"};
107+
vector<string> names{"Rui", "Betty", "Joci", "Yoshi",
108+
"Kora", "Bern", "Jan", "Rose"};
141109
string expected{"Rose"};
142110
string actual = perfect_score(grades, names);
143111

144112
REQUIRE(expected == actual);
145113
}
146114

147-
TEST_CASE("Several perfect scores", "[task_6]") {
115+
TEST_CASE("Several perfect scores", "[task_5]") {
148116
vector<int> grades{11, 100, 92, 23, 70, 100, 67, 100};
149-
vector<string> names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"};
117+
vector<string> names{"Rui", "Betty", "Joci", "Yoshi",
118+
"Kora", "Bern", "Jan", "Rose"};
150119
string expected{"Betty"};
151120
string actual = perfect_score(grades, names);
152121

0 commit comments

Comments
 (0)