Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ only Generating random colors Write a program that generates a different list of 100 random RGB color values using hexadecimal notation. The program should

C++ only

Generating random colors

Write a program that generates a different list of 100 random RGB color values using hexadecimal notation. The program should write something like the following into cout.

324AF3

6A3125

... 98 additional RGB values

To solve this problem you need to generate strings with 6 characters where each character is randomly chosen from the following set of symbols.

{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }

To make the choice random, you need to use the modulo operator (%). Specifically, use the expression rand()%16 to get a random integer between 0 and 15.

You are required to solve this problem by defining a loop within a loop. In fact, with the language features of C++ covered until this point, the solution to this problem requires a loop within a loop. If you know how to solve the problem without a nested loop, then you are required to solved it with a nested loop anyway, because learning how to write nested loops is the main learning objective of this exercise.

The program should generate a different list of color values each times it runs. To get this result, you need to seed the random number generator with a new value each time the program runs. One easy way to do this is to use the current time in seconds as a seed value. The following code shows how to do this.

#include

...

int main()

{

srand(time(0));

...

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

What do you believe was the cause of the turnover problem?

Answered: 1 week ago

Question

Consider this article:...

Answered: 1 week ago