1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
garik1379 [7]
3 years ago
6

Write a program that calculates the occupancy rate for ahotel. The program should start by asking the user how many floorsthe ho

tel has. A loop should then iterate once for each floor. Ineach iteration, , the loop should ask the user for the number ofrooms on the floor and how many of them are occupied. After all theiterations, the program should display how many rooms the hotelhas, how many of them are occupied, how many are unoccupied, andthe percentage of rooms that are occupied. The percentage may becalculated by dividing the number of rooms occupied by the numberof rooms.
Requirements:
Do not accept a value less than one for the number offloors
Do not accept a value less than 10 for the number ofrooms on the floor
In this hotel, the third floor is used for restaurants. Theloop in this program should skip the entire third iteration.
Use for loop and while loop in the program
Sample ouput
How many floors does the hotel have?
How many rooms are on floor 1?
How many of those rooms are occupied?
How many rooms are on floor 2?
How many of those rooms are occupied?
How many rooms are on floor 4?
How many of those rooms are occupied?
How many rooms are on floor 5?
How many of those rooms are occupied?
How many rooms are on floor 6?
How many of those rooms are occupied?
The hotel has a total of 65 rooms.
53 are occupied.
12 are unoccupied.
The occupancy rate is 81.5%

Computers and Technology
1 answer:
Oksana_A [137]3 years ago
6 0

Answer:

Here is the C++ program:

#include <iostream>  //to use input output functions

using namespace std;   //to identify objects like cin cout

int main(){  //start of main function

       int MinFloors = 1;  //minimum number of floors

       int MinRooms  = 10; //minimum number of rooms

       int NoOfFloors;  //stores number of floors

       int NoOfRooms;  //stores number of rooms

       int OccupiedRooms;  //stores number of rooms occupied

       double TotalRooms=0, TotalOccupied=0;   //stores computed total number of rooms and total number of occupied rooms

       cout<<"How many floors does the hotel have? ";  //prompts user to enter number of floors

       do{  //iterates until the user enters valid number of floors

           cout<<"(cannot be less than "<<MinFloors<<"): ";  //error message

           cin >>NoOfFloors;  //reads number of floors from user

       }while(NoOfFloors<MinFloors);  //repeats as long as number of floors is less than minimum number of floors

       for(int floor=1; floor <= NoOfFloors; floor++){    //iterates through the floors to skip third iteration

           if(floor == 3){   //if floor is third floor

               continue;             }  

           cout<<"How many rooms are on floor " <<floor;  //prompts user to enter number of floors

           do{  //start of do while loop

               cout<<"(cannot be less than "<<MinRooms<<"): ";  //error message

               cin >>NoOfRooms;  //reads number of rooms from user

           }while(NoOfRooms<MinRooms);    //iterates as long as number of rooms are less than valid minimum number of rooms

           TotalRooms += NoOfRooms;   //adds number of rooms to the count of total number of rooms

           cout<<"How many of those rooms are occupied?";  //prompts user to enter number of rooms occupied

           do{  //start of do while loop

         cout<<"(cannot be less than 0 or greater than "<<NoOfRooms<<"): ";  //generates error message

         cin >>OccupiedRooms;  //reads number of rooms occupied by user

           }while(OccupiedRooms<0 || OccupiedRooms>NoOfRooms);   //iterates as long as the number of occupied rooms are less than 0 or greater than number of rooms

           TotalOccupied += OccupiedRooms;    }    //adds number of rooms occupied to the count of total number of occupied rooms    

       cout<<"\nThe hotel has a total of "<<TotalRooms<<" rooms"<<endl;  //displays the total number of rooms in the hotel

       cout<<TotalOccupied<<" are occupied."<<endl;  //displays the total number of occupied rooms

       cout<<(TotalRooms-TotalOccupied)<<" are unoccupied."<<endl;  //displays the total number of unoccupied rooms

cout<<"The occupancy rate is: "<<100*(TotalOccupied/TotalRooms)<<"%"<<endl;     }  //computes and displays the occupancy rate

   

Explanation:

The program first prompts the user to enter number of floors in the hotel. Lets say user enters 6. This is stored in NoOfFloors So

NoOfFloors = 6

So the loop runs for 6 times

Next it asks user to enter the number of rooms in the floor 1. Lets say user enters 12 so this is stored in NoOfRooms so

NoOfRooms = 12

TotalRooms += NoOfRooms;

this statement keeps adding number of rooms to TotalRooms so

TotalRooms = 12

Next program asks user about the number of occupied rooms. Lets say user enters 10 so this is stored in OccupiedRooms so

OccupiedRooms = 10

this statement keeps adding number of rooms to TotalOccupied so

 TotalOccupied += OccupiedRooms;

TotalOccupied = 10

At next iteration program asks user again to enter number of rooms in floor 2. Suppose user enters 14 so

