answersLogoWhite

0

Random sentence generator in c plus plus?

Updated: 8/17/2019
User Avatar

Wiki User

12y ago

Best Answer

#include <stdio.h>

#include <stdlib.h>

const char *noun[]={"boy", "girl", "dog", "town", "car"};

const char *verb[]={"drove", "jumped", "ran", "walked", "skipped"};

const char *preposition[]={"to", "from", "under", "over", "on"};

const char *article[]={"the", "a", "one", "some", "any"};

char sentence[50];

int main(void)

{

strcat(sentence, *(article+(rand() %5)));

strcat(sentence, " ");

strcat(sentence, *(noun+(rand() %5)));

strcat(sentence, " ");

strcat(sentence, *(verb+(rand() %5)));

strcat(sentence, " ");

strcat(sentence, *(preposition+(rand() %5)));

strcat(sentence, " ");

strcat(sentence, *(article+(rand() %5)));

strcat(sentence, " ");

strcat(sentence, *(noun+(rand() %5)));

printf("%s",sentence);

getch();

return 0;

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Random sentence generator in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Do I need random picture generator coding in c plus plus?

No.


What is srand in c plus plus?

Srand (seed random ) is used to seed random numbers and is used before calling the rand() or the random number generator. Seeding random numbers ensures that each time the code is executed the number generated is completely random. srand requires one parameter. For most cases it is sufficient to make this parameter time(NULL) [remember to include time.h] as this will seed a new bunch of random number every second


How do you enter a sentence as input in c plus plus?

Use the C++ getline() function from the standard library.


How do you create random numbers on c plus plus?

Random numbers can be generated by a pseudo-random number generator. As of C++11, the standard library provides several generators in the &lt;random&gt; header. The following demonstrates how to simulate 10 throws of a die. #include &lt;random&gt; #include &lt;iostream&gt; int main (void) { std::default_random_engine gen; std::uniform_int_distribution&lt;&gt; dist {1, 6}; // range of distribution [1:6] for (int n=0; n&lt;10; ++n) std::cout &lt;&lt; dist(gen) &lt;&lt; ' '; std::cout &lt;&lt; '\n'; } Example output: 1 1 6 5 2 2 5 5 6 2


Write a c program to print different number into a random order at number of compile times?

This program generates so called pseudo random numbers, and it used srand() function to connect the seed for the random number generator to the current. Which makes it less predictable but cannot claimed as a real random number generator.#include #include #include int main(){srand((unsigned) time(NULL));std::cout


How do you create functions with multiple parameters in C plus plus?

Random example, function with two parameters: int main (int argc, char **argv) {...}


Write a program to declare 10 variables randomly and fill the array evenly using c plus plus?

#include&lt;iostream&gt; #include&lt;chrono&gt; #include&lt;random&gt; #include&lt;vector&gt; int main() { std::vector&lt;int&gt; Array; unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); std::default_random_engine generator (seed); std::uniform_real_distribution&lt;int&gt; distribution (0,100); for (size_t index=0; index&lt;10; ++index) Array.push_back (distribution (generator)); }


What is randomize function in c plus plus?

You can use rand(). Make sure that you use srand()to generate the seed for rand() (if you do not, you get so called pseudo random numbers).


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Symplify c plus c plus c plus c?

4c