Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can anyone help please

Status
Not open for further replies.

tiitii

IS-IT--Management
Jul 6, 2005
2
GB

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::Day(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;
}
 
That sounds a lot like you asking us to make your homework assignment. Ask a specific question, show that you tried and got stuck, or this tread is likely to be reported and deleted, as it is against the forums policies.

Vincent
 
1. Please use [code][/code] tags when posting code.

2.
Code:
std::cout<<(i<4?i+9:i-3)<<(i<3?"am":"pm")
    <<'\t'<<(schedule[i]?"Booked":"Available")<<std::endl;
Try rephrasing this using multiple statements.
It might do what you want (then again, it might not), but the chances of being able to debug it / explain it / change it if it doesn't do what you want are slim.

In particular, try and do something not involving lots of (ab)use of the ?: operator.

The compiler doesn't care whether you cram everything onto one line, and use as few characters as possible, but all your human readers just find such coding hard to read.

--
 
When I see a post with a large block of code with absolutely no whitespace, I don't even bother reading any further.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top