Question: IN C++ PLEASE HERE IS THE CODE THAT I NEED TO ALTER #include #include Using namespace std; class Color{ //private data members for class private:

IN C++ PLEASE

IN C++ PLEASE HERE IS THE CODE THAT I NEED TO ALTER

#include #include Using namespace std; class Color{ //private data members for class

private: int red; int green; int blue; public : //The default constructor

HERE IS THE CODE THAT I NEED TO ALTER

#include

#include

Using namespace std;

class Color{

//private data members for class

private:

int red;

int green;

int blue;

public :

//The default constructor should initialize all the components to 0

Color(){

red = 0;

green = 0;

blue = 0;

}

Color(int r,int g,int b){

if(r255||g255||b255){

cerr

red=0;

green=0;

blue=0;

}

else{

red = r;

green = g;

blue = b;

}

}

//Member functions

int get_b(){

return blue;

}

int get_g(){

return green;

}

int get_r(){

return red;

}

//Second Constructor + Member Function

void set(int r, int g, int b){

if(r255||g255||b255){

cerr

}

else{

red=r;

green=g;

blue=b;

}

}

//Uses values provided to create the inverted value

void invert(){

red=255-red;

green=255-green;

blue=255-blue;

}

// Used to scale colors using inputs

void scale(double s){

if(red*s255||green*s255||blue*s255){

cerr

}

else{

red=red*s;

green=green*s;

blue=blue*s;

}

}

void print(ostream & out){

out

}

};

int main(){

Color c1,c2(20,30,40), c3(255,255,255),c4(100,200,300);

cout

c1.print(cout);

cout

c2.print(cout);

cout

c3.print(cout);

cout

c4.print(cout);

//Print c2 components without the parentheses:

cout

c2.invert();

cout

c2.print(cout);

c3.scale(.5);

cout

c3.print(cout);

c4.set(127, 154, 89);

cout

c4.print(cout);

c4.scale(2.0);

cout

c4.print(cout);

}

Problem A. Overloading Operators for the Color Class (20 points) Recall the color class, from your last homework assignment (HW 8, Problem B), specified below. You will reuse it for this part of homework assignment 9 by overloading operators for the class and using ALL of the operators you overload in a program. b that Member Variables: The class should have three private member variables, r, contain the red, green, and blue components of the light color g, Constructors: The class should have the following two constructors or one constructor that functions as s pecified in item i. or ii. below i. The default constructor should initialize all the components to 0. i A constructor that takes three int arguments representing the red, green, and blue components, respectively. This should check that all three components are between 0 and 255, inclusive. If they are, then it should assign the argument values to the corresponding member variables. If one or more is not, then the constructor should print out a message, and set all member variables to 0 Member Functions: The class should have the following public member functions: takes no arguments and should return the red component. takes no arguments and should return the green component. takes no arguments and should return the blue component. - set (int new r, int new g, int new b) sets the value of the components get_r get_g get_b to the corresponding arguments. However, if any of the arguments is outside the range 0 to 255, then the program should print a message and not change any of the component values. invert changes the components to the values 255 - r, 255 - g, and 255 - b, respectively. So, for example, if the current color is 100, 110, 120, the new red value would be 255-100- 155, the new green would be 255-10145, and the new blue would be 255- 120-135 scale (double s) multiplies each component by the scale factor s. For example, if the current color is 100, 115, 130, and s is .5, then then new red component would be 100 x .5-50, the new green is 1 15 .5-57 (the result, being an int, should not include any fractional part), and the new blue is 130 x .5-65. However, if scaling would result in any component being outside the range 0 to 255, then this function should print a message and leave the components as they were. Any function specified above that does not change the value of its member variables should be a const function. This is good programming practice, and should be followed not only here, but on all classes you write. Next, add the declarations and definitions to the color class necessary to overload the operators specified on the next page

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!