Skip to content

Instantly share code, notes, and snippets.

@sprintr
Created June 14, 2013 05:40
Show Gist options
  • Select an option

  • Save sprintr/5779699 to your computer and use it in GitHub Desktop.

Select an option

Save sprintr/5779699 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class Shape
{
public:
float area();
};
class Circle : public Shape
{
public:
Circle() {
radius = 2.0;
}
float area() {
return radius * radius * 2.146;
}
private:
float radius;
};
class Triangle : public Shape
{
public:
Triangle() {
baseLength = 10;
height = 9;
}
float area() {
return (1.0/2.0) * (baseLength * height);
}
private:
float baseLength;
float height;
};
class Rectangle : public Shape
{
public:
Rectangle() {
breadth = 20;
height = 15;
}
float area() {
return breadth * height;
}
private:
int breadth;
int height;
};
int main()
{
Circle c1;
Triangle t1;
Rectangle r1;
cout << "Area of Circle: " << c1.area() << endl;
cout << "Area of Triangle: " << t1.area() << endl;
cout << "Area of Rectangle: " << r1.area() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment