reservation system

This is a discussion on reservation system within the C++ Programming forums, part of the General Programming Boards category; this system we need to key in bus records...before doin reservation... now...how to modify this program to set buses already ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    8

    reservation system

    this system we need to key in bus records...before doin reservation...
    now...how to modify this program to set buses already available...n user can book the ticket directly...

    Code:
    #include <conio.h>
    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    #include <dos.h>
    
    using namespace std;
    
    static int p=0;
    class a
    {
    		char busn[5],driver[10],arrival[5],depart[5],from[10],to[10],
    		seat[8][4][10];
    	public:
    		void install();
    		void allotment();
    		void empty();
    		void show();
    		void avail();
    		void position(int i);
    }bus[10];//here we declare the number of buses we can have.
    void vline(char ch)
    {
    	for (int i=80;i>0;i--)//Here i's value will depend on your computer.
    		cout<<ch;
    }
    void a::install()
    {
    	cout<<"Enter bus no: ";
    	cin>>bus[p].busn;
    	cout<<"\n Enter Driver's name: ";
    	cin>>bus[p].driver;
    	cout<<"\n Arrival time: ";
    	cin>>bus[p].arrival;
    	cout<<"\n Departure: ";
    	cin>>bus[p].depart;
    	cout<<"\n From: \t\t\t";
    	cin>>bus[p].from;
    	cout<<"\n To: \t\t\t";
    	cin>>bus[p].to;
    	bus[p].empty();
    	p++;
    }
    void a::allotment()
    {
    	int seat;
    	char number[5];
    	top:
    	cout<<"Bus no: ";
    	cin>>number;
    	int n;
    	for(n=0;n<=p;n++)
    	{
    		if(strcmp(bus[n].busn,number)==0)
    		break;
    	}
    	while(n<=p)
    	{
    		cout<<"\n Seat number: ";
    		cin>>seat;
    		if (seat>32)
    			{
    				cout<<"\n There are only 32 seats available in this bus.";
    			}
    		else
    			{
    			if (strcmp(bus[n].seat[seat/4][(seat%4)-1],"Empty")==0)
    				{
    					cout<<"Enter passanger's name: ";
    					cin>>bus[n].seat[seat/4][(seat%4)-1];
    					break;
    				}
    			else
    				cout<<"The seat no. is already reserved.\n";
    			}
    	}
    	if (n>p)
    	{
    		cout<<"Enter correct bus no.\n";
    		goto top;
    	}
    }
    void a::empty()
    {
    	for(int i=0;i<8;i++)
    	{
    		for(int j=0;j<4;j++)
    		{
    			strcpy(bus[p].seat[i][j],"Empty");
    		}
    	}
    }
    void a::show()
    {
    	int n;
    	char number[5];
    	cout<<"Enter bus no: ";
    	cin>>number;
    	for(n=0;n<=p;n++)
    	{
    		if(strcmp(bus[n].busn,number)==0)
    			break;
    	}
    	while (n<=p)
    	{
    		vline('*');
    		cout<<" Bus no: \t"<<bus[n].busn
    		<<"\n Driver: \t"<<bus[n].driver<<"\t\t Arrival time:\t"
    		<<bus[n].arrival<<"\t Departure time:\t"<<bus[n].depart
    		<<"\n From:\t\t"<<bus[n].from<<"\t\t To: \t\t\t"<<
    		bus[n].to<<"\n";
    		vline('*');
    		bus[0].position(n);
    		int a=1;
    		for (int i=0;i<8;i++)
    		{
    			for(int j=0;j<4;j++)
    			{
    				a++;
    				if(strcmp(bus[n].seat[i][j],"Empty")!=0)
    					cout<<"\n The seat no "<<a-1<<" is reserved for "<<bus[n].seat[i][j]<<" .";
    			}
    		}break;
    	}	if(n>p)
    			cout<<"enter correct bus no.";
    }
    void a::position(int l)
    {
    	int s=0,p=0;
    	for(int i=0;i<8;i++)
    	{
    		cout<<"\n";
    		for(int j=0;j<4;j++)
    		{
    			s++;
    			if(strcmp(bus[l].seat[i][j],"Empty")==0)
    				{
    					cout.width(5);
    					cout.fill(' ');
    					cout<<s<<".";
    					cout.width(10);
    					cout.fill(' ');
    					cout<<bus[l].seat[i][j];
    					p++;
    				}
    			else
    				{
    					cout.width(5);
    					cout.fill(' ');
    					cout<<s<<".";
    					cout.width(10);
    					cout.fill(' ');
    					cout<<bus[l].seat[i][j];
    				}
    		}
    	}
    		cout<<"\n\n There are "<<p<<" seats empty in Bus No: "<<bus[l].busn;
    }
    void a::avail()
    {
    	for(int n=0;n<p;n++)
    	{
    		vline('*');
    		cout<<"Bus no: \t"<<bus[n].busn<<"\nDriver: \t"<<bus[n].driver<<"\t\tArrival time:\t"<<bus[n].arrival<<"\tDeparture Time: \t"<<bus[n].depart<<"\n From: \t\t"<<bus[n].from<<"\t\t To: \t\t\t"<<bus[n].to<<"\n";
    		vline('*');
    		vline('_');
    	}
    }
    int main()
    {
    	int w;
    
    	while(1)
    	{
    		cout<<"\n\n\n\n";
    		cout<<"\t\t\t 1.Install\n\t\t\t 2.Reservation\n\t\t\t 3.Show \n\t\t\t 4.Buses Available. \n\t\t\t 5.Exit";
    		cout<<"\n\t\t\t Enter your choice:-> ";
    		cin>>w;
    		switch(w)
    		{
    			case 1:
    			bus[p].install();
    			break;
    			case 2:
    			bus[p].allotment();
    			break;
    			case 3:
    			bus[0].show();
    			break;
    			case 4:
    			bus[0].avail();
    			break;
    			case 5:
    			exit(0);
    		}
    	}
    }

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    A few comments about this code...
    1) bad things happen when you use the dreaded word 'goto' . The block of code where you've used goto could be easily changed to use a do..while loop instead.

    2) avoid using global variables - bus and p don't really need to be global

    3) Use C++ strings instead of char[] - the C++ string header is <string>

    4)
    Code:
    for (int i=80;i>0;i--)//Here i's value will depend on your computer.
    i will be exactly the same regardless of your computer - what makes you think otherwise?

    5)
    Code:
    int seat;
    You already have a member variable of class 'a' called seat - reusing the name inside a member function is bad style.

    6)Some of your class member functions don't actually do anything to the objects which they are called - instead they manipulate global variables - you really need to rethink the design of your code.



    There could be other problems too, but that's what stuck out to me so far

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    8
    ohh...thanks for ur comment....
    i will alter to be better......

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 12:04 PM
  2. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 06:56 PM
  3. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  4. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 04:35 PM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 06:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21