Math, asked by shahsanjay5983, 1 year ago

Define a class rectangle wch has a length and a breadth. define the constructors and the destructor and member functions to get the length and the breadth. write a global function wch creates an instance of the class rectangle and computes the area using the member functions.

Answers

Answered by mad210203
0

Program is given below.

Explanation:

#include <iostream>

using namespace std;

class rectangle

{

   private:

       int length;

       int breadth;

       int area;

   public:

   //Constructor

      rectangle(int x, int y)

       {

       getvalues(x,y);

       area_of_rectangle();

       }

   //Destructor

      ~rectangle()

       {

       }

   //Functions to get the values of length and the breadth

       void getvalues(int l, int b)

       {

       length = l;

       breadth = b;

       cout<<"The Length of the Rectangle is: "<<length<<endl;

       cout<<"The Breadth of the Rectangle is: "<<breadth<<endl;

       }

  //Function to find the area of the rectangle

      void area_of_rectangle()

       {

       area = length * breadth;

       cout << "\nThe Area of the Rectangle is: " <<area;

       }

};

int main ()

{

  rectangle my_rectangle(4,5);

  return 0;

}

Refer the attached image for the output.

Attachments:
Similar questions