MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / main

Function main

Exercises/NoModules/Chapter 08/Soln8_06.cpp:47–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45const unsigned NOT_AVAILABLE = std::numeric_limits<unsigned>::max();
46
47int main()
48{
49 std::vector<unsigned> grades;
50
51 std::cout << "Please enter a number of grades (0-100), terminated by a negative one:" << std::endl;
52 while (true)
53 {
54 int number{};
55 std::cin >> number;
56 if (number < 0)
57 break;
58 else if (number > 100)
59 std::cout << "Only numbers < 100, please..." << std::endl;
60 else
61 grades.push_back(number);
62 }
63
64 sort(grades);
65
66 // Note: thruth be told, this is based on an old solution.
67 // It would be better and/or easier
68 // a) to use std::array<> instead of C-style arrays; and
69 // b) to return the values requested rather than using output parameters
70 // Perhaps you can improve our solution accordingly?
71 unsigned highest[5]{};
72 unsigned lowest[5]{};
73
74 getHighest(grades, highest);
75 getLowest(grades, lowest);
76
77 printNumbers("Five highest grades", highest);
78 printNumbers("Five lowest grades", lowest);
79 printNumber("The grade average", computeAverage(grades));
80 printNumber("The median grade", computeMedian(grades));
81 printNumber("The standard deviation of the grades", computeStandardDeviation(grades));
82 printNumber("The variance of the grades", computeVariance(grades));
83}
84
85// Swap numbers at position first with address at position second
86void swap(std::vector<unsigned>& numbers, size_t first, size_t second)

Callers

nothing calls this directly

Calls 10

sortFunction · 0.70
getHighestFunction · 0.70
getLowestFunction · 0.70
printNumbersFunction · 0.70
printNumberFunction · 0.70
computeAverageFunction · 0.70
computeMedianFunction · 0.70
computeStandardDeviationFunction · 0.70
computeVarianceFunction · 0.70
push_backMethod · 0.45

Tested by

no test coverage detected