2024-08-04 13:07:52 -04:00
|
|
|
#include <array>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
// Round down all provided student scores.
|
|
|
|
std::vector<int> round_down_scores(std::vector<double> student_scores) {
|
|
|
|
return std::vector<int>(student_scores.begin(), student_scores.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count the number of failing students out of the group provided.
|
|
|
|
int count_failed_students(std::vector<int> student_scores) {
|
|
|
|
|
|
|
|
int count{0};
|
|
|
|
|
|
|
|
for (auto score : student_scores) {
|
|
|
|
if (score <= 40)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine how many of the provided student scores were 'the best' based on
|
|
|
|
// the provided threshold.
|
|
|
|
std::vector<int> above_threshold(std::vector<int> student_scores,
|
|
|
|
int threshold) {
|
|
|
|
|
|
|
|
std::vector<int> res;
|
|
|
|
|
|
|
|
for (auto score : student_scores) {
|
|
|
|
if (score >= threshold)
|
2024-08-04 13:22:33 -04:00
|
|
|
res.emplace_back(score);
|
2024-08-04 13:07:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a list of grade thresholds based on the provided highest grade.
|
|
|
|
std::array<int, 4> letter_grades(int highest_score) {
|
|
|
|
|
|
|
|
int step{(highest_score - 40) / 4};
|
|
|
|
std::array<int, 4> grades{41, 0, 0, 0};
|
|
|
|
|
|
|
|
for (int i{1}; i < 4; ++i) {
|
|
|
|
grades[i] += grades[i - 1] + step;
|
|
|
|
}
|
|
|
|
|
|
|
|
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> res;
|
2024-08-04 13:22:33 -04:00
|
|
|
int len = student_scores.size();
|
2024-08-04 13:07:52 -04:00
|
|
|
|
2024-08-04 13:22:33 -04:00
|
|
|
for (int i{0}; i < len; i++) {
|
|
|
|
res.emplace_back(std::to_string(i + 1) + "." + " " + student_names[i] +
|
|
|
|
": " + std::to_string(student_scores[i]));
|
2024-08-04 13:07:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
|
2024-08-04 13:22:33 -04:00
|
|
|
int len = student_scores.size();
|
|
|
|
for (int i{0}; i < len; i++) {
|
2024-08-04 13:07:52 -04:00
|
|
|
if (student_scores[i] == 100) {
|
|
|
|
return student_names[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|