Thursday, July 9, 2009

C++ program which uses random number generator to create sentences?

I'm not going to write any code for you, but I've got some ideas.





If you don't care whether the program uses real words, then implementation should be pretty easy.





First, for each sentence, have the program decide how many words should be in the sentence. Then, for each word, have the program decide how many letters should be in the word. The program should alternate between consonants and vowels in order to ensure that the gibberish is still pronouncable. The program could also have a set probability for inserting parenthesis or commas, perhaps 1 in 7 for a comma and 1 in 40 for parenthesis. Be sure that the first word in the sentence begins with a capital letter. At the end of the sentence, the program should decide whether to end with a period, question mark, or exclamation point. You can then repeat for however many random sentences you would like.





Now, if you want the program to use REAL words, you'll have to do a bit more work. First, you'll need a list of words, a "dictionary" so to speak. This will need to contain a lot of information if you want to make sentences using real words. You'll need information about its part of speech (noun, verb, adjective, adverb, interjection, etc.), gender (masculine, feminine, neuter), if the word is a verb whether it has any irregular forms or whether the verb is transitive or intransitive, if the word is a noun whether it has irregular plurals (e.g. "datum" and "data", or "goose" and "geese") or whether it's a proper noun none, some, or all of the time, if the word is an adjective whether it can be made into an adverb by adding -ly, and basically information for any other question that might come up when making a sentence. That's probably more than enough work right there. BUT, once that's taken care of, the program can use the random number generator along with the rules of grammer to make a sentence "framework", then simply select random words of the right part of speech to "fill in the blanks". For example:





(?article?) (?adjective?) (noun) (?adverb?) (verb) (?article?) (?adjective?) (?noun?)





The question marks indicate optional parts of speech for such a framework sentence. The program might make sentences like the following:





A blue apricot graciously impregnates the tall monkeys.


The car likes reality.


Barns reluctently hold a safe hose.


A baby vomits.





If you get really advanced, you can create other "sentence frameworks":





(?article?) (?adjective?) (noun) was (?adverb?) (verb-past_participle) ?by? (?article?) (?adjective?) (?noun-posessive?) (?article?) (?adjective?) (?noun?)





A velvet god was almost smashed by the delicious boss's happy dollars.


Matthew was totally x-rayed by butter.


A red vending machine was inflated by pride.


The rediculous baseballs were swallowed.





In conclusion, you'll have to apply all of your linguistic knowledge and problem solving skills -- not to mention a lot of time -- on this one. Actually it sounds like something I'd like to try. E-mail me if you're interested.

C++ program which uses random number generator to create sentences?
Look here I cant give you tha answer but i can give the code for a similar program. Here it is:





/* Magic.cpp */


/* This program generates a random number and gets input


from user. If both match say "Magic" else "You know no


magic" */


#include %26lt;iostream.h%26gt;


#include %26lt;conio.h%26gt;





#include %26lt;stdlib.h%26gt;





int generate();


void main()


{


int rand_no;


int input_no;


clrscr();





cout%26lt;%26lt;"What do you think is the Magic Number in my mind : ";


cin%26gt;%26gt;input_no;





rand_no = generate();


if(rand_no == input_no)


cout%26lt;%26lt;"Woow! You are quite a magician!!!";


else


cout%26lt;%26lt;"Phoof! You know no magic!!!";


getch();


}





int generate()


{


int rand_no;


rand_no = rand();


return rand_no;


}


No comments:

Post a Comment