CPP
51
strings 2
Guest on 20th April 2022 02:08:30 AM
// For C++ libraries.
#include <iostream>
// Library for strings.
#include<string>
// The c standard library, math and time libraries are needed.
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;
int randomItem(int max) {
// Set the randomization seed to be based on the current time in seconds in Jan 1, 1970.
srand((unsigned)time(0));
// Pick a random number from 0 to max.
return rand()%max;
}
int main() {
string days[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday",
"Saturday"};
string verbs[]={"Went","Walked","Drove"};
string nouns[]={"to School","to Work","Home"};
int day,verb,noun;
day=randomItem(7);
verb=randomItem(3);
noun=randomItem(3);
cout << "On " << days[day] << " I " << verbs[verb] << " " << nouns[noun] << endl;
return 0;
}