Hello ...


I must do a mini project on Inheritance ..
It's about 2-D and 3-D shapes..


The base class is point ..
and we must define as many derived classes as we could such as circle .. rectangle .. triangle .. Cylender .... and so on !


The most clsses and functions we include the most grades we will get ..


can you please help me in that .. Ideas ... articles .... Tutorials ... Open codes or any thing related ..


:)

Recommended Answers

All 3 Replies

are you doing it in opengl? or is it like turtle graphics

It is an open project ..
the teacher didn't put any rules for it ..

>The base class is point .
Inheritance isn't the right solution for point. A shape is not a point. A shape has one or more points, so containment is a better solution. point should be a stand-alone class. I really hate the shape abstraction as a means of introducing inheritance, but consider this:

struct Point {
  int x, y;
};

class Shape {
  /* No points */
public:
  virtual void draw() const { cout<<"Shape"<<endl; }
};

class Ellipse: public Shape {
  Point center;
  int radius;
public:
  virtual void draw() const { cout<<"Ellipse"<<endl; }
};

class Rectangle: public Shape {
  Point top_left;
  Point bottom_right;
public:
  virtual void draw() const { cout<<"Rectangle"<<endl; }
};

It's much harder to work out a coherent hierarchy if all of the shapes derive from Point.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.