1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
BaLLatris [955]
3 years ago
12

Program 4 - Pick color Class Create a class that randomly pick a color from an array of colors: string colors[7]; Have the color

s array and all functions defined in the class. Create and use a void setElement( index, "color") function to assign values to the array elements 0 to 6: red, orange, yellow, green, blue, indigo, violet. Have a function that prints out all the colors in the array. Have a function that randomly pick One color from the array and cout's the color. (Research Random number code) Run your Code - Produce the correct output and Turn it in for credit ---------------------------------------------------------------------------------------

Computers and Technology
2 answers:
xxMikexx [17]3 years ago
7 0

Answer:

#include<cstdlib>

#include<bits/stdc++.h>

#include<time.h>

using namespace std;

class Colors{

string colors[7];

public:

void setElement(int,string);

void printAllColors();

void printRandomColor();

};

void Colors::setElement(int index,string color){

colors[index] = color;

}

void Colors::printAllColors(){

cout << "Printing all the colors:\n";

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

cout << colors[i] <<"\t";

}

}

void Colors::printRandomColor(){

srand (time(NULL));

int index = rand() % 7;

cout<< "\n\nThe random picked color:";

cout << colors[index] << endl;

}

int main(){

Colors color;

color.setElement(0,"red");

color.setElement(1,"orange");

color.setElement(2,"yellow");

color.setElement(3,"green");

color.setElement(4,"blue");

color.setElement(5,"indigo");

color.setElement(6,"violet");

color.printAllColors();

color.printRandomColor();

}

to get the random color we are using srand and rand function. we are using time as seed to srand() function,because every time the time is changed. And based on that we are using rand() function and doing mod with 7 with the random number to get the index between 0 to 6, as ut array size is 7(0 to 6).

In the setElement(int index,string color) method we are inserting the value of colors in the colors array based on index.

In the printAllColors() function we are printing all the colors in the array.

In the printRandomColor() er are printing any random color based on rand() function.

and in main() we are initializing the string array with colors and calling the functions.

abruzzese [7]3 years ago
5 0

Answer:

C++.

Explanation:

#include <iostream>

#include <stdlib.h>

#include <time.h>

//////////////////////////////////////////////////////////////////////

class Color {

private:

   string colors[7];

public:

   void setElement(int index, string color) {

       colors[index] = color;

   }

   void printColors() {

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

           cout<<colors[i]<<endl;

       }

   }

   void randomColorPicker() {

       srand (time(NULL));

       int colorIndex = rand() % 6; // random number in the range of 0 to 6;

       cout<<colors[color_index]<<endl;

   }

};

You might be interested in
Paige is writing about the progress her team made in setting up a new software system. in one detail, she tells that the team co
jenyasd209 [6]

Answer:

Also

Explanation:

Just checked it in the system

3 0
3 years ago
Read 2 more answers
15. Select the correct answer.
givi [52]

Answer:

Pixel dimensions

Explanation:

measure of height and width of a image in pixels

3 0
3 years ago
A chart that shows the resource (project team member) along with their allocated hours for each week is known as a(n):
Anon25 [30]

Answer: b) GNATT chart

Explanation: GNATT is the type of chart that displays the schedule or working in the form of bars in horizontal direction .The chart displays the duties /task performed on the vertical axis and the time periods on horizontal axis week-vise. This chart is usually used for project management purpose fr coordination, tracing, planning etc.

Other options are incorrect because project staffing chart is for the display of the staff activities involved during project, histogram is graph representation using bars of different heights and entity diagram displays the entities relation in databases..Thus , the correct option is option(b).

4 0
3 years ago
Jerry purchased 25 dozens of eggs. He used 6 eggs to bake 1 cake. How
Nina [5.8K]

Answer:

50

Explanation:

He bought 25 dozens of eggs:

25 (12) = 300

He used 6 eggs to make 1 cake, so:

300 eggs/6 eggs per cake = 50 cakes

8 0
3 years ago
HELP ASAP. Which of the following best describes the path of a network packet on the Internet? I think it's (A)
lesya692 [45]

Answer:

the 1st one

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • _______________________ is a short-term program, typically 30 hours long, in which a therapist, social worker, or trained probat
    5·1 answer
  • ____________ is/are the information, knowledge of people or things, and connections that help individuals enter preexisting netw
    13·1 answer
  • Your environment includes many users who print documents often. A single print device isn't sufficient. You need a "printer pool
    7·1 answer
  • 50 POINTS &amp; A FOLLOW!
    11·2 answers
  • Which of the following is true of how packets are sent through the Internet?
    7·1 answer
  • By default, tables are sorted in ascending order by this.<br><br><br> What’s the answer?
    12·2 answers
  • Computers are used because they :
    9·2 answers
  • Ví dụ sau sẽ in ra dữ liệu của x là kiểu gì ?
    9·1 answer
  • If your earning potential is higher than the cost of your higher education,<br> you will have a
    8·1 answer
  • Computer-aided design software is used by ________.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!