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 ..


13 Years
Discussion Span
Last Post by Narue

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 */
  virtual void draw() const { cout<<"Shape"<<endl; }

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

class Rectangle: public Shape {
  Point top_left;
  Point bottom_right;
  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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.