Hi everyone. See the comments in the code. How do I take three strings and put it inside an object, and return that object to main? This is only a part of the whole program.
class threeStrings
{
private:
string string1, string2, string3;
string generateString(); // Making this a member function
public:
threeStrings();
bool setString1(string str1);
bool setString2(string str2);
bool setString3(string str3);
string getString1();
string getString2();
string getString3();
threeStrings& conjure(); // Making this a member function
};
threeStrings& threeStrings::conjure()
{
setString1( generateString() );
setString2( generateString() );
setString3( generateString() );
return *this; // Returning the object itself.
}
string threeStrings::generateString()
{
switch(rand()%3) // Randomly returns a pre-defined string
{
case 0: return"Snowy weather is cold";
case 1: return"I like tomato sauce";
case 2: return"King Sombre has captured the crystal empire!";
}
}