Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:48:41+00:00 2026-06-07T14:48:41+00:00

I am working on a program to manage a Hotel in C++. I have

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:48:42+00:00Added an answer on June 7, 2026 at 2:48 pm

    In order to sort a container of Rooms, you will need to call std::sort on it. It has an overload that takes a comparator, i.e. a function object determining which Room is “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).

    bool CompareByFloorAndRoomNo(const Room& r1, const Room& r2) 
    {
        if(r1.FloorNo() != r2.FloorNo())
            return r1.FloorNo() < r2.FloorNo();
        return r1.RoomNo() < r2.RoomNo();
    }
    
    ...
    
    int main()
    {
        ...
        std::sort(rooms.begin(), rooms.end(), CompareByFloorAndRoomNo);  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a program to store and manage test results. Tests have properties
Greetings, Forum. I'm working on a program in Python that uses Twisted to manage
I have a working program in C++ that generates data for a Mandelbrot Set.
I have a working C program where the length of an array of strings
I have developed a program in iphone which manage cards, the main functionality is
I working on a program that manages documents. One of the things my app
Working with C and Win32, I have a problem where my program freezes instead
I've managed to get my pthreads program sort of working. Basically I am trying
is there any small working program for recieving from and sending data to client
how can i make java program working with multiple languages (frensh, english , arabic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.