NoOfRooms = 12

TotalRooms += NoOfRooms;

TotalRooms = 12+14

TotalRooms = 26

Program asks again to enter number of occupied rooms so it becomes:

OccupiedRooms = 8

this statement keeps adding number of rooms to TotalOccupied so

 TotalOccupied += OccupiedRooms;

TotalOccupied = 10+8

TotalOccupied = 18

Next is skips floor 3 and iteration 3. and asks user to enter number of rooms in floor 4. Suppose user enters 14

Number of rooms become:

TotalRooms = 12+14+14

TotalRooms = 40

and suppose user enters 14 as occupied rooms so total occupied become:

TotalOccupied = 10+8 + 14

TotalOccupied = 32

For floor 5: Suppose user enters 13

TotalRooms = 12+14+14+13

TotalRooms = 53

For floor 5: Suppose user enters 10

TotalOccupied = 10+8 + 14+10

TotalOccupied = 42

For floor 6: Suppose user enters 12

TotalRooms = 12+14+14+13+12

TotalRooms = 65

For floor 6: Suppose user enters 11

TotalOccupied = 10+8 + 14+10+11

TotalOccupied = 53

Now the loop breaks

Hence

TotalRooms = 65

TotalOccupied  = 53

total unoccupied = TotalRooms-TotalOccupied = 65-53 = 12

The occupancy rate is: 100*(TotalOccupied/TotalRooms) = 100*(53/65) = 81.5385

The output of the program is attached in a screenshot.

You might be interested in
Windows Hello supports multiple biometric authentication methods, including facial recognition. What is the failsafe method to a
Orlov [11]

Answer:

The failsafe method when facial recognition method is unavailable is the Personal Identification Number (PIN) method.

Explanation:

The Personal Identification Number (PIN) option is available for setup for cases when other biometric authentication methods fail due to several reasons.

6 0
3 years ago
¿la tecnología en Venezuela a nivel educativo, es ideal para desarrollar adecuadamente un proceso de Educación a distancia?
antiseptic1488 [7]

Answer:

There is no longer any doubt at this point that technology in education is absolutely necessary, because, thanks to technological advances in this area, we have more tools to offer more attractive and competent learning models. Teachers have more resources than whiteboards, chalks and books, while students learn by having fun, adapting to their digital environments. We will see below the new challenges that this entails in education and what are its benefits.

4 0
2 years ago
Consider the partially-filled array named a. What does the following loop do? (cin is a Scanner object)int[] a = {1, 3, 7, 0, 0,
boyakko [2]

Answer:

Option 1: May crash at runtime because it can input more elements than the array can hold

Explanation:

Given the code as follows:

  1.        int[] a = {1, 3, 7, 0, 0, 0};
  2.        int size = 3, capacity = 6;
  3.        int value = cin.nextInt();
  4.        while (value > 0)
  5.        {
  6.            a[size] = value;
  7.            size++;
  8.            value = cin.nextInt();
  9.        }

From the code above, we know the <em>a</em> is an array with six elements (Line 1). Since the array has been initialized with six elements, the capacity of the array cannot be altered in later stage.

However, a while loop is created to keep prompting for user input an integer and overwrite the value in the array started from index 3 (Line 4- 9). In every round of loop, the index is incremented by 1 (Line 7). If the user input for variable <em>value</em> is always above zero, the while loop will persist.  This may reach a point where the index value is out of bound and crash the program. Please note the maximum index value for the array is supposedly be 5.  

8 0
3 years ago
To what health hazard are people working in offices most likely to be exposed.
Andrei [34K]

Answer:

Sickness

Explanation:

6 0
3 years ago
A hacker tries to compromise your system by submitting script into a field in a web application that is then stored as data in t
sdas [7]
D cross-site scripting
3 0
3 years ago
Read 2 more answers
Other questions:
  • What is the formula equivalent to the function =SUM(B1:B5)?
    11·2 answers
  • You are configuring a switch that has three hosts attached to FastEthernet 0/2 through 0/4. All three hosts are part of a public
    11·1 answer
  • Henrietta, the owner of a very successful hotel chain in the Southeast, is exploring the possibility of expanding the chain into
    15·1 answer
  • 1. True or false: The more pixels per inch in an image, the higher the resolution is. (1 point)
    8·1 answer
  • Is it possible for a PowerPoint user to add notes to slides and see the added comments
    10·1 answer
  • 3n - 12 = 5n - 2<br> how many solutions?
    15·1 answer
  • What is the term used to describe the basic unit of data passed from one computer to another
    14·1 answer
  • The Uniform Electronic Transmission Act (UETA) a. declares that e-signatures are invalid. b. has only been adopted in a handful
    8·1 answer
  • Can someone write this in java? Also, does anyone know how to do Edhesive assignments?
    15·1 answer
  • What is the most significant difference between improving an existing process and designing a new process?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!