Question
PLEASE. HELP. REALLY. NEEDED cannot figure out why my code is not matching the instructor output!!! Here is my code, #include #include #include #include #include
PLEASE. HELP. REALLY. NEEDED
cannot figure out why my code is not matching the instructor output!!!
Here is my code,
#include
//--------------------------------------------------------------------------------- const string NOUNS[]={ "giraffe", "tiger", "fox", "panther", "aardvark", "bear"}; const int numNOUN = 6; const string VERBS[]={"ate", "marched", "slept"}; const int numVERB = 3; const string ADVERBS[]={"heartily", "quickly", "backwards", "slowly"}; const int numADVERB = 4; const string ARTICLES[]= {"The", "This", "A", "That"}; const int numART = 4; //--------------------------------------------------------------------------------- string random_word(const string a[], const int x); string create_a_sentence(); void correct(string &); void print_sentences(string a[], int x); //----------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////// int main(){
int i, seed; int num_sentences = 0; int max_size = 20; string new_word; //seed the random number gen
cout > seed; srand(seed);
do{ cout > num_sentences; }while (num_sentences > max_size || num_sentences
//construct the sentences string sentence; string sentences[num_sentences]; for(i = 0; i
sentences[i].replace(index1 +1, length, newword + " "); } sentences[i] = sentence; }
//print the sentences print_sentences(sentences, num_sentences); }
//////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////// string random_word(const string a[], const int x){
string randomword; int word_index;
word_index = rand() % x; randomword = a[word_index];
return randomword; } ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////// string create_a_sentence(){
string rand_sentence; string s1, s2, s3, s4;
//article s1 = random_word(ARTICLES, numART); //cout
/oun s2 = random_word(NOUNS, numNOUN); //cout
///////////////////////////////////////////////////////////////////// void correct(string &a){ a.replace(0, 1, "An"); cout
//////////////////////////////////////////////////////////////////////// void print_sentences( string a[], int x){
int i = 0;
for(i = 0; i
Here are the assignment instructions:
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.
Making Silly Sentences
The program should begin by entering a seed for the random number generator and how many sentences should be created. You can generate between 1 and 20 sentences. Make sure the user inputs a number between 1 and 20.
"Enter a seed value for the random number generator ";
"Enter the number of sentences to create (1-20)";
After correctly getting the number of sentences, output an endl to force a new line on the output screen. The program will now create the silly sentences. The flow of the program goes like this:
Create a sentence (using function 2).
If the first article is an A, then correct the sentence (using function 3)
Store the finalized sentence in the array of sentences
Repeat this until all sentences are created
Now that all sentences are created, pass the array of sentences to the print function (function 4) and print them out.
Note: You must create a sentence, then correct it before creating another sentence. If you dont, your output won't match ours because of the random number generation.
PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE HELP
Result Your Output Instructor Output cmd line arg Enter a seed value for the random num| Enter a seed value for the random num This bear marched slowly That giraffe ate quickly The giraffe marched slowly The giraffe slept slowly This bear marched slowly That giraffe ate quickly The giraffe marched slowly The giraffe slept slowly 7114 4 cmd line arg Enter a seed value for the random n Enter a seed value for the random n That fox marched backwards The panther ate quickly That giraffe marched backwards The giraffe marched quickly A bear marched backwards This aardvark marched quickly The bear marched backwards An aardvark slept heartily The aardvark marched backwards A fox marched heartilv n aardvark slept quickly n aardvark ate slowly That fox marched backwards The panther ate quickly That giraffe marched backwards The giraffe marched quickly A bear marched backwards A panther marched quickly This aardvark slept heartily A niraffe marched harkwards 5432 20 cmd line arg Enter a seed value for the random num| Enter a seed value for the random num A fox slept backwards That giraffe slept quickly A fox marched backwards A bear ate quickly 543 50 -1 2 cmd line arg Enter a seed value for the random n Enter a seed value for the random n n aardvark marched heartily at tiger marched slowly The fox ate quickly An aardvark marched heartily That panther slept heartily This bear slept backwards A panther marched heartily That aardvark ate quickly This aardvark marched heartily The nanther slent heartilv That tiger marched slowly The fox ate quickly An aardvark marched heartily That panther slept heartily This bear slept backwards A panther marched heartily A panther marched quickly This aardvark marched quickly The fox ate heartily This hear marched harkwards 987 20 cmd line arg Enter a seed value for the random n Enter a seed value for the random n This tiger ate slowly That panther marched backwards The giraffe ate slowly A fox marched slowly This tiger ate slowly That panther marched backwards The giraffe ate slowly A fox marched slowly An aardvark marched heartily A fox slept backwards The giraffe marched slowly A fox ate heartily This aardvark slept slowly The hear slent slowlv 5843 0 15 he giraffe marched slowly e aardvark slept heartily A bear marched heartily That bear marched heartily A fox ate quickly The hear marched heartilv cmd line arg Enter a seed value for the random num| Enter a seed value for the random num That aardvark ate slowly That aardvark ate slowlyStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started