Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Revise)Please write this program in C++ here's source code, need to change this code by the new instruction down there. --------------------------------------------------------------------------------- #include #include using namespace

(Revise)Please write this program in C++

here's source code, need to change this code by the new instruction down there.

--------------------------------------------------------------------------------- #include #include using namespace std; class Color { private: int r,g,b; public: Color(); Color(int r,int g,int b); int get_r() const; int get_g() const; int get_b() const; void set(int r,int g,int b); void invert(); void scale(double s); void print(ostream& out) const; }; //default constructor Color::Color() { r=0; g=0; b=0; } //parameterised constructor Color::Color(int r,int g,int b) { //checking r,g,b values are in between 0 and 255 inclusive if((r>=0 && r=0 && g=0 && br=r; this->g=g; this->b=b; } else { coutr=0; this->g=0; this->b=0; } } //accessor for member variable r int Color::get_r() const { return r; } //accessor for member variable g int Color::get_g() const { return g; } //accessor for member variable b int Color::get_b() const { return b; } //function to set all the varibale r,g,b void Color::set(int r,int g,int b) { //checking r,g,b values are in between 0 and 255 inclusive if((r>=0 && r=0 && g=0 && br=r; this->g=g; this->b=b; } else { cout=0 && newr=0 && newg=0 && newb

------------------------------------------------------------------------

image text in transcribed

image text in transcribed

image text in transcribed

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 for this part of homework assignment 9 by overloading operators for the class and using ALL of the operators you overload in a p Member Variables: The class should have three private member variables, r, g, b that contain the red, green, and blue components of the light color Constructors: The class should have the following two constructors or one constructor that functions as specified in item i. or ii. below i. The default constructor should initialize all the components to 0. ii. 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. corresponding member variables. If one or more is not, then the constructor should print out a message, and set all member variables to 0 If they are, then it should assign the argument val ues to the Member Functions: The class should have the following public member functions: get_r takes no arguments and should return the red component. get_g) takes no arguments and should return the green component. . get b) 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 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 would be 255-120 135 be 255 0 145, and the new blue 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 .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 .5 = 65. However, if scaling would result in any component being outside the range 0 to 255, then this function should printa 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

=+ How would you advise those problems be resolved?

Answered: 1 week ago