Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-17-2006, 05:51 PM   #1 (permalink)
pete0
Registered User
 
Join Date: Mar 2006
Posts: 1
pete0 is on a distinguished road
i need a big heeeeeeeeeeeeeelp anyone please

hi everyone as much involvement i get with C++ i alway get to a point where my fingers are tied, and here i am.

This piece of code displays a date then the time selected by the user, where i got stuck are:
1. i am trying to validate (check) the date enter so that it conforms to something like this 18 03 2006.
2. i am trying to make it to allow a user to request the first free hour of the day.




Code:
#include "stdafx.h"

#using <mscorlib.dll>
using namespace std;


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 checkDate(int,int,int);
       //==========================
       void firstAvailableHour();// Get the first avalaiable hour in the appointment book
       void display();

       bool IfAnyTimeAvailable() 
{
		 for(int i=0;i<9;++i) {
		    if(!schedule[i]) {
		       return true ;//time is available for booking
			   }
		   }
		   return false ;//no time is available for booking
	   }
};

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[i]=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::checkDate(int d,int m,int y);
	
	if (d <= 31 && d >= 1 && m <= 12 && m >= 1 && y <=2006)
{  
	  clrscr();
	  cout<<" Date is kindly Accepted";
	 // day = d;
	  //month = m;
	  //year = y;
	  cout<< "wait   \n";
	  Sleep(2000); // go to bed for 2secs.
}
	else
{
	  cout<<"date is invalid, enter a valid date"
	  
}

//void Day::void firstAvailableHour(int t) // booking the first available hour in the day
//{
       // clrscr();
           for (int i=0;i<9;i++)
           {  if (schedule[i] == true)
               {  strcpy(schedule[i], "Booked");
                   cout << " sorry already booked " <<(i+9) <<" :00\n";
                   i=10; //supposed toend the loop
                   Sleep(2000);
                }
                      else // if there is no booking
                      {
                           if (1==8)// no more time to book
                           { cout<<"sorry no more time to book";
                              Sleep(2000); // go to bed for 2 secs
                           }
                      }
            }
             else //if no date is choosen
          {
           cout << "please enter date b4 boking";
            Sleep(2000);
          }              

 }

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[i]?"Booked":"Available")
	   <<std::endl;
}
int main(void)
{
   int d,m,y,t;
   std::cout<<"    =============Menu===========>   \n";
   std::cout<<"    1. Input time  Appointment time between 9-5\n";
   std::cout<<"    2. Enter 8 to display the avalaible time \n \n";
   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;
	   if(!MyDay.checkTime(t)) {
		   MyDay.display();
	   }
	   if(!MyDay.IfAnyTimeAvailable()){
		   break ;
	   }
	 }
	while(1);
	cout<<"********All Bookings************"<<endl ;
	MyDay.display();

	while(0);
	cout<<"********All Bookings************"<<endl ;
	MyDay.display();
return 0;
}
pete0 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
big command line programs... smckittr Program Design and Methods 3 08-25-2005 09:52 PM
Big O notation saiz66 Standard C, C++ 1 06-22-2004 09:19 AM
Longhorn 'Big Bet' For Company redhead Code Newbie News 1 07-24-2003 04:11 PM
the big 5-0-0 saline Lounge 7 03-27-2003 07:50 PM
The Big 300! Ilya020 Lounge 7 03-02-2003 09:41 AM


All times are GMT -8. The time now is 06:40 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting