Answer to Question #246987 in Java | JSP | JSF for raj

Question #246987

Create A Class Named 'Rectangle' With Two Data Members 'Length' And 'Breadth' And Two Methods To Print The Area And Perimeter Of The Rectangle Respectively. Its Constructor Having Parameters For Length And Breadth Is Used

1
Expert's answer
2021-10-05T13:23:35-0400
#include <iostream>
class Rectangle
{
public:
	Rectangle() {}
	explicit Rectangle(float i) : length(i), breadth(i)
	{}
	Rectangle(float a, float b) :length(a), breadth(b)
	{}
	void Calculate() { std::cout << length * breadth<<std::endl; }


private:
	float length {0},
		   breadth {0};
	
};
int main()
{
	Rectangle r1;
	Rectangle r2{ 10 };
	Rectangle r3{ 15,45 };
	r1.Calculate();
	r2.Calculate();
	r3.Calculate();
	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