Answer to Question #288137 in C++ for anshul

Question #288137

Create a Class Room_Area in C++ with following description: - Private data members: length (float): 

to store the length of a room width (float): to store the width of a room Public member functions: 

Set_data():- to input the values of length and width of a room. Print_data():- to display the values of 

length and width of a room. Create a Friend function Area () to calculate the area of a rectangular room. 

Invoke the member function and friend function in main() to provide the desired outputs.


1
Expert's answer
2022-01-17T12:58:40-0500
#include <iostream>
using namespace std;




class Room_Area{
private:
	float length;
	float width;


public:
	void Set_data(){
		cout<<"Enter length: ";
		cin>>length;
		cout<<"Enter width: ";
		cin>>width;
	}


	void Print_data(){
		cout<<"The length: "<<length<<"\n";
		cout<<"The width: "<<width<<"\n";
	}
	friend float Area(Room_Area room_Area);
};


float Area(Room_Area room_Area){
	return room_Area.length*room_Area.width; 
}


int main() {
	Room_Area room_Area;
	room_Area.Set_data();
	room_Area.Print_data();
	cout<<"Area: "<<Area(room_Area)<<"\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