Write a program to print the area of a rectangle by creating a class named'area' having two function . First function named as 'read data' take the length and breadth of the rectangle as parameters and the second function named as 'calculate area' return the area of the rectangle
#include <iostream>
using namespace std;
class area{
private:
float length;
float breadth;
public:
void readData(float length,float breadth){
this->length=length;
this->breadth=breadth;
}
float calculateArea(){
return this->length*this->breadth;
}
};
int main()
{
float length;
float breadth;
area _area;
cout<<"Enter length of a rectangle: ";
cin>>length;
cout<<"Enter breadth of a rectangle: ";
cin>>breadth;
_area.readData(length,breadth);
cout<<"The area of the rectangle: "<<_area.calculateArea()<<"\n";
cin>>length;
return 0;
}
Comments
Leave a comment