Question: 2) Write a program int_list.cpp that uses a stringstream to help add up some integers and compute an average a) The input will be rows

 2) Write a program int_list.cpp that uses a stringstream to help

2) Write a program int_list.cpp that uses a stringstream to help add up some integers and compute an average a) The input will be rows of 4 integers each, separated by commas. You could pretend these are for quarterly reports b) The output, after a simple explanatory message, includes the sum for each row, then the average of these sums c) #include and d) Among your variables, declare an istringstream to store each line e) Use the version of getline() that takes an input stream and a string - getline(istream, string) - to read each line of input into a string The notes about getline() are wrong. The end of line character is read in, but it is just not included in the string f) Use the stringstream's clear() function to reset it, then pass the string storing the line into the stringstream using the str() function g) Now you can use >> to read in the next integer, then the next char (to skip the commas) . The input is guaranteed to be of the right format Sample run Use stringstreams to parse comma-separated integers Enter rows of 4 integers, each followed by a comma 1,2,3,4, The row's sum = 10 -1, 0, - 2 0 , The row's sum = -3 AZ Avg row sum = 3.5

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!