I am working on a program to manage a Hotel in C++. I have a list of Rooms. All these rooms have a Floor number, Room number, and price.
In one of my reports/display functions, I must print out the rooms in an order of Floor numbers, first, then by the Room numbers. What I mean by this is there will be multiple rooms on each floor so if you were sorting all the rooms on floor 1, it will sort the rooms in ascending order before it goes to the next floor.
Now, I understand how to sort the rooms by Floor number, and I know how to sort by Room number. What I don’t understand is how do I combine it so that one does not over write the order of the other.
Thanks in advance.
In order to sort a container of
Rooms, you will need to callstd::sorton it. It has an overload that takes a comparator, i.e. a function object determining whichRoomis “less”. If you want to sort first by floors and then by room numbers, you have to write an appropriate function object (or simply function).