Lab 10: The one after nine

In this lab we are going to be working with Arrays and Structs again. This time, we are going to be working on the concept of "finding" within an array.

Details

For this lab, you will have an input source that will give you a name of file that you are to open and read. That input file will contain a string and a double that you are to store in an array of structures. The struct in this case will have a string and a double. This is very similar to the struct from lab 9. In fact, you can probably use that struct for this lab. The reading of the string and double will be the same as you did last time too. In fact you can probably use lab9 as the starting point for this lab. Once you've read in the data into an array, then you will process commands that are in the istream that is given to the function.

For this lab, we are going to write a function with the same name as lab9, readData. This function will have the same signature:

void readData( istream& in, ostream& out );

The readData function, after it opens and reads the data file it was asked to read, will process a series of commands until they run out. There are 2 commands: find-name and find-number.

Commands

Command:

find-name <name>
This command will "search" the array and when the given name is found it will output the following message:
Found: <name> <number>\n
Where <name> is the name you were looking for and <number> is the number that was read in and stored with the number.

If the name is not found, then this message is output:

Not found: <name>\n
where <name> is the name you were looking for.

Command:

find-number <number>
This command will "search" the array and when the given number is found it will output the following message:
Found: <name> <number>\n
Where <name> is the name that was read in and stored with the number and <number> is the number that you were looking for.

If the number is not found, then this message is output:

Not found: <number>\n 
where <number> is the number you were looking for.

Attached is a set of sample files that you can use for your testing.

Input

This is what a sample input might look like commands.txt

filename: data.txt
find-name Dave
find-number 4.5
find-name Freda
find-number 3.14

This is what the contents of data.txt would look like data.txt

Dave 10.0
Molly 13.1
Matthew 3.2
Kelly 4.5

Output

Assuming that your program opened the data file that is in the example above and then processed the commands in the command file above, this would be the output:

Found: Dave 10.0
Found: Kelly 4.5
Not found: Freda
Not found: 3.14

Requirements

  1. You must implement your function in a file called lab10.h
  2. You must have the function void readData( istream& in, ostream& out); declared in the header.
  3. You must use an array of structs to store the data.
  4. The initial size of the array is 10.

Grading

Zip up your lab10.h and your implementation file and turn them in to web-cat.

Due

Like all labs, this is due on Tuesday November 4th, by 6:50. Submissions will no longer be accepted after 11:50AM on Friday November 7th.