Title: Mega Kolor Klass
Description: it will rock once it becomes a creation
Gmakermaniac!!! - July 14, 2004 12:02 PM (GMT)
I am working on a class to manage colors. So far it is really good. During creation you define the RGB values and soon I'll put in a way to display the color (I hope ;) ).
Making a new color is so simple...
| CODE |
| Color * yellow = new Color(256,256,0); |
...And you can even do this...
| CODE |
| Show_Color_Stats(yellow) |
...Who knows where thiss will go? (I dont know about you but during this project I just learned you can use a class as an argument :) )
Here is the source code...
| CODE |
// // Color Wheel Plus // - A simple program idea by Albert (Gmakermanac!!!). A program that takes colors and // dose stuff. Colors (proof that I'm not biritish (colours?)) are RGB. //
#include <iostream> using namespace std;
class Color { private: // All the vars. to store info int c_red; int c_green; int c_blue;
public: // Constructor Color(int r, int g, int b) { c_red = r; c_green = g; c_blue = b; }
// Use this to get the value of red, you cant accses c_red directly because it's private. int Get_Red() { return c_red; }
// Same here for blue. int Get_Green() { return c_green; }
// Nothing new here bud'. int Get_Blue() { return c_blue; } };
// Show Color Stats // - So far it shows you the arguments that make up the color. Soon I hope to even create // a display where it shows you the color. void Show_Color_Stats(Color * SColor) { cout << "Red: " << SColor->Get_Red() << endl << "Green: " << SColor->Get_Green() << endl << "Blue: " << SColor->Get_Blue() << endl; }
int main() { // Create 3 new colors. Blue, yellow, and white. Color * blue = new Color(0,0,256); Color * yellow = new Color(256,256,0); Color * white = new Color(256,256,256);
// Show color stats for all 3 colors cout << "Blue..." << endl; Show_Color_Stats(blue);
cout << endl << "Yellow..." << endl; Show_Color_Stats(yellow);
cout << endl << "White..." << endl; Show_Color_Stats(white);
// Delete all 3 colors to prevent memory leaks delete blue; delete yellow; delete white;
// return 0 to say the program ended succesfully return 0; } |
myork - July 14, 2004 01:58 PM (GMT)
Some advice.
If a method does not change the state of the object then mark the method as const.
| CODE |
int Get_Red() const // Note the const here { return c_red; } |
Dont use pointers where you dont need to.
| CODE |
Color * blue = new Color(0,0,256); Color * yellow = new Color(256,256,0); Color * white = new Color(256,256,256);
|
Can by changed into:
| CODE |
Color blue(0,0,256); Color yellow(256,256,0); Color white(256,256,256); |
No need to delete the colours now. It will be done automatically.
Then modify you display function to:
| CODE |
void Show_Color_Stats(const Color& SColor) { cout << "Red: " << SColor.Get_Red() << endl << "Green: " << SColor.Get_Green() << endl << "Blue: " << SColor.Get_Blue() << endl; } |
Gmakermaniac!!! - July 14, 2004 02:40 PM (GMT)
ohh... Microsoft Visual C++ .NET 2003 Step By Step (the book) makes things more complicated than they have to be.
C-Man - July 14, 2004 02:41 PM (GMT)
You'r using a m$ relatyed book !? are you crazy ?! :wacko:
Burn it !
myork - July 14, 2004 02:54 PM (GMT)
Actually "Code Complete" forget the author by Microsoft press is very good and worth a read if intend to become a professional programmer.
C-Man - July 14, 2004 02:56 PM (GMT)
inline_skater20032001 - July 14, 2004 05:46 PM (GMT)
| QUOTE |
You'r using a m$ relatyed book !? are you crazy ?! Burn it ! |
lol :lol:
MonkeyMan - July 14, 2004 06:16 PM (GMT)
I don't see much of a point to this but what you make is your choice. :rolleyes:
myke - July 14, 2004 09:15 PM (GMT)
| QUOTE (C-Man @ Jul 14 2004, 02:41 PM) |
You'r using a m$ relatyed book !? are you crazy ?! :wacko: Burn it ! |
the best A+ certification book i've ever read is by microsoft
KTC - July 15, 2004 02:56 PM (GMT)
| QUOTE (C-Man @ Jul 14 2004, 03:41 PM) |
You'r using a m$ relatyed book !? are you crazy ?! :wacko: Burn it ! |
As mentioned, some MS Press book is actually very very good.
For example Code Complete as myork said or the newer recent release
Code Complete 2nd Ed. ;)
You must be forgetting also Programming Windows by Petzold is also MS Press release as well ;)

Something I heard during a talk, the speaker recalling what he once told some MS reps.:
Got nothing against people who works for Microsoft. It's just a job, like any other job. One do it to put foods on the table. (In fact, MS is worst pay than most others in the industry but that's another story.) OTOH, Microsoft itself
is evil .... they know it, and they doesn't care.
Gmakermaniac!!! - July 15, 2004 03:35 PM (GMT)
I just realized there is a class called Color in GDI. I will change mine. I plan on making an easy to use system.