Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Class RgbColor stores a color in RGB format. It is different from struct Rgb as it has member functions and will be part of a

Class RgbColor stores a color in RGB format. It is different from struct Rgb as it has member functions and will be part of a class hierarchy. Do the following: Make RgbColor a derived class of Color. Change provided member function getRgb() so that it overrides the base class version of the function. Inside the function definition of rangeComponent(), remove the if-else and instead call the base class version of the rangeComponent() function with a min of 0 and max of 255 (do not change the RgbColor constructor).

Relevant Code:

// Color base class. class Color { public: // Convert color to RGB (default to black since base class // does not have a particular color representation). void getRgb(int& red, int& green, int& blue) const;

protected: // Keep component between min and max (inclusive). static void rangeComponent(int& component, int min, int max); };

// RgbColor class definition for objects that represent a color // made of 1-byte red, green, and blue components. class RgbColor { public: // Initialize color to red, green, blue components specified. RgbColor(int initRed, int initinitGreen, int initBlue);

// Convert color to RGB (trivial). void getRgb(int& red, int& green, int& blue) const;

private: int red, green, blue;

// Keep component in proper range. static void rangeComponent(int& component); };

// Definitions

RgbColor::RgbColor(int initRed, int initGreen, int initBlue) : red(initRed), green(initGreen), blue(initBlue) // initialize components { // Ensure components in proper range. rangeComponent(red); rangeComponent(green); rangeComponent(blue); }

void RgbColor::rangeComponent(int& component) { if (component < 0) component = 0; else if (component > 255) component = 255; }

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

=+j Describe an effective crisis management program.

Answered: 1 week ago