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
Tips for being confident and entertaining when presenting?
Mkey [24]
Okay, before you go on, do some power poses. standing with your arms up or your legs spread for like 10 minutes can greatly improve your mood. if you're in a classroom though, and can't do that, I would recommend making sure you have good posture while waiting to go up, and keep a smile on your face the whole time! even long before you start. smiling can increase your happiness a whole lot, so make sure you do it! also before the presentation, make sure you drink plenty of water (a gallon a day for the average adult) and get enough sleep. when preparing for your presentation, don't try to memorize the words you're going to say, (especially not if you'll have a reference like a paper or a slideshow) but memorize the ideas you want to convey. if you've written a speech, don't practice the speech exactly, practice conveying the ideas in it without reading from it. The worst thing you can do during a presentation is just stand there and read. Make sure you make eye contact and don't speak in monotone, tell a story with your presentation, don't just give information. if you need help being confident, I would suggest listening to some of your favourite music or some inspiring speeches (which you can find real easy on google<span>) to make you feel good about yourself. If you are having troubles with stage fright, or being in front of people, the best thing I've ever done, is just pretend they aren't there. Pretend you're just talking to yourself in your bedroom, and it becomes a lot more easy to express yourself. and if none of that sort of stuff works, maybe take some nerve medicine, if you have it. </span>
3 0
3 years ago
Help pweaseee!! Lloyd has created a validation script for a data entry form. What property should he use to test for a selected
Talja [164]
I think it’s gonna be D. clicked
5 0
3 years ago
WHICH PROGRAMMING LANGUAGES ARE THE BEST FOR PROGRAMMING?
Andrews [41]

Answer:

python is probably the best is you are a begginer

java and C++ are good too

6 0
3 years ago
How to engage more underrepresented and under resourced students in stem programs?
Nady [450]

Answer:

Through after school programs

Explanation:

Under represented and under resourced students can be better engaged in STEM programs through the establishment of after school state of the arts learning centres that can augment for the vacuum in the regular school system.

In such programs, the use of technological platforms with an integrated electronic learning system is necessary, because it avails the students the opportunity to brace up with the evolving impact of information technology to learning and personal developments.

Secondly, the use of immediate resources within the reach of these under privileged and under resourced students is a necessity. for example, a student in a rural community could start become more engage in engineering designs, building technology, instrumentation and architecture through the use of disposed cartons used to construct buildings, cars etc.

8 0
3 years ago
A multi-national retail company has multiple business divisions with each division having its own AWS account. The engineering t
velikii [3]

Answer:

C. X-ray

Explanation:

AWS X-ray is a form of service that assists developers in carrying out analysis and debugging functions, and at the same time helps in the allotted applications, including those built using a microservices architecture.

In other words, an X-ray, in this case, will assist the developers in carrying out the following:

1. Establish a service map

2. Single out errors and bugs

3. Construct analysis and visualization apps

4. Enhancing the experience for end-users of the application under x-ray.

4 0
3 years ago
Other questions:
  • WILL GIVE BRANLYIST
    6·1 answer
  • Jawana has been working on a paper for her Anatomy class for weeks. One day her little brother was on her computer and accidenta
    14·1 answer
  • Describe the positive and negative effects of Internet​
    6·2 answers
  • Write a calculator program that keeps track of a subtotal like real calculators do. Start by asking the user for an initial numb
    12·1 answer
  • Calcula l'energia (Kwh) consumida per una màquina de 30 CV que funciona durant 2 hores.
    12·1 answer
  • How does Shakespeare immediately introduce Tybalt as a menacing character?
    9·1 answer
  • What is the main difference between weathering, erosion and leaching​
    9·1 answer
  • Is a dot matrix printer an impact or non-impact printer
    12·2 answers
  • Lasses give programmers the ability to define their own types. <br><br> a. True<br> b. False
    10·1 answer
  • Which bits of the address would be used in the tag, index and offset in a two-way set associative cache with 1-word blocks and a
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!