Question #336073

A C++ program to print the area of a rectangle by creating a class named Area having two functions, first function named as Setdim takes the length and width of rectangle as parameters and second function named as getArea returns the area of the rectangle, length and width are entered through keyboard.

Expert's answer

#include<iostream>

using namespace std;

class Area
{
	float length;
	float width;
public:
	Area(){}
	void Setdim()
	{
		cout << "Please, enter a length: ";
		cin >> length;
		cout << "Please, enter a width: ";
		cin >> width;
	}
	float getArea()
	{
		return length*width;
	}
};
int main()
{
	Area a;
	a.Setdim();
	cout << "The area of a rectangle is " << a.getArea();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS