i want to alter the program below to the following a & b.
a. Write a program by amending the program B2 above, so that as well as being able to
book a particular hour in the day, the user can request the first free hour of the day.
b. Write a program by amending the program B2 above (this is a bit more tricky), so that the
user can make an appointment of more than one hour in length. The user enters a start hour
(e.g. 10 ) and required length in hours (e.g. 2). The program checks to see if the whole
period is free and if it is it makes the booking, otherwise it rejects it.
====================
the program
====================
#include <iostream>
class Day{
private:
int day,month,year;//Date
bool schedule[9];//Hours 9am-6pm
public:
Day(int,int,int);//Constructor
~Day();//Destructor
void setTime(int);
bool checkTime(int);
void display();
};
Day:ay(int d,int m,int y){//Pass date to constructor
day=d;month=m;year=y;//Set the date
for(int i=0;i<9;++i)schedule=false;//Initialise all the hours in the day to “free”
}
Day::~Day(){}
bool Day::checkTime(int t){
if(t>5&&t<9)return 0;//Invalid time
else t+=(t>=9?-9:3);
if(!schedule[t]){//Check if booked
schedule[t]=true;//Now booked
return 1;//Success!
}
else return 0;//Not available...
}
void Day::display(){
std::cout<<day<<'/'<<month<<'/'<<year<<std::endl;//Display day
for(int i=0;i<9;++i)std::cout<<(i<4?i+9:i-3)<<(i<3?"am":"pm")<<'\t'<<(schedule?"Booked":"Available")<<std::endl;
}
int main(){
int d,m,y,t;
std::cout<<"Input the date:\n";
std::cin>>d>>m>>y;
Day MyDay(d,m,y);//Create a day
do{
std::cout<<"Input appointment time:\n";
std::cin>>t;
}while(!MyDay.checkTime(t));//Do until you find a free time
MyDay.display();
return 0;
}