How Draw C++ Shapes
For Shape Class Use this code bellow....
For the Shape .cpp use code bellow....
Now lets start with example class...... we do a easy shape...
Now to draw the shape... add this code..
00000000000000000000000000
And remember...
#include "Shape.h"
#include "Rectangle.h"
#include <iostream.h>
--------------------------------------------------
To make a circle...
You get it....
-----------
--------
Credits
computer engW
VernonDozier
Boomdocks
CA*****(name is wrong to say)
Code:
class Shape {
public:
Shape(int newx, int newy);
int getX();
int getY();
void setX(int newx);
void setY(int newy);
void moveTo(int newx, int newy);
void rMoveTo(int deltax, int deltay);
virtual void draw();
private:
int x;
int y;
};
Code:
#include "Shape.h"
// constructor
Shape::Shape(int newx, int newy) {
moveTo(newx, newy);
}
// accessors for x & y
int Shape::getX() { return x; }
int Shape::getY() { return y; }
void Shape::setX(int newx) { x = newx; }
void Shape::setY(int newy) { y = newy; }
// move the shape position
void Shape::moveTo(int newx, int newy) {
setX(newx);
setY(newy);
}
void Shape::rMoveTo(int deltax, int deltay) {
moveTo(getX() + deltax, getY() + deltay);
}
// abstract draw method
void Shape::draw() {
}
Code:
Rectangle(int newx, int newy, int newwidth, int newheight); int getWidth(); int getHeight(); void setWidth(int newwidth); void setHeight(int newheight); void draw(); private: int width; int height; };
Code:
// draw the rectangle
void Rectangle::draw() {
cout << "Drawing a Rectangle at:(" << getX() << "," << getY() <<
"), width " << getWidth() << ", height " << getHeight() << endl;
}
And remember...
#include "Shape.h"
#include "Rectangle.h"
#include <iostream.h>
--------------------------------------------------
To make a circle...
Code:
void Circle::draw() {
cout << "Drawing a Circle at:(" << getX() << "," << getY() <<
"), radius " << getRadius() << endl;
-----------
--------
Credits
computer engW
VernonDozier
Boomdocks
CA*****(name is wrong to say)


