HOMEWORK 09 - READING AND WRITING WITH DATA FILES

Concepts

In this homework, we will continue to practice file I/O, data manipulation, and while loops.

Overview

For this assignment, your job is to find the secret message hidden within a large file of words. To do this, we need to find the words that correspond to specific values. That is, you will read a value, search for a word in your input file that has the same value, and then print that word to an output file. You will then read the next value, search for the next word in your input file that has that value, and then print that word to an output file.

The Specifics

Points

In order to calculate how much a given word is worth, you need to know how many points each character in the word is worth. Here's the breakdown.

File Format

Your input files are formatted with one value/word per line. Your list of words, found in words.txt has one string, all lower-case, per line. Your list of word values that you are searching for in the encoded message, found in points.txt has one int per line. You should place these input files at the project level, which should be the same directory as your main.cpp file. You should see both your input files AND a .vcxproj file in the same directory.

Your output file, message.txt should have spaces separating each word (no newlines!).

Example

Here's an example

Words
in
you
are
tin
grade
awesome!
programming
is
pure

Points
80
40
130

Right off the bat you (as a person) know that there are 3 words in this secret message, because you are only given 3 point values. (Of course, the computer won't know there are 3 words until your program finishes executing.) One important thing to note is that you should not look at the top of your word list for each point value; in order words, each search will start where the previous search left off.

Let's run through this example:

Since there are no more point values to retrieve, your program is done (even though more words in your file exist). Your output file should read:

you are awesome!

Hints

Submission

You need to submit your solution of this homework (HW09) with two lab assignments: Lab09A and Lab09B. Detailed generic instructions for submitting homework assignments are available. For homework due this Wednesday, follow these specific steps: