Define a Class to get length and breadth of a rectangle. Get length and breadth from the user, calculate and display its area.
#include <iostream>
using namespace std;
class Rectangle{
private:
float length, breadth;
public:
Rectangle(){}
Rectangle(float length,float breadth){
this->length=length;
this->breadth=breadth;
}
float calculateArea(){
return length * breadth;
}
};
int main (){
float length, breadth;
cout << "Enter length: ";
cin >> length;
cout << "Enter breadth: ";
cin >> breadth;
Rectangle rectangle(length,breadth);
cout << "Area: " << rectangle.calculateArea() << "\n";
system("pause");
return 0;
}
Comments
Leave a comment