Answer to Question #336073 in C++ for Dunnymore

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.

1
Expert's answer
2022-05-01T19:06:00-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS