answer.
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]
1 year 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]1 year 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]1 year 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
Each of these is a basic type of a touch screen, except ________.
Oksanka [162]
<span>A touch screen gives response and acts simply with a touch on the screen area. Reflective screen is not a basic type of touch screen. The reflection can be reduced for the touch screen when it is combined with the LCD and the screen still be very visible. These screens can be anti glare and safe to the eyes.</span>
8 0
2 years ago
Read 2 more answers
Acceleration is the rate at which an object changes its velocity. It is typically represented by symbol a and measured in m/s2 (
Natalija [7]

Answer:

<u>Pseudocode:</u>

INPUT velocity

INPUT time

SET velocity = 0.44704 * velocity

SET acceleration = velocity / time

SET acceleration = round(acceleration, 1)

PRINT acceleration

<u>Code:</u>

velocity = float(input("Enter a velocity in miles per hour: "))

time = float(input("Enter a time in seconds: "))

velocity = 0.44704 * velocity

acceleration = velocity / time

acceleration = round(acceleration, 1)

print("The acceleration is {:.2f}".format(acceleration))

Explanation:

*The code is in Python.

Ask the user to enter the velocity and time

Convert the miles per hour to meters per second

Calculate the acceleration using the formula

Round the acceleration to one decimal using round() method

Print the acceleration with two decimal digits

7 0
1 year ago
In a situation where handicapped person can only input data into the computer using a stylus or light pen, which keyboard config
asambeis [7]
I think the best one is voice recognition keyboards.


Would perfect work there



Mark as brainliest
8 0
1 year ago
Read 2 more answers
HackerCards is a trendy new card game. Each type of HackerCard has a distinct ID number greater than or equal to 1, and the cost
joja [24]

Answer:

I don't know if this is right output is {1,3}

Explanation:

5 0
1 year ago
To be a successful computer systems engineer, you must be proficient in programming languages and operating systems. Similarly,
Maslowich

Collectively, skills like the ones listed above are Technical skills. These skills refer to the Knowledge and ability to perform specific tasks. However, Soft skills are also important, because they relate to the ability to interact and communicate effectively with people.

6 0
2 years ago
Read 2 more answers
Other questions:
  • A circuit contains three resistors connected in parallel. The value of R1 is 2 K , the value or R2 is 6 K , and the value of R3
    5·1 answer
  • Edward has started up a new company with his friend, Matthew. Currently, he has only two people working with him. Which type of
    8·1 answer
  • Select the correct answer. James is a sales analyst of a departmental store chain. He checked the sale records for the past 12 m
    6·2 answers
  • The Web can play a significant role in making large amounts of information available to decision makers. Decision makers must be
    10·1 answer
  • Write a loop that counts the number of space characters in a string. Recall that the space character is represented as ' '.
    11·1 answer
  • An entrepreneur is opening a computer store in a small town and wants to display a few laptops in the store, but is concerned ab
    11·2 answers
  • Write a method that takes three numerical String values and sums their values.
    14·2 answers
  • Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", a
    7·1 answer
  • A company with a large number of hosts creates three subdomains under a main domain. For easier management of the host records,
    11·1 answer
  • You are working on a documentation file userNotes.txt with some members of your software development team. Just before the file
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!