Question: Please Help, I am especially struggling with function 3 First - this program's whole purpose is to be able to follow directions to create silly

Please Help, I am especially struggling with function 3

First - this program's whole purpose is to be able to follow directions to create silly sentences. Many times a programmer needs to create something that is specific to user requirements even when it may not be useful elsewhere. This is that program!

What we are going to do is create four word sentences that consist of an article, noun, verb, and adverb. The words will be predefined and stored in arrays. The program will randomly select words and put them together in a sentence. For example: The article array may contain the values This That A The the program would then need to generate a random number between 0 and 3 (the size of the array). If the random number is a 2, then the first word in the sentence would be A. The program would then randomly select a noun from the array of nouns, a verb, and an adverb respectively. These will then be concatenated together into one sentence (in that order).

After creating the silly sentence it may need some grammatical correction and adjustments to correct it then after all sentences are created, they will be printed. Well be doing some functions to make this program easier to do.

It is imperative you follow these instructions if you miss a step your program may fail.

Step 1: The word arrays: These arrays will be set up as const arrays before int main. For example, the article array you will have:

const int NUMART=4; // number of items in the article array

const string ARTICLES[]={The, This, A, That};

You will need to set up the constants for the other types of words. Be SURE to keep the words in the same order!! Note: While we are using static arrays here - these are still considered data. You may not use these values or the positions of the values in the program itself. That is considered hard coding data.

nouns: "giraffe","tiger","fox","panther","aardvark","bear"

verbs: "ate", "marched","slept"

adverbs: "heartily", "quickly","backward", slowly

Step 2: The functions we will be building functions to make this program easier to do. You must create and use these functions. The functions are listed below under the "Functions Required" section.

Step 3: The main program will create an array of sentences (max of 20 sentence). The user will input how many sentences to generate. The sentences will be constructed and then corrected. Some sentences may start with the article "A" followed by a noun that starts with a vowel. That is grammatically incorrect. So, if the main program determines a sentence begins with the article A, it will call the correct sentence function to finalize it. Otherwise, the sentence is unaltered. As the sentences are finalized, they will be stored in the array of sentences and printed using the print function.

Functions Required

Do NOT name your functions function1, function 2, etc. Use good names that indicate what they do.

Function 1 - Pick a word. This function takes one of the word arrays (article, noun, etc) as an array of strings (remember its const), and the number of words in the array as parameters. The function will then randomly select one of the words and return it as a string. You will seed the random number generator in the main program not in this function.

Function 2 Create a sentence. This function takes no parameters and returns a string that contains a sentence of four words. The first word is an article, the second word a noun, the third word is a verb and the fourth would is an adverb. You must use function 1 to generate the words. Concatenate the words into a sentence and return the sentence.

IMPORTANT NOTE: It is very important to force the computer to execute function1 for the articles, noun, verb, and adverb in that order so the random numbers work correctly. There are several ways to do this and the safest is probably to create temp variables such as string article then call the function to get the article. After you have created each of the words THEN concatenate them together.

Function 3 Correct a sentence. The article An is deliberately left out of the list of articles. The main program is going to check to see if the sentence starts with the article A. If it does, this function will be called. This function is going to correct the sentences where the noun begins with a vowel. The rules for this function are as follows:

If the noun in the sentence begins with a vowel, replace the article A with An. For our purposes, vowels will be a, e, i, o, u.

Otherwise, if the noun does NOT begin with a vowel, we are going to generate a new verb and replace the verb in the sentence with a new verb (you will need to use function 1 to get a new verb). Why are we doing this? Just because the instructions say to.

This function will be a void function. There will be one parameter the string sentence. Since the corrected sentence will need be returned in the original string, the parameter will need to be a reference parameter.

Function 4 Print the array of sentences: This is a void function that takes two parameters: the array of sentences (strings) as well as the integer indicating how many sentences there are in the array. It will go through the array printing out each final sentence. You may ONLY print the sentences from this function. They may NOT be printed directly in the main program, but rather by calling this function.

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!