Question

In: Computer Science

Hotel Occupancy C++ Only Program Description Write a program that calculates the occupancy rate for a...

Hotel Occupancy

C++ Only

Program Description

Write a program that calculates the occupancy rate for a hotel. The program should read its data from a file named "hotel.dat". The first line of this file will be a single integer specifying the number of floors in the hotel. Each of the remaining (N) lines will have two integers; the number of rooms on that floor and the number of occupied rooms on that floor.

Your program should display the following:

  • How many rooms the hotel has,
  • How many rooms are occupied,
  • How many are unoccupied, and
  • The percentage of rooms that are occupied.

Notes

  1. Your program should be named hotel.cc.
  2. You can build this program initially to read from the keyboard, get that working, and then modify the program to read from the file.
  3. You will need to create the "hotel.dat" data file.

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include<iostream>

#include<iomanip>

#include<fstream>

using namespace std;

int main(){

    ifstream in;

    in.open("hotel.dat");

    if(in.fail()){

        cout<<"Unable to open file"<<endl;

        return 0;

    }

    int no_floors, no_rooms, no_occupied_rooms, total_rooms, total_occupied_rooms;

    int total_unoccupied_rooms;

    double percentage_occupied;

    in>>no_floors;

    for(int i=0; i<no_floors; i++){

        in>>no_floors>>no_occupied_rooms;

        total_rooms += no_floors;

        total_occupied_rooms += no_occupied_rooms;

    }

    total_unoccupied_rooms = total_rooms-total_occupied_rooms;

    percentage_occupied = (double)total_occupied_rooms/total_rooms;

    cout<<setprecision(2)<<fixed;

    cout<<"Total rooms the hotel has "<<total_rooms<<endl;

    cout<<"Total rooms occupied "<<total_occupied_rooms<<endl;

    cout<<"Total rooms unoccupied "<<total_unoccupied_rooms<<endl;

    cout<<"Percentge of rooms occupied "<<percentage_occupied<<"%"<<endl;

    return 0;

}


Related Solutions

IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel....
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations,...
Write a program that calculates the occupancy rate for each floor of a hotel. (Use a...
Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations, the program...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy...
Using Loops for the Hotel Occupancy calculator. You will write a program that calculates the occupancy of a hotel. Rules: 1# The hotel must have more than 2 floors and less than or equal 5 floors. 2# Each floor in the hotel can have a different number of rooms on the floor. 3# You must set the number of occupied rooms. Again, there must less rooms occupied than the number of rooms. 4# Using the total number of rooms and...
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 JAVAProgram #1: Hotel Occupancy: 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. A for loop should then iterate once for each floor. In each iteration of the for loop, the program should ask the user for the number of rooms of the floor and how many of them are occupied. After all of the iterations are complete the program should display how...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $ 0.35 per mile. Your program should interact with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading: 13505.2 Enter ending odometer reading     : 13810.6 You traveled 305.40 miles. At $ 0.35 per mile, your reimbursement is $ 106.89. The values in red color are inputs for the program. The values in blue color are results of expressions.
Write a C program that calculates a worker’s wages from their hours worked and hourly rate....
Write a C program that calculates a worker’s wages from their hours worked and hourly rate. This wage calculator should also account for overtime hours, calculate amount to be witheld from taxes, and calculate the final net income. Required functionality: 1. Ask the user for the number of hours worked and hourly rate in dollars. The program should be able to accept decimal values for both of these (e.g. 3.2 hours, 11.25 dollars/hour) 2. Overtime hours are those worked in...
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
Following are the number of victories for the Blue Sox and the hotel occupancy rate for...
Following are the number of victories for the Blue Sox and the hotel occupancy rate for the past eight years. You have been asked to test three forecasting methods to see which method provides a better forecast for the Number of Blue Sox Wins. Year Number of Blue Sox Wins Occupancy Rate 1 70 78% 2 67 83 3 75 86 4 87 85 5 87 89 6 91 92 7 89 91 8 85 94 For the following, you...
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is worth 4 points, a B is worth 3 points, a C is worth 2 points, a D is worth 1 point, and an F is worth 0 points. For the purposes of this assignment, assume that all classes carry the same number of credit hours. 2) Use a sentinel-controlled loop to gather a variable number of letter grades. This should terminate the loop if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT