Advertisement
Guest User

freffdf

a guest
Jul 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int add(int a,int b);
  4. double add(double a,double b);//can not declare with just prototype return type difference
  5.  
  6. class rectangle
  7. {
  8. private:
  9.     int area;
  10.     int length;
  11.     int breadth;
  12. public:
  13.     rectangle(int l,int b)
  14.     {
  15.         length=l;
  16.         breadth=b;
  17.  
  18.     }
  19.     rectangle(int s)
  20.     {
  21.         length=s;
  22.         breadth=s;
  23.     }
  24.     rectangle()
  25.     {
  26.        
  27.     }
  28.     ~rectangle()
  29.     {
  30.  
  31.         cout<<"destructor calling"<<"\n";
  32.  
  33.     }
  34.     void set_length(int l);
  35.  
  36.     int get_length();
  37.  
  38.     void set_breadth(int b);
  39.  
  40.     int get_breadth();
  41.  
  42.     int get_area();
  43.  
  44.  
  45. };
  46.  
  47. void rectangle::set_length(int l)
  48. {
  49.     if(l<0)
  50.     {
  51.         length=0;
  52.         return;
  53.     }
  54.     length=l;
  55. }
  56. int rectangle::get_length()
  57. {
  58.     return length;
  59. }
  60. void rectangle::set_breadth(int b)
  61. {
  62.     if(b<0)
  63.     {
  64.         breadth=0;
  65.         return;
  66.     }
  67.     breadth=b;
  68. }
  69. int rectangle::get_breadth()
  70. {
  71.     return breadth;
  72. }
  73. int rectangle::get_area()
  74. {
  75.     area=length*breadth;
  76.     return area;
  77. }
  78. int add(int a,int b)
  79. {
  80.     int sum=a+b;
  81.     return sum;
  82. }
  83. double add(double a,double b)
  84. {
  85.     double sum=a+b;
  86.     return sum;
  87. }
  88.  
  89.  
  90. int main()
  91. {
  92.     rectangle r1(5,4),r2(10,3);
  93.     rectangle r4(3),r3;
  94.     r1.set_length(6);
  95.  
  96.     cout<<"length of r1 is "<<r1.get_length()<<endl;
  97.     cout<<"breadth of r2  is "<<r1.get_breadth()<<endl;
  98.     cout<<"area of r1 is "<<r1.get_area()<<endl;
  99.  
  100.     cout<<"length of r2  is "<<r2.get_length()<<endl;
  101.     cout<<"breadth of r2  is "<<r2.get_breadth()<<endl;
  102.     cout<<"area of r2 is "<<r2.get_area()<<endl;
  103.     cout<<"sum of 3 and 5 is "<<add(3,5)<<"\n";
  104.     cout<<"sum of 3.2 and 5.5 is "<<add(3.2,5.5)<<"\n";
  105.  
  106.  
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement