Skip to main content

Silly sentence

Do you want to display silly sentences? And using code?

Have three arrays with subjects, objects and verbs and randomize them. 

I have used latin words in the program, you can replace them with any language of your choice and amuse your friends.


 #include<iostream>  
 using namespace std;  
 class sentence  
 {  
   string subject;  
   string object;  
   string verb;  
 public:  
   sentence();  
   sentence(string,string,string);  
   void print_sentence();  
 };  
 sentence::sentence()  
 {  
   subject = "";  
   object = "";  
   verb = "";  
 }  
 sentence::sentence(string sub,string obj,string verb)  
 {  
   this->subject = sub;  
   this->object = obj;  
   this->verb = verb;  
 }  
 void sentence::print_sentence()  
 {  
   cout<<subject<<" "<<object<<" "<<verb<<endl;  
 }  
 int main()  
 {  
   string sub_arr[]= {"agricola","regina","filia","servus","filius","epistula","amica","dominus","Iulius","captivus"};  
   string obj_arr[] = {"agricolam","reginam","filiam","servum","filium","epistulam","amicam","dominum","Ilium","captivum"};  
   string verb_arr[] = {"vocat","laudat","pugnat","liberat","amat"};  
   srand((long)time(0));  
   sentence sen[10];  
 for(int i = 0;i<10;i++)  
   {  
    int r1 = rand()%10;  
    string subject = sub_arr[r1];  
    int r2 = rand()%10;  
    string object = obj_arr[r2];  
    int r3 = rand()% 5;  
    string verb = verb_arr[r3];  
    sen[i] = sentence(subject,object,verb);  
   }   
   for(int i =0;i<10;i++)  
    sen[i].print_sentence();  
 }  

Comments