Question: Using C++ Each fortune cookie will have an array of 10 strings that will hold different fortunes. You can make up the 10 fortunes. One

Using C++

Each fortune cookie will have an array of 10 strings that will hold different fortunes. You can make up the 10 fortunes. One of those fortunes will be the active one. That active fortune will be selected by generating a random number for an index in the array. The UML class diagram for the Fortune Cookie class looks like the following:

FortuneCookie

-rand_index : int

- fortunes[10] : string

+ openFortuneCookie() : void

+generateNewFortune() : void

+<>FortuneCookie() :

The fortune cookie will have the following methods:

void generateNewFortune();

Summary: This function creates a new random index that

represents a different fortune. The fortunes are stored

in a string array called fortunes, of size 10.

void openFortuneCookie();

Summary: This function displays the fortune at rand_index in the array of strings. Sample output

shown below:

|=========================|

| You will get great news!|

|=========================|

FortuneCookie();

Summary: The default constructor assigns a fortune to each

index in the fortunes array. It also initializes the rand_index

to a random number from 0 to 9.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!