Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following class definition: #include usingnamespacestd; classColor { private: intred, green, blue; intcheckAndTruncate(intx); public: Color() { red = 0; green = 0; blue =

Given the following class definition:

#include

usingnamespacestd;

classColor

{

private:

intred, green, blue;

intcheckAndTruncate(intx);

public:

Color() { red = 0; green = 0; blue = 0; }

// Copy constructor

voidsetRed(intr) { red = checkAndTruncate(r); }

voidsetGreen(intg) { green = checkAndTruncate(g); };

voidsetBlue(intb) { blue = checkAndTruncate(b); }

intgetRed() { returnred; }

intgetGreen() { returngreen; }

intgetBlue() { returnblue; }

};

intColor::checkAndTruncate(intx)

{

if(x>= 0 && x<= 255)

returnx;

elseif(x< 0)

{

return0;

}

else

{

return255;

}

}

Add all necessary operators, functions and/or constructors so the that the following main will generate the following output:

Notes:

>> and << operators must be implemented as friend functions.

All other operators should be implemented as member functions.

Notes:

You are not allowed to change anything in the main

You have to implement the copy constructor

intmain()

{

Colorcol1;

Colorcol2;

Colorcol3;

cout <<"Please enter the first color (red green blue):";

cin >>col1;

cout <<"Please enter the second color (red green blue):";

cin >>col2;

cout <<"Please enter the third color (red green blue):";

cin >>col3;

Colorcol4 = col1 +col2;

cout <

return0;

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

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions

Question

Have issues been prioritized?

Answered: 1 week ago

Question

d. How will lack of trust be handled?

Answered: 1 week ago

Question

Are the rules readily available?

Answered: 1 week ago