This program defines a class named Rectangle that has two public member variables length and breadth and two member functions area() and perimeter(). The area() function returns the area of the rectangle and the perimeter() function returns the perimeter of the rectangle.
In the main() function, an instance of the Rectangle class named r is created and its length and breadth values are set to 5 and 10, respectively. Then, the area() function of the r object is called and its return value is printed to the console using the cout statement.
#include<iostream> using namespace std; class Rectangle { public : int length; int breadth; int area() { return length*breadth; } int perimeter() { return 2*(length+breadth); } }; int main() { Rectangle r; r.length=5; r.breadth=10; cout<<"Area : "<<r.area(); return 0; }To download raw file Click Here
Stack Area : 50Heap Area : 100
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions