
USING C++
Program Specifications: Write a program to calculate the minimum, maximum, mean, median, mode, and whether a
Step 0. Review the starter code in main(). A vector is filled with integers from standard input. The first value indicates how many numbers are to follow and be placed in the vector.
Step 1. Use a loop to process each vector element and output the minimum and maximum values. Submit for grading to confirm one test passes.
Ex: If the input is:
6 4 1 5 4 99 17
the output is:
Minimum: 1
Maximum: 99
Step 2. Use a loop to sum all vector elements and calculate the mean (or average). Output the mean with one decimal place using cout << fixed << setprecision(1); once before all other cout statements. Submit for grading to confirm two tests pass.
Ex: If the input is:
6 4 1 5 4 99 17
the output is:
Minimum: 1
Maximum: 99
Mean: 21.7
Step 3. Use a loop to determine if the vector is a palindrome, meaning values are the same from front to back and back to front. Output "true" or "false". Submit for grading to confirm three tests pass.
Ex: If the input is:
9 1 2 3 4 5 4 3 2 1
the output is:
Minimum: 1
Maximum: 5
Mean: 2.8
Palindrome: true
Step 4. main() includes a call to sort(), which sorts the vector elements into ascending order. Do not sort the vector before step 4. After sorting, identify the median. The median is located in the middle of the vector if the vector's size is odd. Otherwise, the median is the average of the middle two values. Output the median with one decimal place. Submit for grading to confirm four tests pass.
Ex: If the input is:
6 2 2 5 6 7 7
the output is:
Minimum: 2
Maximum: 7
Mean: 4.8
Palindrome: false
Median: 5.5
Step 5. Identify the mode after the vector is sorted in ascending order. The mode is the value that appears most frequently. Assume only one mode exists. Hint: Use a loop to process each vector element, looking for the longest sequence of identical values. Submit for grading to confirm all tests pass.
Ex: If the input is:
9 1 2 2 2 3 3 4 5 6
the output is:
Minimum: 1
Maximum: 6
Mean: 3.1
Palindrome: false
Median: 3.0
Mode: 2



Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 5 images

- I have a vector labeled Dengue_Vec. I need to code a for loop that will provide me with the number of characters in that vector. The characters are nucleotides so they are letters. -The first image is the clear question and the second one is while loop referenced in the question. thank you (I mainly don't understand how to iterate over nonnumerical values in a vector using the for loop or the while loop).arrow_forwardEvery data structure that we use in computer science has its weaknesses and strengthsHaving a full understanding of each will help make us better programmers!For this experiment, let's work with STL vectors and STL dequesFull requirements descriptions are found in the source code file Part 1Work with inserting elements at the front of a vector and a deque (30%) Part 2Work with inserting elements at the back of a vector and a deque (30%) Part 3Work with inserting elements in the middle, and removing elements from, a vector and a deque (40%) Please make sure to put your code specifically where it is asked for, and no where elseDo not modify any of the code you already see in the template file This C++ source code file is required to complete this problemarrow_forwardSelect all code lines that creates a vector with content {10, 10, 10, 10). You are also given the C-type array, an_array with content (10, 10, 10, 10). std::vector a_vector (an_array, an_array + sizeof(an_array)/sizeof(int)); std::vector a_vector [10, 10, 10, 10); std::vector a_vector (10, 4); std::vector a_vector = {10, 10, 10, 10); Ostd::vector a_vector (4, 10);arrow_forward
- Complete the following function that counts the even numbers in a 2D vector of integers. int count_evens(const std::vector<std::vector<int>>& v) { // Add your code... } Please add output screenshot!arrow_forwardnow the pros and cons of using arrays vs. vectors. Know how to build and use a 2d vector. Know what the "at" function does if you try to access memory beyond the bounds of the array.arrow_forwardc++arrow_forward
- Integers are read from input and stored into a vector until 0 is read. If the vector's last element is odd, output the odd elements in the vector. Otherwise, output the even elements in the vector. End each number with a newline. Ex: If the input is -9 12 -6 1 0, the vector's last element is 1. Thus, the output is: -9 1 Note: (x % 2 != 0) returns true if x is odd. int value; int i; bool isodd; 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 } cin >> value; while (value != 0) { } for (i = 0; i > value; Check return 0; 1 Next level 2 X 1: Compare output 3 4 For input -9 12 -6 1 0, the vector elements are -9, 12, -6, and 1. The last element, 1, is odd. The odd elements in the vector, -9 and 1, are output, each on a new line. Not all tests passed. 2 V 3arrow_forwardYou may insert an element into an arbitrary position inside a vector using an iterator. Write a function, insert(vector, value) which inserts value into its sorted position inside the vector. The function returns the vector after it is modified. #include <vector>using namespace std; vector<int>& insert(vector<int>& v, int value){ ................ return v; }arrow_forwardIntegers are read from input and stored into a vector until 0 is read. If the vector's last element is odd, output the odd elements in the vector. Otherwise, output the even elements in the vector. End each number with a newline. Ex: If the input is -9 12 -6 1 0, the vector's last element is 1. Thus, the output is: -9 1 Note: (x % 2!= 0) returns true if x is odd. 4 5 int main() { 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} vector vect1; int value; int i; bool isodd; cin >> value; while (value != 0) { vect1.push_back(value); cin >> value; } V* Your code goes here */ return 0; 2 3arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





