Question: 17.2 Programming Fundamentals 2 Assessment 1 (1) Prompt the user to enter five numbers, being five people's weights. Store the numbers in a vector of

17.2 Programming Fundamentals 2 Assessment 1

(1) Prompt the user to enter five numbers, being five people's weights. Store the numbers in a vector of doubles. Output the vector's numbers on one line, each number followed by one space. (2 pts) Example output:

 

(2) Also define and call a double returning function, weightSummary, that accepts the vector as a parameter, and does the following

(a) output the total weight, by summing the vector's elements. (1 pt)

(b) output the average of the vector's elements. (1 pt)

(c) output the max vector element. (2 pts)

(d) returns the sum of the total weight, average and max vector element. (4 pts) ** Quick note: weightSummary is already called for you in the starter code below**

Example Output:

 

You may code your solution in your C++ compiler, then copy and paste it in the editor below to test and submit

When running the program here in zyBooks, type your test data in the INPUT box below

#include // include vector library using namespace std;

//Function prototype double weightSummary(vector);

int main() { vector list1; //Do NOT modify this vector declaration /* Type your code here. */ double w; for(int i = 0; i < 5; i++) { cin >> w; list1.push_back(w); } for(int i = 0; i < list1.size(); i++) { cout << list1[i] << " "; } cout << endl; //Do NOT modify these last two statements double showResults = weightSummary(list1); return 0; }

//Function definition double weightSummary(vector v){ // Type your code here { double sum = 0, max = v[0]; for(int i = 0; i < v.size(); i++) { sum += v[i]; if(v[i] > max) { max = v[i]; } } double average = sum / v.size(); cout << "total weight = " << sum << endl; cout << "average = " << average << endl; cout << "max = " << max << endl; return sum + average + max; } }

Enter program input (optional)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!