You are calling the display method on your Hotel object and that displays the Floors within that Hotel, but you never correctly initialized the Floor objects stored
inside your Hotel object. Instead you created and initialized a
separate Floor object (which is not connected to your Hotel).
If you want to initialize your Hotel's Floors, you need to loop over these Floors and initialize each of them separately.
P.S.: since you asked for more help, I modified the code to include the initialization. Most importantly, I changed the two classes to let you construct them as fully initialized objects. The most prominent changes are the introduction of a factory method for your Floor class and the addition of a loop in main() to construct the floors of your hotel:
#include<iostream>
#include<string>
#include <vector>
using namespace std;
class Floor {
private:
int available_rooms;
public:
Floor();
Floor(const Floor& other_floor); Floor& operator=(const Floor& other_floor); static Floor make_floor_with_rooms(int number_of_rooms); void set_available_rooms(int ar);
int get_available_rooms();
void display();
};
class Hotel {
protected:
string name;
std::vector<Floor> floor_arr;
public:
Hotel(const string& hotel_name); void add_floor(const Floor& floor); void display();
};
Hotel::Hotel(const string& hotel_name) : name(hotel_name) {}
void Hotel::add_floor(const Floor& floor) {
floor_arr.push_back(floor);
}
void Hotel::display() {
auto floor_number = floor_arr.size(); cout << "The available floors are: " << floor_number << endl;
int x;
cout << "Select Floor" << endl;
cin >> x;
if (x < 1 || x > floor_number)
cout << "Enter Valid Input" << endl;
else
floor_arr[x-1].display(); }
Floor::Floor() {
available_rooms = 0;
}
Floor::Floor(const Floor& other_floor) { available_rooms = other_floor.available_rooms;
}
Floor& Floor::operator=(const Floor& other_floor) { available_rooms = other_floor.available_rooms;
return *this;
}
Floor Floor::make_floor_with_rooms(int number_of_rooms) {
Floor new_floor; new_floor.set_available_rooms(number_of_rooms);
return new_floor; }
void Floor::set_available_rooms(int ar) {
available_rooms = ar;
}
int Floor::get_available_rooms() {
return available_rooms;
}
void Floor::display() {
cout << "The available rooms are " << available_rooms << endl;}
int main() {
int a, b;
Hotel my_hotel("Hotel California");
cout << "Enter available floors" << endl;
cin >> a;
for (int i = 0; i < a; ++i) {
cout << "Floor " << i+1 << ". "; cout << "Enter available rooms" << endl;
cin >> b;
my_hotel.add_floor(Floor::make_floor_with_rooms(b));
}
my_hotel.display();
return 0;
}