Answer to Question #270128 in C++ for Bulbul

Question #270128

Write a program to print the area of a rectangle by creating a class named'area' having two function . First function named as 'read data' take the length and breadth of the rectangle as parameters and the second function named as 'calculate area' return the area of the rectangle

1
Expert's answer
2021-11-22T15:17:28-0500


#include <iostream>
using namespace std;


class area{
private:
	float length;
	float breadth;
public:
	void readData(float length,float breadth){
		this->length=length;
		this->breadth=breadth;
	}


	float calculateArea(){
		return this->length*this->breadth;
	}
};
int main()
{
	float length;
	float breadth;
	area _area;
	cout<<"Enter length of a rectangle: ";
	cin>>length;
	cout<<"Enter breadth of a rectangle: ";
	cin>>breadth;
	_area.readData(length,breadth);
	cout<<"The area of the rectangle: "<<_area.calculateArea()<<"\n";


	cin>>length;
	return 0;
}

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