sorry about the lenght of code:
#include <iostream>
using namespace std;
class Shape
{
public:
Shape(int,int);
Shape ();
virtual ~Shape();
virtual void print()const = 0;
virtual double calArea() = 0;
protected:
int centreX,centreY;
};
////// CONSTRUCTORS ////////////////////
Shape::Shape(int x, int y)
{
centreX = x;
centreY = y;
}
Shape::Shape()
{
centreX=0;
centreY=0;
}
///// DESTRUCTOR ///////////////////////
Shape::~Shape()
{ }
///// Virtual functions ////////////////////////
void Shape::print()const
{ }
double Shape::calArea()
{ }
class Circle:public Shape
{
public:
Circle(int x,int y,int r);
~Circle ();
void print()const;
double calArea()const;
protected:
int radius;
};
class Rectangle:public Shape
{
public:
Rectangle( int, int, int, int);
~Rectangle();
void print()const;
double calArea()const;
protected:
int height;
int width;
};
Circle::Circle (int x,int y, int r) : Shape(x,y)
{
radius = r;
}
Circle::~Circle()
{}
void Circle::print(void)const
{
cout << "Circle with radius " << radius << " at " << centreX << "," <<
centreY <<endl;
}
Rectangle::Rectangle(int x,int y,int h,int w)
:Shape(x,y)
{
height=h;
width = w;
}
double Circle::calArea()const
{
return 3*3;
}
Rectangle::~Rectangle()
{}
void Rectangle::print(void)const
{
cout <<"Rectangle is at " << centreX <<','<< centreY
<< " Height:" << height << " width:" << width <<endl;
}
double Rectangle::calArea()const
{
return 2*2;
}
int main()
{
return 0;
}
This is the error it generates! Really confusing!
C:\computer science programming\CPP2\excerise sheet 8\Question 3 - shape\main.cpp(45) : error C4716: 'Shape::calArea' : must return a value