Create a class called \"RGB\" for representing the RGB color code of any color.
ID: 3659178 • 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. Use the following as a guide: #include using namespace std; char *myfun(int R, int G, int B); int main() { int red=255, green=255, blue=255; char *hex_equiv; hex_equiv = new char[6]; hex_equiv = myfun(red,green,blue); cout<<hex_equiv[0]<<hex_equiv[1]<<hex_equiv[2]<<hex_equiv[3]<<hex_equiv[4]<<hex_equiv[5]<<endl; return 0; } char *myfun(int R, int G, int B) { char *hex; hex = new char[6]; hex[0] = 'F'; hex[1] = 'F'; hex[2] = 'F'; hex[3] = 'F'; hex[4] = 'F'; hex[5] = 'F'; return hex; } The attached file contains 6 integers: the R, G, and B values for color 1, and the values for color 2. Read the data and create a formatted output file with the R, G, and B values for each color, their hexadecimal equivalents, and the distance between the two colors. This program is giving me a really hard time. I had work in this for almost two week and still not get any results. What I need is an idea how to start with my header file, complementation file, and the main file. I will rate immediately.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(rem<10) hexR[i]=rem+48; /*converts integer to char*/ /*as ascii value of 1-9 ranges from 48-57*/ else hexR[i]=rem+55; /*converts integer to char*/ /*as ascii value of A-Z ranges from 65-90*/ red=red/16; i++; } hexR[i]=''; i=0; while(green>0) { rem=green; if(green<10) hexG[i]=rem+48; else hexG[i]=rem+55; green=green/16; } hexG[i]=''; i=0; while(blue>0) { rem=blue; if(rem<10) hexB[i]=rem+48; else hexB[i]=rem+55; blue=blue/16; } hexB[i]=''; }
pls must rate
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.