Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions