Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ NOTE: It is REQURED that Each program must include this line: cout << \"Name

ID: 3883479 • Letter: C

Question

c++

NOTE: It is REQURED that Each program must include this line:

cout << "Name: YOURNAME - Program Name: PROGRAM NAME - Date: MMDDYY" << endl;

* Be sure to add your name as a cout in the first lines of each program - else 0 credit.

       * Add constructors - a default and parameterized constructor to each.

       * Write an .h interface and a .cpp implementation for each class

       * Write an Drive/Test file that tests the constructors and functions

       * Write a UML class diagram for each class

Program 4 - Pick color Class

Create a class that randomly pick a color from an array of colors: string colors[7];

Have the colors 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

Explanation / Answer

//Please see the code below Please do thumbs up if you like the solution

#define SIZE 7
#include<string>
#include <iostream>

using namespace std;

class PickColor
{
    private:
    string myColors[SIZE];

    public:
   void setElement( int index, string color)
   {
       myColors[index]=color;
   }
  
    void printColors()
    {
       cout<<"All the colors in the array are : "<<endl;
       for(int i=0;i<SIZE;i++)
           cout<< myColors[i]<<" ";
       cout<<endl;
    }

   void printRandomColors()
    {
       cout<<"Randomly pick One color from the array is ";
       cout<< myColors[(rand()%7)]<<endl;
    }

  
};

int main()
{
   PickColor p1;
   p1.setElement(0,"red");
   p1.setElement(1,"orange");
   p1.setElement(2,"yellow");
   p1.setElement(3,"green");
   p1.setElement(4,"blue");
   p1.setElement(5,"indigo");
   p1.setElement(6,"violet");
  
    p1.printColors();


   p1.printRandomColors();
   p1.printRandomColors();
   return 0;
}

OUTPUT:

All the colors in the array are :
red orange yellow green blue indigo violet
Randomly pick One color from the array is violet
Randomly pick One color from the array is orange