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
Question: define oprators​
Svetlanka [38]

Answer:

Explanation:

Operator can be defined as

a character or characters which gives determination of actions that are needed to be performed/ considered. Operators are symbols that gives the compiler information to perform specific mathematical/logical manipulations.They are special type of functions, which are capable of taking one or more arguments, then produces a new value. Different types of operator are;

✓arithmetic operators(addition "+" substraction "-"

✓relational operators( greater than ">"

lesser than"<"

✓Logical operators.( Connective words/symbols such as AND, NOT, OR)

Arithmetic Operators: These include "+" (addition), "-" (subtraction), "*" (multiplication), "/" (division), "\" (integer

5 0
2 years ago
Many people dream of being successful, but their actions can sometimes hold them back. What are some ways you can be sure that y
Nikitich [7]

Answer:

  • make a promise
  • write it in a diary
  • make a scrap book
  • create a video
  • make a picture book

I hope this helps

<h2>I know you will do great!!!</h2>

5 0
2 years ago
____________ provides the architect opportunity to electronically plan and place elements of a building.
Snowcat [4.5K]
CAD provides the architect opportunity to electronically plan and place elements of a building. The correct option among all the options that are given in the question is option "c". The full form of CAD is Computer Aided Design. It gives the designers the opportunity to create three dimensional pictures.
5 0
3 years ago
Read 2 more answers
Consider a student club or organization in which you are a
lakkis [162]

Answer:

Entity Relationship Diagram (ERD):

An ERD is an abstract data model to represent real world entities and their relationship to each other. ERD data schemas are used to define what data is important to processes in graphical form.

4 0
2 years ago
Adam is so good at playing arcade games that he will win at every game he plays. One fine day as he was walking on the street, h
ohaa [14]

Answer:

ask it to ur teacher boiiiiii

3 0
2 years ago
Other questions:
  • Use the image below to answer this question.
    14·1 answer
  • Janice, who is 15, posts a picture of herself drinking alcohol and making an obscene gesture on her social networking page. Whic
    11·2 answers
  • When Liam went to print his presentation, the boot process established the connection to the printer, sent the presentation to t
    12·1 answer
  • Which character goes at the end of a line of code that starts with if?
    8·1 answer
  • Are to print or find<br> the sum<br> 5 numbers<br> of<br> using flow chart
    6·1 answer
  • Which option is referred to by the Reports Due tag?
    7·1 answer
  • The =COUNT function calculates what value?
    15·2 answers
  • Which item can you add using the tag?
    10·2 answers
  • Adassadad saflalfaklfajfklajfalkfjalkfjalkfalkf
    6·2 answers
  • Question 1
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!