Write a program to compute the average of all the numbers stored in a text file. Assume the numbers are integers representing test scores, for example: XXXXXXXXXX XXXXXXXXXX 87 98 First use the...


Write a program to compute the average of all the numbers stored in a text file. Assume the numbers are integers representing test scores, for example:


70 85 90


92 57 100 88


87 98


First use the extraction operator, >>. Then use a WordStreamIterator object. Since WordStreamIterator::Current returns a string, you’ll need to convert the string to the corresponding integer; that is, the string "123" should be converted to the int 123. The function atoi in "strutils.h" in Howto G will convert the string.


int atoi(string s)


// pre: s represents an int, that is "123", "-457", etc.


// post: returns int equivalent of s


// if s isn’t properly formatted (that is "12a3")


// then 0 (zero) is returned

Nov 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here