#include <iostream>
using namespace std;
class Box
{
public:
double length;
double breadth;
double height;
Box();
~Box();
Box(const Box &p){
length = p.length;
}
double get(void);
void set(double len, double bre, double hei);
int compare(Box box)
{
return this->Volume() > box.Volume();
}
static int getCount()
{
return objectCount;
}
friend void printWidth( Box box );
Box operator+(const Box& b)
{
Box box;
box.length = this->length + b.length;
box.breadth = this->breadth + b.breadth;
box.height = this->height + b.height;
return box;
}
private:
double width;
protected:
double width2;
};
Box::Box(void)
{
cout << "Object is being created" << endl;
}
Box::~Box(void)
{
cout << "Object is being created" << endl;
}
void printWidth( Box box )
{
cout << "Width of box : " << box.width <<endl;
}
double Box::get(void)
{
return length * breadth * height;
}
void Box::set(double len, double bre, double hei)
{
length = len;
breadth = bre;
height = hei;
}
class SmallBox:Box
{
public:
void setSmallWidth( double wid );
double getSmallWidth( void );
};
double SmallBox::getSmallWidth(void)
{
return width2 ;
}
void SmallBox::setSmallWidth( double wid )
{
width2 = wid;
}
#include <iostream>
using namespace std;
class Shape {
protected:
int width, height;
public:
Shape( int a=0, int b=0)
{
width = a;
height = b;
}
int area()
{
cout << "Parent class area :" <<endl;
return 0;
}
};
class Rectangle: public Shape{
public:
Rectangle( int a=0, int b=0):Shape(a, b) { }
int area ()
{
cout << "Rectangle class area :" <<endl;
return (width * height);
}
};
class Triangle: public Shape{
public:
Triangle( int a=0, int b=0):Shape(a, b) { }
int area ()
{
cout << "Triangle class area :" <<endl;
return (width * height / 2);
}
};
int main( )
{
Shape *shape;
Rectangle rec(10,7);
Triangle tri(10,5);
shape = &rec;
shape->area();
shape = &tri;
shape->area();
return 0;
}