This program defines a Rectangle class with private data members length and breadth, and a public member function area() that calculates and returns the area of the rectangle. In the constructor of the class, default values of length and breadth are set to 0. The constructor takes arguments for length and breadth and initializes the corresponding data members using this pointer.
In the main() function, an object r of the Rectangle class is created with length = 10 and breadth = 5. The area() function of the object r is called to calculate and display the area of the rectangle.
#include<iostream> using namespace std; class Rectangle { private : int length; int breadth; public : Rectangle(int length=0,int breadth=0) { this->length=length; this->breadth=breadth ; } int area() { return length*breadth; } }; int main() { Rectangle r(10,5); cout<<"Area : "<<r.area(); return 0; }To download raw file Click Here
Area : 50
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions