Answer to Question #174860 in C++ for sivasurya

Question #174860

Define a Class to get length and breadth of a rectangle. Get length and breadth from the user, calculate and display its area.


1
Expert's answer
2021-03-23T13:59:29-0400
#include <iostream>


using namespace std;


class Rectangle{
private:
    float length, breadth;
public:
	Rectangle(){}
	Rectangle(float length,float breadth){
		this->length=length;
		this->breadth=breadth;
	}
    
    float calculateArea(){
        return length * breadth;
    }
};




int main (){
	float length, breadth;
	cout << "Enter length: ";
    cin >> length;
        
    cout << "Enter breadth: ";
    cin >> breadth;


	Rectangle rectangle(length,breadth);
    cout << "Area: " << rectangle.calculateArea() << "\n";
	system("pause");
	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