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>
class Rectangle{
private:
float length, breadth;
public:
void GetDimensions(){
std::cout << "Input length:";
std::cin >> length;
std::cout << "Input breadth:";
std::cin >> breadth;
}
void DisplayArea(){
float area = length * breadth;
std::cout << "Area:" << area << "\n";
}
};
int main(){
Rectangle rectangle;
rectangle.GetDimensions();
rectangle.DisplayArea();
return 0;
}
Comments
Leave a comment