Define the Rectangle class
Define a class called Rectangle
and add two public attributes length
and breadth
to it.
#include <iostream>
using namespace std;
//Rectangle class to demonstrate the use of Constructor and Destructor in CPP
class Rectangle {
public:
float length, breadth;
//Declaration of the default Constructor of the Rectangle Class
public:
Rectangle() {
cout<<"Constructor Called"<<endl; //displaying the output when called
length = 2;
breadth = 4;
}
//Declaration of the Destructor of the Rectangle Class
public:
~Rectangle() {
cout<<"Destructor Called"<<endl; //displaying the output before destruct
}
};