Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- class Shape{
- public:
- double area();
- };
- class Square:public Shape{
- double side;
- public:
- Square(double = 0.0);
- double area();
- };
- class Circle:public Shape{
- double radius;
- public:
- Circle(double = 0.0);
- double area();
- };
- class Rectangle:public Shape{
- double length, breadth;
- public:
- Rectangle(double = 0.0, double = 0.0);
- double area();
- };
- inline Square::Square(double side){
- Square::side = side;
- }
- inline Circle::Circle(double radius){
- Circle::radius = radius;
- }
- inline Rectangle::Rectangle(double length, double breadth){
- Rectangle::length = length;
- Rectangle::breadth = breadth;
- }
- inline double Circle::area(){
- return M_PI * radius * radius;
- }
- inline double Rectangle::area(){
- return length * breadth;
- }
- inline double Square::area(){
- return side * side;
- }
- int main(int argc, char** argv) {
- system("cls");
- cout << "For square" << endl;
- cout << "Enter a side: ";
- double side;
- cin >> side;
- cout << "For circle" << endl;
- cout << "Enter a radius: ";
- double radius;
- cin >> radius;
- cout << "For rectangle" << endl;
- cout << "Enter a length: ";
- double length;
- cin >> length;
- cout << "Enter a breadth: ";
- double breadth;
- cin >> breadth;
- Circle c(radius);
- Rectangle r(length, breadth);
- Square s(side);
- cout << "Area of circle = " << c.area() << endl;
- cout << "Area of square = " << s.area() << endl;
- cout << "Area of rectangle = " << r.area() << endl;
- cin.ignore();
- cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment