Created
June 14, 2013 05:40
-
-
Save sprintr/5779699 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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