Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 3 - Modify the following Program. Convert the following program as per comments // program colors // -> Convert class into .h header file

Part 3 - Modify the following Program. Convert the following program as per comments

// program colors

// -> Convert class into .h header file and .ccp implemenation file and a main file.

// Keep int main() funciton same...

#include

using namespace std;

#include

/* srand example */

#include

#include /* NULL */

#include /* srand, rand */

class colorPicker {

private:

string colorArray[7];

public:

colorPicker() {

// Defalut Consructor assign values to array

// Use 7 assignment statements to assign each color to the color array

colorArray[0] ="Red";

colorArray[1] ="Green";

colorArray[2] ="Purple";

colorArray[3] ="Yellow";

colorArray[4] ="Orange";

colorArray[5] ="Indigo";

colorArray[6] ="Pink";

}

void printAllColors() {

// use for loop to print out all colors

for (int i = 0 ;i < 7; i++)

{ cout << colorArray[i] << endl;}

}

string randomColor() {

srand((unsigned)time(0));

// pick a random number between 1 and 7

int i =0;

i = rand()%7;

return colorArray[i];

}

};

int main()

{

colorPicker P;

//

P.printAllColors();

cout << "Random Color: " << P.randomColor();

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Does your message reiterate its main idea?

Answered: 1 week ago

Question

5 The mechanics of the circular flow model.

Answered: 1 week ago

Question

1 The difference between a command system and a market system.

Answered: 1 week ago

Question

4 How the market system adjusts to change and promotes progress.

Answered: 1 week ago