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.
#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;
}
Comments
Leave a comment