Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Area of Circle and Rectangle */
- /* Language: C++ */
- #include <iostream.h>
- #include <conio.h>
- #define pi 3.14
- class area
- {
- protected:
- float area;
- public:
- virtual float area_calc()
- {}
- };
- class rectangle:public area
- {
- float length,breadth;
- public:
- rectangle()
- {
- cout<<"\n\nEnter Length of the Rectangle";
- cin>>length;
- cout<<"\nEnter Breadth of the Rectangle";
- cin>>breadth;
- }
- float area_calc()
- {
- return length*breadth;
- }
- };
- class circle:public area
- {
- float radius;
- public:
- circle()
- {
- cout<<"\n\nEnter Radius of the Circle: ";
- cin>>radius;
- }
- float area_calc()
- {
- return pi*radius*radius;
- }
- };
- int main()
- {
- system("cls");
- area *area_ptr;
- cout<<"\n\nCalculating area of a rectangle....\n\n";
- rectangle rect1;
- area_ptr=&rect1;
- cout<<"\n\nArea of the given rectange is: "<<area_ptr->area_calc();
- cout<<"\n\nCalculating area of a Circle....\n\n";
- circle circle1;
- area_ptr=&circle1;
- cout<<"\n\nArea of the given circle is: "<<area_ptr->area_calc();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement