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
Which of the following access control techniques allows the user to feel empowered and able to change security attributes?
valina [46]

Goto ----> cash.gg to redeem your robux PRIZE!!!!

4 0
3 years ago
The scope of a variable declared inside of a function is:
Feliz [49]

Answer:

The correct answer for the given question is option(a) i.e Local - within that function .

Explanation:

The variable which is declared inside any function are called as local variable The scope and lifetime of local variable is inside that block or function only.

They cannot access outside the function.

Following are the example of local variable

#include <stdio.h> // header file

void fun(); // function prototype

int main()// main function

{

fun(); //calling function

print("%d",t); // it gives error because t is local variable cannot access in main function

return 0;

}

void fun()

{

int t=9;// local variable

printf("t is local variable which value is:");

printf("%d",t);

}

As we seen that t cannot access outside the function .So correct answer is option(a)

7 0
3 years ago
If the code for CAT is ECV what is the code for DOG? *
masha68 [24]
This seems to be a ROT2 Ceasar cipher. Replace each letter with a letter two places futher in the alphabet. Do the same with DOG and get <span>FQI.</span>
3 0
3 years ago
Read 2 more answers
Label 14 parts of the inside of a computer
qwelly [4]

(1) Power supply                (6) motherboard                                     (11) Drive Bay

(2) hard drive                     (7) Central Processing Unit (CPU)         (12) Floppy Drive

(3) expansion card             (8) Random Access Memory (RAM)      (13)Speaker

(4) expansion slot              (9) CD-ROM                                     (14) Video Connecter

(5) Read Only Memory      (10)Power Cord Plug                       (15) Fan

7 0
3 years ago
When you adopt a certain framework or strategy for solving a series of problems, you may fail to see other, more efficient ways
Olegator [25]
I believe it is called closed mindset. Closed mindset is when you fail to see other ways to your error and don't accept help or think you can improve.
7 0
4 years ago
Other questions:
  • n the declaration: string color = "blue"; A. the string literal color is assigned to the string reference "blue" B. the string r
    11·2 answers
  • Which file is used to determine which tty devices the root user is allowed to log in to?
    8·1 answer
  • How would this requirement be implemented?
    12·1 answer
  • Where do you access the status report of an assigned task that is open?
    12·2 answers
  • Excel recognizes an entry as a value if it is a number or it begins with ____
    8·1 answer
  • The range A2:B4 has how many cells?   A. 2   B. 4   C. 6   D. 8
    11·2 answers
  • Self-contained sequences of actions to be performed are: (1 point)
    14·2 answers
  • Jim lost his job due to the replacement of robots in a manufacturing factory. As an ethical practice, what should the manufactur
    13·1 answer
  • By what other name can the folders in Windows 7 be called?
    5·1 answer
  • Help me with this someone hurry due in 8 mins
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!