C++: Making the Grade: clean up methods

This commit is contained in:
Andrew Scott 2024-08-04 13:22:33 -04:00
parent 659cce59ff
commit 8a1efbaf0f
Signed by: a
GPG key ID: 7CD5A5977E4931C1

View file

@ -30,7 +30,7 @@ std::vector<int> above_threshold(std::vector<int> student_scores,
for (auto score : student_scores) {
if (score >= threshold)
res.push_back(score);
res.emplace_back(score);
}
return res;
@ -55,11 +55,11 @@ student_ranking(std::vector<int> student_scores,
std::vector<std::string> student_names) {
std::vector<std::string> res;
int rank = 1;
int len = student_scores.size();
for (int i{0}; i < student_scores.size(); i++, rank++) {
res.push_back(std::to_string(rank) + "." + " " + student_names[i] + ": " +
std::to_string(student_scores[i]));
for (int i{0}; i < len; i++) {
res.emplace_back(std::to_string(i + 1) + "." + " " + student_names[i] +
": " + std::to_string(student_scores[i]));
}
return res;
@ -70,7 +70,8 @@ student_ranking(std::vector<int> student_scores,
std::string perfect_score(std::vector<int> student_scores,
std::vector<std::string> student_names) {
for (int i{0}; i < student_scores.size(); i++) {
int len = student_scores.size();
for (int i{0}; i < len; i++) {
if (student_scores[i] == 100) {
return student_names[i];
}