Advertisement

help

Started by May 03, 2002 09:21 AM
7 comments, last by dreamer 22 years, 7 months ago
i was beginning a shape class which contains point,rectangle,triangle,circle and line.the program can draw and resize.i have start a little but i don''t want tto write after this class shape { public: Draw(); Resize(); class point { public: point(int,int) then i don''t know how to continue can anyone help me
You probably want to store a color in there too?


  class Shape_C{public: short Top, Left, Height, Width; unsigned char Red, Green, Blue;public: virtual void Draw(void){};//Does nothing if we don''t have a fucntion for it in our derived classes! void Resize(short top, short left, short height, short width); void SetColor(unsigned char r, unsigned char g, unsigned char b);};/*Use =0 for width/height so when we call Point.Resize() we need only supply x,y locations, and not width/height (unless you want a width and height for a point, then you can still use it).*/void Shape_C::Resize(short left, short top, short width=0, short height=0){  Top=top;  Left=left;  Width=width;  Height=height;}class Point_C : Shape_C{public: void Draw(void);};void Point_C::Draw(void){//Draw code for point drawing! PutPoint(Left,Top,Red,Green,Blue);}class Rectangle_C : Shape_C{public: void Draw(void);}void Rectangle_C::Draw(void){//Rectangle drawing code here! PutRectangle(Left,Top,Width,Height,Red,Green,Blue);}  


Something like that is what I''d do I guess...

Billy - BillyB@mrsnj.com
(Hey, I''''m no longer anonymous!)
Advertisement
You should probably be in the Beginner''s forum with this question. Can you describe a bit more about your problem? I can see you''ve made a start, but you haven''t said exactly what it is you''re stuck with. I''m assuming that you are talking about C++. Have you thought about what you want your classes to do? Is it that you don''t know how to write a class? If so, do you have a C++ tutorial guide? You might find Thinking in C++ to be helpful.

[ C++ FAQ Lite | ACCU | Boost | Python | Agile Manifesto! ]
It all depends on what you're using these shapes for (post and I'm sure people can come up with a ton of suggestions).
Some general functions might be:

int IsPointInside(int x, int y)
single Area()
void Translate(int deltaX, int deltaY)//Translate means move
void Rotate(single angle)

If its part of a game engine you might also want some things like:

int IsCollision(CShape aShape)
rect BoundingBox()




[edited by - Michalson on May 3, 2002 10:42:47 AM]
Try this...

class Shape{  public:    // Virtual Destructor ensures proper handling    // of destruction    virtual ~Shape();    // Virtual NULL Functions force sub-classes    // to implement these.    virtual void Draw( ... ) = 0;    virtual void Resize( ... ) = 0;};class Point : public Shape{  public:    // Constructor and destructor    Point();    ~Point();    // Actual implementation of functions    virtual void Draw( ... );    virtual void Resize( ... );};class Triangle : public Shape{  public:    Triangle();    ~Triangle();    // Actual implementation of functions    virtual void Draw( ... );    virtual void Resize( ... );};// Etcetera... 


Any other questions?

PropellerBoy


-> For Beginners.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!
Advertisement
hi thx u guy,teaching how to write a class.by the way do u have any reference site which teach u how to build a class.becoz i have learn C languange last year,but i didn''t do good on it,especially coding part.i would like to improve it.can anyone tell me any tutorial site for me to have a look at c++ programming or evening sample of the script.
Try the "free books" link in my sig.

______________________________
[Free Books!] [Reference and Tutorials]
[For Beginners] [IGDA]
[OpenGL Tutorials] [Sourceforge]
[DirectX Tutorials] [Gamasutra]
hi i have got sth finished,but i don''t know if i''m right?can any one tell me where have problem.and where to correct it.
class shape
{
public:
vitrual void draw()=0;
virtual void resize()=0;
virtual~shape();
};
class pointublic shape
{
public:
Point(int x,int y);
virtual void setpoint(int);
virtual void getpoint()const;
virtual void draw();
virtual void resize();
virtual~point();
private:
int x,y;
}
class lineublic shape
{
public:
line(int l,int x, int y);
virtual setlength(int);
virtual getlength()const;
virtual void draw();
virtual void desize();
virtual~line();
private:
int length;
}
class circleublic shape
{
public:
circle(int r,int x, int y);
virtual void setradius(int);
virtual void getradius()const;
virtual void draw();
virtual void resize();
virtual~circle();
private:
int radius;
}
class triangleublic shape
{
public:
triangle(int a,int x,int y);
virtual void setangle(int);
virtual void getangle()const;
virtual void draw();
virtual void resize();
virtual~triangle();
private:
int angle;
}
class rectangleublic shape
{
public:
rectangle( int l, int x, int y);
virtual void setlength(int);
virtual void setheight(int);
virtual void getlength()const;
virtual void getheight()const;
virtual void draw();
virtual void resize();
virtual~rectangle();
private:
int length,height;
}
class squareublic shape
{
public:
square(int l, int h, intx ,int y);
virtual void setlength(int);
virtual void setheight(int);
virtual void getlength()const;
virtual void getheight()const;
virtual void draw();
virtual void resize();
virtual ~square();
private:
int length,height;
}

This topic is closed to new replies.

Advertisement