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

Function main

Exercises/Modules/Chapter 08/Soln8_06.cpp:48–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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