Question: File I/O Data contained in files can easily be processed by computer programs. In this lab, you will use C++ ifstream object to read a

File I/O

Data contained in files can easily be processed by computer programs. In this lab, you will use C++ ifstream object to read a text file (with whitespace as delimiter). Using the stream object you use to read the file, you should extract the words in the file.

A string is an object that represents sequence of characters. You need to find the sum of all the ASCII values of characters in a word and display them to console. Also, you need to keep track of the number of words you process in the file.

Hint: You may want to use the size() member function to obtain the length of a string.

What is given: A text file named lab10test.txt in txt format

What you need to do:

Write a C++ program that

Reads the given text file. Counts the total number of words in the file.

Finds the sum of the ASCII values of each character in every word.

Sorts the words based on their ASCII sums in increasing order. (You can use the bubble sort algorithm here.)

What your program should display:

Each word along with its ASCII sum, in increasing order.

Print the total number of words in the file to the console.

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!