This is a program to calculate the area of a rectangle using classes and objects in C++.
Overall, this program demonstrates how classes and objects can be used to encapsulate data and behavior related to a rectangle's area.
#include<iostream> using namespace std; class Area { private: int length; int breadth; public: Area(): length(7), breadth(4){ } void GetLength() { cout<<"\nEnter length of the Rectangle: "; cin>>length; cout<<"\nEnter breadth of the Rectangle: "; cin>>breadth; } int Calculation() { return (length*breadth); } void Display(int temp) { cout<<"Area: "<<temp; } }; int main() { Area A1,A2; int temp; A1.GetLength(); temp=A1.Calculation(); A1.Display(temp); cout<<endl<<"\nDefault Area when value is not taken from user"<<endl; temp=A2.Calculation(); A2.Display(temp); return 0; }To download raw file Click Here
Enter length of the Rectangle: 20 Enter breadth of the Rectangle: 10 Area: 200 Default Area when value is not taken from user Area: 28
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions