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]
2 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]2 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]2 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
Will mark Brainliest, need help ASAP!
Whitepunk [10]

Answer:

What Sherman needs to configure is:

RIPv2 class D of 240.

Explanation:

Multicast messages are usually dispatched to a select group of hosts on a network and require acknowledgement of the recipients. RIPv2 is a router-based internet protocol for exchanging routing information to the IP address 224.0. 0.9 on a network. It determine the most efficient way to route data on a network and to prevent routing loops.

3 0
2 years ago
The document asks about dependents because the number can
BARSIC [14]
The answer is: Lower overall taxes
8 0
3 years ago
Read 2 more answers
Money left over after the bills are paid is referred to as
sveta [45]
Change is what is left over 

ex. the cashier tells you "here is your leftover change sir/ma'am "<span />
3 0
3 years ago
Read 2 more answers
The two most common mechanisms for sharing an ip address are a router or ____.
Karo-lina-s [1.5K]
ICS would bet he answer. 


Good luck! (:
8 0
3 years ago
Travis completes his assignments on a word processor. He wants to make sure that his documents are free from spelling or grammat
mrs_skeptik [129]

Answer:

C:F7 I TAKE COMPUTER CLASAES

3 0
3 years ago
Read 2 more answers
Other questions:
  • Select the correct answer from each drop-down menu. Select the correct type of address reference.
    6·2 answers
  • Which subject area describes collecting and analyzing data from computer systems, networks, and storage devices, as part of an i
    7·1 answer
  • One is FPGA and other is ASIC. Budget, power consumption, and speed are the common parameters considered for the selection of th
    9·1 answer
  • Consider the following code segment.
    15·1 answer
  • What is the easiest way to create a resume in Word with predefined content that can be replaced with your information?
    13·2 answers
  • this bar is located at the top of your computer school in.Its functions allow you to navigate the web​
    5·2 answers
  • Let X and Y be two decision problems. Suppose we know that X reduces to Yin polynomial time. Which of the following statements a
    14·1 answer
  • Which is a connectionless protocol in the transport layer? What are the small chunks of data called?
    12·2 answers
  • The success criteria are used to judge whether a project is successful. False True <br> need it now
    13·2 answers
  • . Which of the following is NOT a
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!