//base class Shape with dim as data member and constructor to initialize its data
//derived classes Square and Circle to FindPerimeter() as member functions
//dim as side for Square and dim as radius for Circle
//Implement Run Time Polymorphism
#include <iostream>
using namespace std;
class Shape
{
protected:
float dim;
public:
Shape()
{
dim=0;
}
Shape(float d)
{
dim=d;
}
virtual void show()=0;
};
class Square:public Shape
{
public:
Square(float d):Shape(d)
{
}
void show()
{
cout<<"Area of Square is "<<4*dim<<endl;
}
};
class Circle:public Shape
{
//derived classes Square and Circle to FindPerimeter() as member functions
//dim as side for Square and dim as radius for Circle
//Implement Run Time Polymorphism
#include <iostream>
using namespace std;
class Shape
{
protected:
float dim;
public:
Shape()
{
dim=0;
}
Shape(float d)
{
dim=d;
}
virtual void show()=0;
};
class Square:public Shape
{
public:
Square(float d):Shape(d)
{
}
void show()
{
cout<<"Area of Square is "<<4*dim<<endl;
}
};
class Circle:public Shape
{
No comments:
Post a Comment