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:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education