Question

In: Computer Science

In c++, please make it short and simple A hotel chain needs a program which will...

In c++, please make it short and simple

A hotel chain needs a program which will produce statistics for the hotels it owns.

Write a program which displays the occupancy rate and other statistics for any of the chain’s large hotels (all are 20 floors with 16 rooms each floor).

In main:

-declare a 20 X 16 array of “int” named hotel to represent a hotel’s 20 floors and 16 rooms per floor.

Then in main, repeatedly:

-call a function which fills the hotel array with 1s and 0s, where 1 indicates an occupied room and 0 indicates an unoccupied room. Call a second function to validate that each entry is either 1 or 0 by having the second function access the original entry using a pointer in its parameter list.

-pass the hotel array to a third function which dynamically allocates a new size 20 “int” array with each element representing a floor of the hotel and the floor’s number of occupied rooms; place the number of occupied rooms of each floor into the new array and return it to main.

-display the floor number** and number of occupied rooms on each floor by incrementing the address of the new array.

-also calculate and display the hotel’s overall occupancy rate to 1 decimal (total rooms occupied per total rooms), and the floor number** and number of occupied rooms of the floor with the highest occupancy.

-process another hotel (unknown number of hotels in chain).

**NOTE: hotels do not have a floor numbered 13 due to guests’ superstitions.

To create your screen print, temporarily set the floors and rooms to 3 and 5 respectively to reduce data entry, and enter:

Floor #1: occupied, occupied, unoccupied, occupied, unoccupied

Floor #2: occupied, unoccupied, occupied, occupied, occupied

Floor #3: occupied, unoccupied, unoccupied, unoccupied, occupied

Solutions

Expert Solution

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks.

Code:

#include<iostream>
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <string>
#define NUM_FLOORS 20
#define NUM_ROOMS 16
using namespace std;

void fillHotelRandom(int hotel[NUM_FLOORS][NUM_ROOMS])
{
   srand (time(NULL));
   for(int i=0;i<NUM_FLOORS;i++){
       for(int j=0;j<NUM_ROOMS;j++){
           hotel[i][j]=rand()%2;
       }
   }
}

void fillHotelUser(int hotel[NUM_FLOORS][NUM_ROOMS])
{
   string input;
   for(int i=0;i<NUM_FLOORS;i++){
       if(i!=12){
           cout<<"FLOOR #"<<i+1<<": ";
           for(int j=0;j<NUM_ROOMS;j++){
               cin>>input;
               if(input=="occupied" ||input=="occupied,"){
                   hotel[i][j]=1;
               }else{
                   hotel[i][j]=0;
               }
           }
       }
   }
}

bool validateHotel(int *hotel){
   for(int i=0;i<NUM_FLOORS;i++){
       if(i!=12){
           for(int j=0;j<NUM_ROOMS;j++){
               int val=*((hotel+i*NUM_ROOMS)+j);
               if(val!=0 && val!=1){
                   return false;
               }
           }
       }
   }
   return true;
}

int* occupiedRooms(int hotel[NUM_FLOORS][NUM_ROOMS]){
   int *occupied;
   occupied=new int[NUM_FLOORS];
   for(int i=0;i<NUM_FLOORS;i++){
       if(i!=12){
           for(int j=0;j<NUM_ROOMS;j++){
               if(j==0){
                   occupied[i]=0;
               }
               if(hotel[i][j]==1){
                   occupied[i]=occupied[i]+1;
               }
           }
       }
   }
   return occupied;
}
void main(){
   int hotel[NUM_FLOORS][NUM_ROOMS];
   int *occupied;
   bool result;
   char choice='y';
   while(choice=='y'){
       //fillHotelRandom(hotel);
       fillHotelUser(hotel);
       result=validateHotel((int *)hotel);
       if(!result){
           cout<<"Invalid Data\n";
       }else{
           occupied=occupiedRooms(hotel);
           for(int i=0;i<NUM_FLOORS;i++){
               if(i!=12){
               cout<<"Room #"<<i+1<<" Total rooms booked :"<<occupied[i]<<" Occupancy Rate :"<<(double)occupied[i]/NUM_ROOMS<<endl<<endl;
               }
           }
       }
       cout<<"Do you want to continue ?(Press y)\n";
       cin>>choice;
   }
   system("pause");
}

Output:


Related Solutions

C++ program, I'm a beginner so please make sure keep it simple Write a program to...
C++ program, I'm a beginner so please make sure keep it simple Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File.txt: Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets...
Make a simple game using C++ which implements all about Object Oriented Programming (Please make an...
Make a simple game using C++ which implements all about Object Oriented Programming (Please make an explanation which of each part in it)
C language only please and please make a simple code Write a function that will find...
C language only please and please make a simple code Write a function that will find whether there exist two integers that sum to the target integer. The function is to “return” three values.First, return “1” if the integers were found,return “-1” if your search was not successful.If you find two integers which add up to the target value, you should return their respective index position inside the array. Suggested prototype:int TwoSumFunction(int arr[], int size, int target, int*index1, int* index2);Inside...
Write a short and simple C++ program (must be able to have custom inputs): Design a...
Write a short and simple C++ program (must be able to have custom inputs): Design a class that holds the following personal data: name, address, age, and phone number Write appropriate accessor and mutator functions. Demonstrate the class by writing a program that creates three instances of it. One instance should hold your information, and the other two should hold your friends' or family members' information. Thanks!!
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem you will take a list of names from the user and sort them alphabetically using selection sort. The code for selection sort for integer is available in the "Lab and Weekly Coding Solution module" in webcourses. Ask the user how many names the user wants to input. Let's say the number be N. Then take N number of names and put them in an...
Paraphrase the following. please try not to make it short. needs urgently.. thanks in advance. i...
Paraphrase the following. please try not to make it short. needs urgently.. thanks in advance. i just want to avoid plagiarism. Significant research has been completed regarding the importance of effective preparation of principals as school leaders and fundamental changes in the school environment. Curriculum Design - Principals are faced with the critical task of assigning teachers in different grades which includes special need teachers as well to teach curriculum that is comprehensive and more encompassing. While assigning grades principle...
C++ questions about Monty Hall Problem, please make sure to divide the program into functions which...
C++ questions about Monty Hall Problem, please make sure to divide the program into functions which perform each major task. Imagine yourself on the set of a game show. You're given the choice of three doors. Behind one of the doors is a car you can drive home in if you guess correctly. Behind the other two doors are goats. After you initially guess the door, the host of the game show (who knows the door holding the car) opens...
USE C++ and please keep program as simple as possible and also comment so it is...
USE C++ and please keep program as simple as possible and also comment so it is easy to understad Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the...
C++ questions, please make sure to dividet he program into functions which perform each major task,...
C++ questions, please make sure to dividet he program into functions which perform each major task, A leap year is defined as any calendar year which meets the following criteria: If the year is not divisible by 4, it is a common year If the year is not divisible by 100, it is a leap year If the year is not divisible by 400, it is a common year Otherwise it is a leap year For your program you will...
C++ questions, Please make sure to divide your program into functions which perform each major task....
C++ questions, Please make sure to divide your program into functions which perform each major task. The game of rock paper scissors is a two player game in which each each player picks one of the three selections: rock, paper and scissors. The game is decided using the following logic: ROCK defeats SCISSORS (“smashes”) PAPER defeats ROCK (“wraps”) SCISSORS defeats PAPER (“slices”) If both players choose the same selection the game ends in a tie. Write a program that asks...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT