COSC 1436 Lab 5

Purpose: This lab focuses on writing a C++ programs that using pointers and dynamically created arrays.

Due: Section 2: Before class on February 26, Section 3: Before class on February 28

Requirements C++ Programs: There are two parts of this lab. Make sure your part A works completely before starting on Part B.

Part A. You will be writing a C++ program for this lab that uses pointers, dynamically created arrays, and modifications to dynamically created arrays. There are three data files, that are in comma delimited format, that contain varying numbers of words. For example the first file looks like this:

12,Apple,fruit,dog,cat,car,tree,Pill,forty,keep,help,test,zoo

 

What this means is that this file contains 12 words, with a comma separating each of the words. You will not know how many words are in the file, until you open and process the file. In fact, one of the files will have over 180,000 words in it.

Your task is to read the file into a dynamically created array. After the file is completely stored, pass that array to a subroutine or subroutines that will find the word or words that have the most vowels (use a, e, i, o, u as vowels), and return that word or those words to the calling program in a dynamically created array that is returned (not passed by reference), to the calling program. The calling program will then print those word(s) and the number of vowels that each has.

You must use defensive coding, there may be more or less words in the file than the first number given. If there are more words in the file than the number of words given at the beginning of the file, stop processing the file when the number of words exceeds what was given at the front of the file. If there are less words than the number of words at the beginning of the file, stop processing when you run out of words.

Remember that any dynamically created arrays must be properly deleted before the program closes.

You may use the string class or c-strings to complete this assignment.

The program must be well documented. Please include a text file of your program processing the three example files, with a file name of lab04XXX.txt, where the XXX is your initials.

Hint: the getline( ) function makes it easy to process comma delimited material, see section 12.5 of your text for an example.

Here are the three example word files. The files the grader will test your program on will be different in size, but be in the same file format. I suggest you test with the first file and after that works properly test with the larger files.

Part B. In the second part of this lab, you will be modifying your first program to allow your user to add additional words to the array. The requirements are as follows:

Provide a user interface that allows the user to add additional words to the array. The user must be able to add one or more words to the array from the keyboard (use a loop).

After the user adds the word, call a function that takes the existing array, adds the new word to the array, and then returns the expanded array. The function prototype for the function should be: void addWord(string * saWords, int & iSize, string sNewWord) The string pointer will be used to receive the existing array and then after modification pass back the new array. The size must be passed by reference, to allow the function to increase the size of the array. Remember to do this, the following steps are required:

You should then call the function that finds the word with the most vowels and output the results. The user should then be asked if they want to add another word to the array.

Lab Report. Prepare a lab report that contains the following information:

Submission: You will be submitting this lab via Blackboard, as demonstrated in class. You will need to zip your files together and then upload your zipped submission to Blackboard. Make sure you include the source code and the rest of the documentation package, but not the executable files.

Grading Criteria: 100 points available for this lab. The lab grader will be using this grading criteria to grade your programs. Here is a C++ style guide from Dr. Fernandez that should assist you in coding your program. Style guide.

Bonus Points. Bonus points will be awarded for outstanding user interface.