Question
Need corrections to the following C++ code so that it adheres to the requirements attached: #include #include #include class VectorOperations { private: std::vector numbers; public:
Need corrections to the following C++ code so that it adheres to the requirements attached:
#include
#include
#include
class VectorOperations {
private:
std::vector
public:
void getInput() {
for (int i = 0; i
int num;
cin>>num; numbers.push_back(num);
}
}
void displaySortedElements() {
std::sort(numbers.begin(), numbers.end());
std::cout
for (int i = 0; i
std::cout
}
std::cout
}
void displaySmallestElement() {
int smallest = numbers[0];
for (int i = 1; i
if (numbers[i]
smallest = numbers[i];
}
}
std::cout
}
void displayLargestElement() {
int largest = numbers[0];
for (int i = 1; i
if (numbers[i] > largest) {
largest = numbers[i];
}
}
std::cout
}
void displayTotal() {
int total = 0;
for (int i = 0; i
total += numbers[i];
}
std::cout
}
void displayAverage() {
int total = 0;
for (int i = 0; i
total += numbers[i];
}
double average = (double) total / 5;
std::cout
}
};
int main() {
VectorOperations obj;
obj.getInput();
obj.displaySortedElements();
obj.displaySmallestElement();
obj.displayLargestElement();
obj.displayTotal();
obj.displayAverage();
return 0;
}
- Prompt the user for 5 integer values - Stores the elements in a vector - Displays the sorted elements - Displays the smallest element - Displays the largest element - Displays the total of all elements - Displays the average of all the elements
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started