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
What's the drawback of using Screened Subnet (DMZ)?
lesantik [10]

It's more expensive, it's more difficult to configure and maintain and it can be more difficult to troubleshoot

4 0
3 years ago
The following checksum formula is widely used by banks and credit card companies to validate legal account numbers: d0 + f(d1) +
Aleksandr [31]

Answer:

Here is the JAVA program:

import java.util.Scanner; //to import Scanner class

public class ISBN

{   public static void main(String[] args)  { // start of main() function body

   Scanner s = new Scanner(System.in); // creates Scanner object

//prompts the user to enter 10 digit integer

   System.out.println("Enter the digits of an ISBN as integer: ");    

   String number = s.next(); // reads the number from the user

   int sum = 0; // stores the sum of the digits

   for (int i = 2; i <= number.length(); i++) {

//loop starts and continues till the end of the number is reached by i

          sum += (i * number.charAt(i - 1) ); }

/*this statement multiplies each digit of the number with i and adds the value of sum to the product result and stores in the sum variable*/

          int remainder = (sum % 11);  // take mod of sum by 11 to get checksum  

   if (remainder == 10)

/*if remainder is equal to 10 adds X at the end of given isbn number as checksum value */

  { System.out.println("The ISBN number is " + number + "X"); }

  else

// displays input number with the checksum value computed

 {System.out.println("The ISBN number is " + number + remainder); }  }  }  

Explanation:

This program takes a 10-digit integer as a command line argument and uses Scanner class to accept input from the user.

The for loop has a variable i that starts from 2 and the loop terminates when the value of i exceeds 10 and this loop multiplies each digit of the input number with the i and this product is added and stored in variable sum. charAt() function is used to return a char value at i-1.

This is done in the following way: suppose d represents each digit:

sum=d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 + d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9

Next the mod operator is used to get the remainder by dividing the value of sum with 11 in order to find the checksum and stores the result in remainder variable.

If the value of remainder is equal to 10 then use X for 10 and the output will be the 10 digits and the 11th digit checksum (last digit) is X.

If the value of remainder is not equal to 10, then it prints a valid 11-digit number with the given integer as its first 10 digits and the checksum computed by sum % 11 as the last digit.  

8 0
2 years ago
Which visual aid should Emil use to compare and contrast the political systems in three countries?
BaLLatris [955]
A vent diagram. It helps to outline the differences and the similarities between the three countries
5 0
3 years ago
During Iteration planning, the PO introduces multiple new stories to the team. After a lot of discussion, the team decides to in
netineya [11]

Answer:

The answer is "Option d".

Explanation:

The Iteration Management is also an activity in which all members of the team will determine how many the backlog team will allocate towards the next Iteration, and each team wraps up the work only as a group of determined iteration targets. in the given question the "choice d" is correct because The plans to achieve without training entered PO or design staff and requirements have not even been identified, and the wrong choice can be defined as follows:

  • In choice A, T' he PO doesn't give the story detail, that's why it's incorrect.    
  • In choice B,  the doesn't a team left the past for more refining with the PO in the Project Backlog, that's why it's incorrect.  
  • In choice C, The Development Team has not found some other team dependency, that's why it's incorrect.

4 0
3 years ago
Can someone please help me? my audio visual teacher wants me to watch two movies. i've never seen them and i have no way to watc
kati45 [8]

Answer:

You can try afdah or 123 movies, maybe try Netflix if you have it

Explanation:

The sites do have ads but that's where I usually watch my movies

4 0
3 years ago
Other questions:
  • Walter’s health insurance premium increased by 22 percent this year. Now he pays $488 every month for health insurance. What was
    10·1 answer
  • 15 POINTS COMPUTER LITERACY <br> The range A2:A4 has how many cells<br> -2<br> -4<br> -6<br> -8
    14·1 answer
  • The _____ is a narrative description of the product, service, or information system.
    7·1 answer
  • Select five system utility functions.
    11·1 answer
  • What is the difference between simple and complex waveforms?
    10·1 answer
  • The difference between a for loop and a while loop is that a for loop is a loop that happens for a certain number of times. A wh
    14·1 answer
  • Que se puede observar en el escritorio de windows
    8·1 answer
  • What is the purpose of a forecast worksheet?
    15·1 answer
  • Drag each statement to the correct location.
    10·1 answer
  • Sebutkan contoh komputer analog, komputer digital, dan komputer hybrid
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!