Computer Science, asked by hardikaryan106, 6 days ago

write a program in c++ to find the area of circle and rectangle by using default and parameterized constructor.​

Answers

Answered by shubhamkumarmishra25
0

INPUT :

/*  C++ Program to find Area of Rectangle using constructor  */

#include <iostream>

using namespace std;

class CRectArea

{

   private:

       int length;

       int breadth;

   public:

       CRectArea (int,int);

       int areaofrect ()

       {

           return (length * breadth);

       }

       int length1()

       {

           return length;

       }

       int breadth1()

       {

           return breadth;

       }

};

CRectArea::CRectArea(int x, int y)

{

   length = x;

   breadth = y;

}

int main ()

{

   CRectArea myrectangle (2,2);

   cout<<"The Length of Rectangle :: "<<myrectangle.length1()<<"\n";

   cout<<"\nThe Breadth of Rectangle :: "<<myrectangle.breadth1()<<"\n";

   cout << "\nThe area of rectangle is :: " << myrectangle.areaofrect()<< endl;

   return 0;

}

OUTPUT :  

/*  C++ Program to find Area of Rectangle using constructor  */

The Length of Rectangle :: 2

The Breadth of Rectangle :: 2

The area of rectangle is :: 4

Process returned 0

Similar questions