#pragma once
class Rectangle
{
private:
float length;
float width;
public:
Rectangle();
void setLength(float l);
void setWidth(float w);
float getLength();
float getWidth();
float area(float length, float width);
void print();
};
#include <iostream>
#include "Rectangle.h"
using namespace std;
Rectangle::Rectangle() {
length = width = 0;
}
void Rectangle::setLength(float l) {
length = l;
}
void Rectangle::setWidth(float w) {
width = w;
}
float Rectangle::getLength() {
return length;
}
float Rectangle::getWidth() {
return width;
}
float Rectangle::area(float length, float width) {
float a = (float)length * width;
return a;
}
void Rectangle::print() {
cout << "Length= " << getLength() << endl;
cout << "Width= " << getWidth() << endl;
cout << "Area= " << area(length, width) << endl;
}
#include <iostream>
#include "Rectangle.h"
using namespace std;
int main() {
float length, width;
Rectangle rectangle;
cout << "Enter length of the rectangle: ";
cin >> length;
cout << "Enter width of the rectangle: ";
cin >> width;
rectangle.setLength(length);
rectangle.setWidth(width);
rectangle.print();
}