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
Which option in a Task element within Outlook indicates that the task is scheduled and will be completed on a later
joja [24]
I think it’s in progress
5 0
2 years ago
Read 2 more answers
I need help with the rest also
dalvyx [7]

Answer:

??? blackkkkkkkkkkkkkkkkk

6 0
2 years ago
What are somd negetive aspects and some positive aspects of having robots as a part of workplace?
aksik [14]

Answer and Explanation:

Some of the negative aspects of robots at work place:

  • Lesser flexibility
  • Higher maintenance and installation cost
  • Future insecurity and risk if the system malfunctions
  • A decline in the opportunities for humans
  • Unemployment as a result of automation and robot regulated work place.

Some of the positive aspects of robots at work place:

  • Higher accuracy
  • Higher speeds
  • More work in less time
  • Productivity and hence efficiency will increase
  • Cost of some operations is reduced.
  • Ease of employing in dangerous and hazardous fields by using specific robots for each task
5 0
2 years ago
On an unweighted scale, a grade of A is worth _____ points
Lubov Fominskaja [6]
On an unweighted scale, a grade of A is worth 4 points and  B. 3 points, C. 2 points, and D 1 point. E. 0 points. If you're trying to calculate your gpa then simply add all of those together! BAM                                                                                 
7 0
3 years ago
How would you log in as zach if you did not know his password but knew the root password?
Nuetrik [128]
You can login in root terminal and then type #sudo Zach 
8 0
3 years ago
Other questions:
  • How many years does it take in total to complete Bachelor’s, Master’s, and Phd in CS?
    14·1 answer
  • Encyclopedia.com is considered to be
    15·1 answer
  • How can i complain a rude comment
    7·1 answer
  • Go online and research the computer topic
    6·1 answer
  • Which of the following is necessary to connect a computer outside of the hospital to the hospital's server?
    15·1 answer
  • Complete the second clause of the following Prolog program for member/2 where member(X, Y) checks whether X is an element (a mem
    7·1 answer
  • To improve readability,______ use text on a dark green background.
    11·2 answers
  • Add the following method to the Point class: public double distance(Point other) Returns the distance between the current Point
    12·1 answer
  • The price of an item you want to buy is given in dollars and cents. You pay for it in cash by giving the clerk d dollars and c c
    6·1 answer
  • Carl is beginning a digital forensic investigation. he has been sent into the field to collect a machine. when he arrives, he se
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!