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

  • Home
  • SEARCH
  • 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 7700341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:41:10+00:00 2026-05-31T22:41:10+00:00

For my class, I am making a program that manages a Hotel. My ‘Test’

  • 0

For my class, I am making a program that manages a Hotel. My ‘Test’ method creates random rooms and random customers. Once it has does this, it then takes the random customers it created, and checks them into the random rooms it created.

My goal is for the Test to check-in only HALF of the rooms with customers. And leave the other half of the rooms empty. And also, I can only have 1 customer per room.

The method compiles, but their are some flaws:

  1. The ‘Test’ fills ALL the rooms with customers (instead of only half of them).
  2. The ‘Test’ will often assign a single room to multiple customers( For example, Room 301 will now belong to 3 different customers instead of just 1)

Can anyone help me figure out how to fill only half of the rooms that are created.
And also help me figure out how to not let a single room be applied to more than 1 customer? I am pretty sure that the last FOR loop in the method should be the only thing that I need to adjust.

string Hotel::test(int numRooms, int numCustomers)
{
    string result;
    for(int i=0;i<numRooms;i++) // **********CREATES RANDOM ROOMS
    {
        Room iRoom(randString(8),
                   randInt(0,1000),
                   randInt(0,1000),
                   randInt(0,1000),
                   randInt(0,1000));
        listofrooms.add(iRoom);
    }
    for(int i=0;i<numCustomers;i++) // ***********CREATES RANDOM CUSTOMERS
    {
        Customer cus(randString(8),randNumberString(10),randNumberString(16));
        listofcustomers.add(cus);
    }

    for(int i=0;i<numCustomers+numRooms;i++) // **FILLS RANDOM ROOMS WITH RANDOM CUSTOMERS
    {                                        // **I KNOW THIS IS THE ONLY LOOP I NEED TO ADJUST
        checkIn(listofrooms.getRandID(),listofcustomers.getRandID());
    }

    return result;
}
  • 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-05-31T22:41:11+00:00Added an answer on May 31, 2026 at 10:41 pm

    Part 1

    You need half the rooms to be filled. Since only 1 guest can be in any room, you need to fill the rooms numRooms times. So, you just need to adjust your loop to:

    for (int i = 0; i < numRooms/2; i++)
    

    Part 2

    There are many ways to ensure that. The naive approach would be to retry in a loop

    for (int i = 0; i < numRooms/2; i++)
    {
        int assignedRoom;
        do
        {
            assignedRoom = listofrooms.getRandID();
        } while (isFull(assignedRoom);
        checkIn(assignedRoom, listofcustomers.getRandID());
    }
    

    Of course, you wouldn’t want the same customer in two rooms, so you need to do the same thing with customers also.

    Another method could be to take a random room, and if it was full iterate to next rooms (wrapping around to first room if overflow) until you find an empty room.

    Another method could be to random_shuffle a copy of the rooms and take the first half.

    Like I said, whatever you do with the rooms, you need to do with the customers also.

    recommendation: Perhaps the best distribution is achieved with the last method (the one with random_shuffle. Note that the naive approach has a non-deterministic (and possibly bad) performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im making a program for class that manages a Hotel. I have a function
I am making a program for class that manages a Hotel. I am able
I'm making a program that allows you to add any class file that extends
I'm making a program that imports a custom widget that is a class (it
I'm making a program that has three classes: Output class receives data from other
I'm making a program that can access data stored inside a class. So for
I'm making a simple program in Objective-C. It has one class with a lot
I am making a class Customer that has the following data members and properties:
While making some final tests of a class-library that I'm writing for Windows Mobile
Im making a login/logout class that logs users in, sets cookies based on user's

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.