In: Computer Science
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:
Notes
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;
}