Advertisement
steverobinson

Area of Circle and rectangle

Oct 12th, 2010
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. /*      Area of Circle and Rectangle   */
  2. /*            Language: C++            */
  3.  
  4.  
  5.  
  6. #include <iostream.h>
  7. #include <conio.h>
  8. #define pi 3.14
  9.  
  10.  
  11. class area
  12. {
  13.     protected:
  14.         float area;
  15.  
  16.     public:
  17.  
  18.         virtual float area_calc()
  19.         {}
  20. };
  21.  
  22. class rectangle:public area
  23. {
  24.  
  25.         float length,breadth;
  26.  
  27.         public:
  28.  
  29.             rectangle()
  30.             {
  31.                 cout<<"\n\nEnter Length of the Rectangle";
  32.                 cin>>length;
  33.                 cout<<"\nEnter Breadth of the Rectangle";
  34.                 cin>>breadth;
  35.             }
  36.             float area_calc()
  37.             {
  38.                 return length*breadth;
  39.             }
  40.  
  41. };
  42.  
  43. class circle:public area
  44. {
  45.     float radius;
  46.  
  47.     public:
  48.         circle()
  49.         {
  50.             cout<<"\n\nEnter Radius of the Circle: ";
  51.             cin>>radius;
  52.         }
  53.         float area_calc()
  54.         {
  55.             return pi*radius*radius;
  56.         }
  57. };
  58.  
  59. int main()
  60. {
  61.     system("cls");
  62.     area *area_ptr;
  63.  
  64.  
  65.     cout<<"\n\nCalculating area of a rectangle....\n\n";
  66.  
  67.             rectangle rect1;
  68.             area_ptr=&rect1;
  69.             cout<<"\n\nArea of the given rectange is: "<<area_ptr->area_calc();
  70.  
  71.     cout<<"\n\nCalculating area of a Circle....\n\n";
  72.  
  73.             circle circle1;
  74.             area_ptr=&circle1;
  75.             cout<<"\n\nArea of the given circle is: "<<area_ptr->area_calc();
  76.     getch();
  77.     return 0;
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement