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

Create a class called \"RGB\" for representing the RGB color code of any color.

ID: 3657924 • Letter: C

Question

Create a class called "RGB" for representing the RGB color code of any color. Include the following: 1) Attributes (all integers): a number from 0 to 255 for each of red (R), green (G), and blue (B). 2) Default constructor: all attributes are set to zero. 3) Initial value constructor. 4) Accessors and mutators for all attributes. 5) A method for calculating the "distance" between two points. The smaller the distance, the more similar two colors are. This is done by representing R, G, and B as the x, y, and z coordinates in a 3D coordinate system. Overload an operator if you'd like. 6) A method for converting the RGB values of a color into their hexadecimal equivalent. For each color, you're essentially converting 3 base-10 numbers into 3 base-16 numbers. The best way to do this is to represent the hexadecimal equivalent as a character array. However, the array has to be dynamic, both in the main function and in the method

Explanation / Answer

/*you may also download my code in particular format from.....http://www.2shared.com/file/i_997xx-/RGB.html*/ /*this code run for BORLAND COMPILER...the older one.*/ #include#include#include class RGB { int red; int green; int blue; public: RGB() { red=green=blue=0; } RGB(int r,int g,int b) { red=r; green=g; blue=b; } int getRed() { return red; } void setRed(int r) { red = r; } int getGreen() { return green; } void setGreen(int g) { green = g; } int getBlue() { return blue; } void setBlue(int b) { blue = b; } int distance(int x1,int y1,int z1,int x2, int y2,int z2) { float dis; dis=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))+((z2-z1)*(z2-z1))); return dis; } void RGB::convert(char *hexR,char *hexG,char *hexB,int red,int green,int blue); }; void RGB::convert(char *hexR,char *hexG,char *hexB,int red,int green,int blue) { int i=0; int rem; while(red>0) { rem=red; if(rem0) { rem=green; if(green0) { rem=blue; if(rem
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote