Question

In: Computer Science

( C++ ) Occupancy rate is often considered to be one of the top three most...

( C++ ) Occupancy rate is often considered to be one of the top three most useful metrics for hotel owners. Generally speaking, those working in the hotel industry should be aiming for a high occupancy rate, because this indicates that space is being used efficiently.

The occupancy rate of a hotel is expressed as a percentage. So, for example, if a hotel has 100 rooms available to be sold and 60 of those rooms are occupied, the occupancy rate would be 60 percent.

How to Calculate Occupancy Rate

The occupancy rate can be calculated with the following formula:

Occupancy Rate = Number of Occupied Rooms / Total Number of Available Rooms

Example: If your hotel has 220 rooms and 210 of the rooms are occupied:

210 / 220 = 0.95 = 95 percent occupancy rate.

Program Description

Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. Use the following message for the prompt: "How many floors does the hotel have? ".

A loop should then iterate once for each floor. In each iteration, the loop should ask the user for the number of rooms on the floor and how many are occupied. Use the following messages for the prompts:

"\nEnter the number of rooms on floor <floor number>: " and "\nHow many rooms are occupied on floor <floor number>? ".

Note: <floor number> should be substituted whith the floor number.

After all the iterations complete, the program should display a report similar to the following:

Total number of rooms: 330
Occupied rooms: 264
Unoccupied rooms: 66
Occupancy Rate: 0.80

Note: A new line should be displayed before the report is displayed and the occupancy rate should be displayed with 2 digits after the decimal.

Hint: Your program should use 2 accumulators to keep track of the total number of rooms in the hotel and how many rooms are occupied. Don't forget to initialize these variables to zero.

Input Validation

  • Number of floors must be 1 or greater.
  • Number of rooms on a floor must be 10 or greater.
  • Number of occupied rooms must be a number between 0 and the number of rooms on that floor.

Loops should be used to continue prompting the user for input, until it is valid. If invalid input is entered, an error message should be displayed and the input should be read again. Use the error messages below.

Error messages:

  • "\n->Number of floors must be 1 or greater. Try again: "
  • "\n->Number of rooms must be 10 or greater. Try again: "
  • "\n->Number of occupied rooms must be between 0 and <max rooms>. Try again: "

Note: <max rooms> should be replaced with the maximum number of rooms on the respective floor.

Reminder

Don't forget that to avoid integer division, one of the operands should be a floating point number. One way to avoid this is to use the static_cast operator to convert one of the operands to a double before dividing. Keep this in mind when you calculate the occupancy rate.

Solutions

Expert Solution

//The code will be

#include <iostream>

using namespace std;

int main() {
  
   int noFloors, totalRooms = 0, totalOccupiedRooms = 0, rooms, occupiedRooms, i;
   cout<<"How many floors does the hotel have? ";
   cin>>noFloors;
   while(noFloors < 1) {
       cout<<"\n->Number of floors must be 1 or greater. Try again: ";
       cin>>noFloors;  
   }
   for(i=1;i<=noFloors;i++){
       cout<<"\nEnter the number of rooms on floor "<<i<<": ";
       cin>>rooms;
       while(rooms<10){
           cout<<"\n->Number of rooms must be 10 or greater. Try again: ";
           cin>>rooms;
       }
       cout<<"How many rooms are occupied on floor "<<i<<"? ";
       cin>>occupiedRooms;
       while(occupiedRooms<0 || occupiedRooms>rooms)
       {   cout<<"\n->Number of occupied rooms must be between 0 and "<<rooms<<". Try again: ";
           cin>>occupiedRooms;
       }
       totalRooms += rooms;
       totalOccupiedRooms += occupiedRooms;
   }
   double occupancyRate = (double)totalOccupiedRooms/(double)totalRooms;
   //Output
   cout<<"\nTotal number of rooms: "<<totalRooms;
   cout<<"\nOccupied rooms: "<<totalOccupiedRooms;
   cout<<"\nUnoccupied rooms: "<<(totalRooms-totalOccupiedRooms);
   printf("\nOccupancy Rate: %.2f",occupancyRate);
   return 0;
}

//The output will be


Related Solutions

QWhich of the following are considered to be one of the top nine characteristics of a...
QWhich of the following are considered to be one of the top nine characteristics of a programming language (choose all that apply): o Simplicity o Recursive adaptation o Restricted aliasing o Semantic evaluation Q list six features of programming functionality provided by the plankalkül programming language. QWhat language(s) are direct predecessors to the PHP programming language? (choose any that apply): o Fortran I o Perl o Awk o ICON Q Based on the Von Neumann Architecture which of the following...
We want to investigate now whether the average occupancy rate in May differs across the three...
We want to investigate now whether the average occupancy rate in May differs across the three regions.2.1 State the null and alternative hypotheses for the above research question.2.2 Conduct a Levene test for the homogeneity of the variances at the 10% level using the absolute deviations from the median. Make sure you state both the null and alternative hypotheses and the conclusions of your test.2.3 Test the null hypothesis in 1.1 at the 10% significance level.2.4 What can you conclude...
We want to investigate now whether the average occupancy rate in May differs across the three...
We want to investigate now whether the average occupancy rate in May differs across the three regions.2.1 State the null and alternative hypotheses for the above research question.2.2 Conduct a Levene test for the homogeneity of the variances at the 10% level using the absolute deviations from the median. Make sure you state both the null and alternative hypotheses and the conclusions of your test.2.3 Test the null hypothesis in 2.1 at the 10% significance level.2.4 What can you conclude...
We want to investigate now whether the average occupancy rate in May differs across the three...
We want to investigate now whether the average occupancy rate in May differs across the three regions.2.1 State the null and alternative hypotheses for the above research question.2.2 Conduct a Levene test for the homogeneity of the variances at the 10% level using the absolute deviations from the median. Make sure you state both the null and alternative hypotheses and the conclusions of your test.2.3 Test the null hypothesis in 1.1 at the 10% significance level.2.4 What can you conclude...
Why is ROE considered one of the best measurements of top managements performance . A PE...
Why is ROE considered one of the best measurements of top managements performance . A PE ratio of 20:1 means that an investor is paying $20 for every dollar of income the company is generating. (true or false) The ECB is charging negative interest rates to its member banks. What is the logic behind this?
"Tale of Genji" is often considered the first novel in history. Give three traits that make...
"Tale of Genji" is often considered the first novel in history. Give three traits that make this story "novel-like" and describe how similar or different these traits are to modern novels. You may want to look up the definition of a novel, or compare it to other modern books like it.
There are a handful of top coffee companies but one of the most well-known companies is...
There are a handful of top coffee companies but one of the most well-known companies is Starbucks. The high-priced, high-quality coffee and beverages are quality products that keep customers returning for more. From their famous pumpkin spice latte to Frappuccino’s appeal to both adults and kids. To properly advertise their coffee, Starbucks uses multiple distribution channels. The most common method is the retail stores. Customers can order their coffee in advance via their mobile app and pick it up hot...
In most organisations customer satisfaction is one of the top priorities. As such attention to customers...
In most organisations customer satisfaction is one of the top priorities. As such attention to customers is necessary for success. Briefly describe the four dimensions of high performance that customers expect companies to deliver through effectively managing and running their business operations
Rachel Carson. Carson’s most famous book, Silent Spring, is often named as one of the most...
Rachel Carson. Carson’s most famous book, Silent Spring, is often named as one of the most important books of the 20th century, and she is frequently called the mother of the modern environmental movement. Yet some question her relevance to today’s environmental debates, and others view her as a divisive or discredited figure. This week, we’ll discuss who Rachel Carson was and how her ideas and viewpoints still resonate in the 21st century. As a freelance writer, I’ve told Carson’s...
Mosquitoes are considered one of the most deadly animals on Earth. As outlined in the modules...
Mosquitoes are considered one of the most deadly animals on Earth. As outlined in the modules this week, they are host to a number of infectious diseases that result in almost a million deaths each year. Currently, the most effective methods to control mosquitoes use insecticides that are toxic to both the environment and humans.  What if we could control mosquito populations without causing environmental damage with insecticides? What if we could alter the properties of a mosquito in such a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT