Please solve the following problem in C++ and do not use vectors or while(true) make sure there is a condition in the while loop. Make the solution simple and do not use too advanced concepts. Given a hotel with 30 floors numbered 1-30 and up to 100 rooms per floor so that the lower 2 digits are the room number and upper digits are the floor number (e.g. room 1899 is the 99th room on the 18th floor), take reservation inputs that consist of pairs integers that represent the number of nights and a room number (each on a separate line) and terminated by "0 0", and output: (a) the average duration (number of nights) of a reservation (b) the floor number (1-30) that had the most reservations. If there is a tie for the floor with the most reservations, you may output ANY one of the floors that tied. For error checking of input values, ignore any input that has an illegal room number (i.e. above 3099 or below 100) or an input that has a negative number of nights for the reservation. Instead, count how many of these errors occur and output those values. Also output:

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.4: A Case Study: Rectangular To Polar Coordinate Conversion
Problem 9E: (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question

Please solve the following problem in C++ and do not use vectors or while(true) make sure there is a condition in the while loop. Make the solution simple and do not use too advanced concepts.

Given a hotel with 30 floors numbered 1-30 and up to 100 rooms per floor so that the lower 2 digits are the room number and upper digits are the floor number (e.g. room 1899 is the 99th room on the 18th floor), take reservation inputs that consist of pairs integers that represent the number of nights and a room number (each on a separate line) and terminated by "0 0", and output:

(a) the average duration (number of nights) of a reservation

(b) the floor number (1-30) that had the most reservations. If there is a tie for the floor with the most reservations, you may output ANY one of the floors that tied.

For error checking of input values, ignore any input that has an illegal room number (i.e. above 3099 or below 100) or an input that has a negative number of nights for the reservation. Instead, count how many of these errors occur and output those values. Also output:

(c) the number of invalid room numbers entered 

(d) the number of negative reservation durations.

Inputs from the user will contain at least one valid entry so that there will always be a floor with the most reservations and a non-zero average duration.

Use printResults() to output the answers.

An example input and output sequence is shown below.

Sample input:

101 2

3099 3

2054 -1

3100 -1

99 2

-546 3

3064 2

0 0

In the above there are only 3 valid input lines (the first 2 and the last). There are 3 lines with invalid room numbers (3100, 99, -546) and 2 lines with negative night durations. Notice that one input line can contain both and invalid room number AND a negative night duration. 2.3333 is the average number of nights per reservation for the valid inputs. And floor 30 is the floor with the most reservations.

The sample output:

Average nights per reservation: 2.33333
Floor with most reservations: 30
Invalid room numbers: 3
Number of negative nights: 2
 
Also, here is a skeleton code to follow:
#include <iostream>
using namespace std;
void printResults(double avgNights, int mostUsedFloor, int numInvalidRoomNumbers, int numNegativeNights); int main()
{
// Add the code here to declare data values, read the input, // and compute the desired answers.
// call printResults before exiting
return 0;
}
 
void printResults(double avgNights, int mostUsedFloor,
                            int numInvalidRoomNumbers, int numNegativeNights)
{
cout << "Average nights per reservation: " << avgNights << endl;
cout << "Floor with most reservations: " << mostUsedFloor << endl;
cout << "Invalid room numbers: " << numInvalidRoomNumbers << endl;
cout << "Number of negative nights: " << numNegativeNights << endl;
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr