Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C program. indentations and relevant comments should be included . Q2: (Random S

ID: 3703236 • Letter: C

Question

C program.

indentations and relevant comments should be included .

Q2: (Random Sentences) (25 points) Write a program that uses random number generation to create sentences. The program should use four arrays of pointers to char called article, noun, verb and preposition. The program should create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article and noun. As each word is picked, it should be concatenated to the previous words in an array large enough to hold the entire sentence. The words should be separated by spaces. When the final sentence

Explanation / Answer

here is your program : ------------->>>>>>>>>>>>>

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>


//this function generate a sentence from the given pointer arrays
char* generateSentence(char *art[5],char *noun[5],char *verb[5],char *prep[5]){
char *temp = (char *)malloc(sizeof(char)*100);//allocating space for the sentence 100 char
int n = rand()%5;//random number generate between 0-4
strcpy(temp,art[n]);//copying the random article and copying into temp char pointer
n = rand()%5;
strcat(temp," ");//copying space between two words
strcat(temp,noun[n]);//concatinating the random noun to temp char pointer
n = rand()%5;
strcat(temp," ");
strcat(temp,verb[n]);
n = rand()%5;
strcat(temp," ");
strcat(temp,prep[n]);
n = rand()%5;
strcat(temp," ");
strcat(temp,art[n]);
n = rand()%5;
strcat(temp," ");
strcat(temp,noun[n]);
strcat(temp,".");
temp[0] = (char)((int)temp[0] - 32);

return temp;
}

int main(){
//declaration of each arrays of pointer and initializing it
char *art[5] = {"the","a","one","some","any"};
char *noun[5] = {"cat","dog","truck","plane","skateboard"};
char *verb[5] = {"drove","jumped","ran","walked","flew"};
char *prep[5] = {"to","from","over","under","on"};
char *sentence[20];
int i;
//seeding the random
srand(time(0));

//generating 20 sentence and saving it in a sentence variable
for(i = 0;i<20;i++){
  sentence[i] = generateSentence(art,noun,verb,prep);
}

//printing the senteces
for(i = 0;i<20;i++){
  printf("%s ",sentence[i]);
}
}