reservation system

Tracing an error in the reservation program

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

39 Replies - 3040 Views - Last Post: 12 April 2010 - 08:02 AM Rate Topic: -----

#1 wmugume2000  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 130
  • Joined: 18-March 10

reservation system

Posted 09 April 2010 - 09:45 PM

The program is return an error:
504 function-definition is not allowed here before '{' token

#include<iostream>
#include<fstream>
#include<string>
#include <iomanip> 

//#include "cruise.h"
//#include "ticket.h"
//#include "booking.h"
//#include "ticketControl.h"
//#include "summary.h"

using namespace std; 

const int ROWS = 13;  
const int COLS = 4;  
const int LEVELS = 3;  

class Cruise  
{  
private:  
        char cabins[LEVELS][ROWS][COLS];  
        bool validate(char);       
 
public:         
        Cruise(){ReadInformation();}// constructor
        //~Cruise();
        
        void ReadInformation();
        void displayCabinsConfig(); 
        void writeInformation();
        void reserveCabin();
        void displaySummmary();
        bool checkAvailability(int r,int n, int m);
        char getCabinType(int, int, int); 
        double getTicketPrice(int, int, int, double);
	    void cabinSold(int i, int j, int k) 
        {cabins[i][j][k] = 'X';}
}; 

//definition of the functions.  
//-----------------------------------------------------------------------------------------------------  
 
void Cruise :: ReadInformation() 
{
 std::cout << "Begin reading file.\n";  
      
   ifstream fin;
   char c;
   
   fin.open("cabinConfig.txt");
   if (fin.fail( ))
    {
        cout << "Input file opening failed.\n";
        exit(1);// executed if the file fails to open
    }
        fin.get(c); 
        while (!fin.eof())
      
  for(int level=0; level<LEVELS; level++)   
        {   
                for(int row=0; row<ROWS; row++)   
                {   
                        for(int col=0; col<COLS; col++)   
                        {   
                                if (col==0||col==3)   
                                {   
                                        cabins[level][row][col] = (row<5) ? 'B' : 'W';   
                                } else   
                                {   
                                        cabins[level][row][col] = 'I';   
                                } 
                                while (fin.get(c)) 
                                { 
                                        if (validate(c)) 
                                        { 
                                                cabins[level][row][col] = c; 
                                                break; 
                                        } 
                                }   
                        }   
                }   
        }   
 
 fin.close();  
 //std::cout << "File successfully read!\n" << endl;   
} 
//-------------------------------------------------------------------------------------------------------------  
void Cruise:: displayCabinsConfig() 
{
     cout << endl;
cout << " LITTLE SWAN CABIN CONFIGURATION \n\n\n";  
  
   ifstream fin;
   char c;
   fin.open("cabinConfig.txt");
   
   if (fin.fail( ))
        {
            cout << "Input file opening failed.\n";
            exit(1);
        }
    
    fin.get(c); 
    while (!fin.eof())
    {     
          for(int level=0; level<LEVELS; level++)   
            {   
                    cout<<endl;
                    cout << "------------- LEVEL " << (level + 1) << " ------------" << endl;
                    cout<<endl;
                    cout << "    ";   
                    //cout << '+';    
                    for(int col=0; col<COLS; col++) { cout << '\t' << (col+1); }    
                    cout << endl;   
     
                    for(int row=0; row<ROWS; row++)   
                    {   
                            cout << (row + 1);   
                            for(int col=0; col<COLS; col++)  
                            {   
                                    cabins[level][row][col]=c;
                                    cout << '\t' << cabins[level][row][col]; 
                                    fin.get(c);  
                            }   
                            fin.get(c);
                            cout << endl;   
                    }   
                    cout << endl;   
     
            }
      
     }
     fin.close(); 
} 
//----------------------------------------------------------------------------------------------------------------  
void Cruise::writeInformation()
{     
ofstream fin;
fin.open("cabinConfig.txt", ios::trunc);// open file, and replace text with new text
if (fin.fail())
   {
        cout << "Cannot write to file.\n";   
   }
    for(int level=0; level<LEVELS; level++) 
    {
        for(int row=0; row<ROWS; row++)  
        {      
             for(int col=0; col<COLS; col++) 
            {
              fin << cabins[level][row][col];
            }
            fin << endl;
        }      
    }
    
  fin.close();        
}
//------------------------------------------------------------------------------------------------------------------ 
bool Cruise :: validate(char c)   
{  
        if (c=='B' || c == 'I' || c == 'W' || c == 'X')  //Ensure the expected characters are what exist in file
                return true;  
        else   
                return false;  
}  
//--------------------------------------------------------------------------------------------------------------------
void Cruise::reserveCabin()
{
        int i1;
        int j1;
        int k1;
        char resv;
        int bookingId ;
        srand((unsigned)time(0)); 
              int random_integer;     
              int lowest=1, highest=10;    
              int range=(highest-lowest)+1;     
                 
      do
      {  
            cout << endl;
            cout <<" Welcome to the Cruise Reservation "  <<endl;
            cout <<" "  <<endl;
            while(true) 
            { 
                  cout <<"Enter Level 1 - 3 : ";
                  cin >> i1; 
                  cout << endl;
                  cout <<"Enter Row:1-13 : "; 
                  cin>> j1; 
                  cout << endl;
                  cout<<"Enter Column: 1-4 : "; 
                  cin >> k1; 
            if((i1>=0 && i1<=3)&&(j1>=1&&j1<=13)&&(k1>=1&&k1<=4)) 
                  break; 
            else 
                        cerr<<"************ INPUT NOT VALID ***********"<<endl; 
                         
            }
            cout << " ==========================================================\n";
               i1 = i1 - 1; //after array use
               j1 = j1 - 1; //after array use
               k1 = k1 - 1; //after array use
            
        if ((cabins [i1][j1][k1] == 'B') || (cabins [i1][j1][k1] =='I') || (cabins [i1][j1][k1] =='W'))
            {
                cabins[i1][j1][k1] = 'X';
            }
        else if (cabins [i1][j1][k1] == 'X')
            {
                cout << "Sorry!! The Cabin is already booked \n" << endl;
                break;
            }
          writeInformation();
               
          for(int index=0; index < 10; index++)// used to generate a booking Id at random
          {random_integer = (rand()%10);} 
          
          cout<<endl;
          cout << "Thank you for the time, A cabin on \n\n";
          cout << " Level  : " << (i1 + 1) << "\n Row    : " << (j1 + 1) << "\n Column: "<< (k1 + 1) << "\n Has been reserved for you!\n\n";
          cout << " Your booking ID is: " << random_integer << cout << endl;
          cout << " ==========================================================\n\n";
          cout << " Would you like to book another cabin? Y/N" << endl;
          cin >> resv;
          if (resv == 'N' || resv == 'n'){system("pause");}
    }
    while ((resv == 'Y') || (resv == 'y'));
}
//---------------------------------------------------------------------------------------------------------------------
char Cruise:: getCabinType(int, int, int)
{
     int r,n,m;
if(r>=0 && r<LEVELS && n >= 0 && n < ROWS && m >= 0 && m < COLS) {
		return cabins[r][n][m];
	} else {
		return 'O';
	}
}
//-----------------------------------------------------------------------------------------------------------
double Cruise::getTicketPrice(int r, int n, int m, double basePrice) {
	if(r>=0 && r<LEVELS && n >= 0 && n < ROWS && m >= 0 && m < COLS) {
		double price;
		switch (cabins[r][n][m]) {
			case 'A':
				price = basePrice;break;
			case 'B':
				price = basePrice *1.6;break;
			case 'C':
				price = basePrice *2.0;break;
			case 'D':
				price = basePrice *0.6;break;
			case 'E':
				price = basePrice *0.5;break;
			case 'F':
				price = basePrice *0.4;break;
			default:
				break;
		}		
		return price;
	} else {
		return -1;
	}
}
//----------------------------------------------------------------------------------------------
bool Cruise::checkAvailability(int r,int n, int m) {
	if(r>=0 && r<LEVELS && n >= 0 && n < ROWS && m >= 0 && m < COLS && cabins[r][n][m] !='X') {
		return true;
	} else {
		return false;
	}
}
//=============================================================================================
void Cruise:: displaySummmary()
{
         int lev, row, col;
         int t1 = 0, t2 = 0, t3 = 0;
               
       ifstream fin; 
       int letterCount[26]={0}; 
       string fileName; 
       char next; 
       int a= 0;
       int b =0, b1=0,b2=0,b3=0;
       int i =0, i1=0,i2=0,i3=0;
       int w =0, w1=0,w2=0,w3=0;  
   
       //fin.get word; 
 
       fin.open("cabinConfig.txt"); 
       if (fin.fail( )) 
       { 
           cout << "Sorry cannot read file \n"; 
           exit(1); 
       } 
       while (!fin.eof())  
             {          
                // Get a character from the file 
               fin.get(next);   
               // Check if this character equals with 'X'.  
               if  (next == 'X') 
               a++; // If it does, increase the counter; 
               else if (next == 'B') 
               b++;
               else if (next == 'I')
               i++;
               else if (next == 'W')
               w++;
               }    
 
      
     // level 1 Summary for
     for (int lev = 0; lev < 1; lev++)
     {
        for(int row = 0; row < 13; row++)
        {      
            for (int col = 0; col < 4; col++)
            //while (true)
            {
            if (cabins[lev][row][col] == 'X')
                {
                   t1 = t1 + 1;
                }
            else if (cabins[lev][row][col] == 'B') 
                {
                   b1 = b1 + 1;
                }
            else if (cabins[lev][row][col] == 'I')
               {
                   i1 = i1 + 1;
                }
            else if (cabins[lev][row][col] == 'W')
                {
                   w1 = w1 + 1;
                }
            }
        }
        
     }
     
     
     // level 2 Summary
     for (int lev = 1; lev < 2; lev++)
     {
        for(int row = 0; row < 13; row++)
        {      
            for (int col = 0; col < 4; col++)
            
            if (cabins[lev][row][col] == 'X')
                {
                   t2 = t2 + 1;
                }
            else if (cabins[lev][row][col] == 'B') 
                {
                   b2 = b2 + 1;
                }
            else if (cabins[lev][row][col] == 'I')
               {
                   i2 = i2 + 1;
                }
            else if (cabins[lev][row][col] == 'W')
                {
                   w2 = w2 + 1;
                }
        }
     }
     
     // level 3 Summary
     for (int lev = 2; lev < 3; lev++)
     {
        for(int row = 0; row < 13; row++)
        {      
            for (int col = 0; col < 4; col++)
            
            if (cabins[lev][row][col] == 'X')
                {
                   t3 = t3 +1;
                }
            else if (cabins[lev][row][col] == 'B') 
                {
                   b3 = b3 + 1;
                }
            else if (cabins[lev][row][col] == 'I')
               {
                   i3 = i3 + 1;
                }
            else if (cabins[lev][row][col] == 'W')
                {
                   w3 = w3 + 1;
                }
        }
     }

      // Print how many 'X' are in the file. Should print 2 
      
       cout << "----------------------------------------------------------------\n";
       cout << "Total number of reverved cabins per Level :\n"; 
       cout << "----------------------------------------------------------------\n\n";
       cout <<"LEVEL 1\n\n";
       cout << "The number of reserved cabins on level 1 : " << t1 << endl;
       cout << "The number of cabins on Balcony available: "<< b1 << endl ;
       cout << "The number of cabins on windows available: "<< w1 << endl ;
       cout << "The number of cabins on Inside available: "<< i1 << endl ;
       cout << "----------------------------------------------------------------\n\n";
        cout <<"LEVEL 2\n\n";
       cout << "The number of reserved cabins on level 2 : " << t2 << endl;
       cout << "The number of cabins on Balcony available: "<< b2 << endl ;
       cout << "The number of cabins on windows available: "<< w2 << endl ;
       cout << "The number of cabins on Inside available: "<< i2 << endl ;
       cout << "----------------------------------------------------------------\n\n";
        cout <<"LEVEL 3\n\n";
       cout << "The number of reserved cabins on level 3 : " << t3 << endl;
       cout << "The number of cabins on Balcony available: "<< b3 << endl ;
       cout << "The number of cabins on windows available: "<< w3 << endl ;
       cout << "The number of cabins on Inside available: "<< i3 << endl ;
        cout << "---------------------------------------------------------------\n\n";
       cout << " Little Swan reservation General Summary. \n\n";
       cout << "----------------------------------------------------------------\n";
       cout << "The Total number of reserved cabins are       : "<< a << endl; 
       cout << "The number of available cabins on Balcony are : "<< b << endl; 
       cout << "The number of available cabins on Windows are : "<< w << endl; 
       cout << "The number of available cabins Inside are     : "<< i << endl;
       cout << endl;
       cout << "Press Enter to procced-----\n";
        
     cin.ignore(); 
     cin.get(); 
       //fin.close();
}
//============================================TRIP CLASS ===========================================
class Trip {
public:
	int tripId;
	string city;
	double basePrice;
	int travelDate;
};
//========================================TICKET ====================================================
class Ticket {
private:
	int tripId;
	int cabinLevel;
	int cabinRow;
	int cabinCol;
	char cabinType;
	double price;
	int date;
public:
	Ticket();
    Ticket(int, int, int, int, char, double, int); 
	void printTicket(string);
};

Ticket::Ticket() { // constructor to set default for the ticket
	tripId = -1;
	cabinLevel = -1;
	cabinRow = -1;
	cabinCol = -1;
	cabinType = 'O';
	price = 0.0;
	date = 0;
}

Ticket::Ticket(int id, int r, int n, int m, char c, double p, int d){
	tripId = id;
	cabinLevel = r;
	cabinRow = n;
	cabinCol = m;
	cabinType = c;
	price = p;
	date = d;
}

void Ticket::printTicket(string location) {
	cout << "Trip Location : " <<  location << endl;
	cout << "Cabin : " << "Level " << (cabinLevel+1) 
         << ",Column " << (cabinCol+1) 
         << ",row " << (cabinRow+1)<< endl;
	cout << "Cabin Type: " << cabinType << endl;
	cout << "Price: $" << price << endl;
	cout << "Date: " << date << endl << endl;
//========================================TICKET CONTROL=================================================
class TicketControl {
      
private:
	TicketSell *sales[500];
    Trip locations[6]; 
	bool isFull(int, int, int);
	bool daysAvaliable(int);
	int salesTot;
	int tripTot;
public:
	TicketControl() {
		salesTot = 0;
		tripTot = 0;
	}
    void addTrip(Trip);
	bool checkTrip(int, int);
	void ticketSell(int, int, int, int);
	void displayAvailability(int);
};

void TicketControl::ticketSell(int date, int lev, int row, int col) {
	for (int i=0;i<salesTot;i++) {
		if(sales[i]->getTripDate() == date) {
			if (sales[i]->sell(lev,row,col)) {
				cout << "You can come and pick your ticket.\n" << endl;
			} else {
				cout << "Sorry that ticket is not available.\n" << endl;
			}
		}
	}
	return;
}

bool TicketControl::daysAvaliable(int depart) {
	bool flag = true;
	for (int k=0;k<tripTot;k++) {
		if(trip[k].depart > depart) ) {
			flag = false;
			break;
		}
	}
	return flag;
}

bool TicketControl::isFull(int m, int n){
	if (type == 0) {
		if (tripTot + n >= 6) {
			cout <<" Trips are booked out " << endl;
			return true;
		} else {
			return false;
		}
	} else {
		if (salesTot + n >= 500) {
			cout <<" Tickets are sold out" << endl;
			return true;
		} else {
			return false;
		}
	}
}

void TicketControl::addTrip(Trip t) {

	if( !daysAvaliable(t.departDate)  {
		cout << "Sorry those dates are not available" << endl;
		return;
	}

	if (isFull(0,1) || isFull(1, t.departDate +1)) return;
    
	trip[tripTot++] = t;
    
	for (;int d= t.departDate;d++) {
		TicketSell *sale = new TicketSell;
		sale->setTrip(t);
		sale->setDate(d);
		Cruise c;
		sale->setCruise(c);
		cout << endl;
		cout << salesTot;
		cout << endl;
		cout << " Trip " + t.location + " on date ";
		sales[salesTot++] = sale;
		cout << sales[salesTot-1]->getTripDate();
		cout << " is generated." << endl; 
	}
}

void TicketControl::displayAvailability(int date) {
	for (int i=0;i<salesTot;i++) {
		if(sales[i]->getTripDate() == date ) {
		   sales[i]->displayCabins();
		   break;
		}	
	}
	return;
}	
//---------------------------------------------Customer class -----------------------------------------------
class customer:public Ticket
{
    public:
    void addCustomer();
    void dispCustomer();
    
    private:
    char name[];
    int payment;
};
//==========================================SELL TICKET==============================================
class TicketSell { 
private: 
        Trip location; 
        int date; 
        Cruise record;  
public: 
        void setTrip(Trip t ) {location = t;} 
        void setCruise(Cruise c) {record = c;} 
        void setDate(int d) {date = d;} 
        void displayCabins(); 
        int getTripID() { 
                return location.tripId; 
        } 
   int getTripDate() { 
                return date; 
        } 
 
        bool sell(int r, int n, int m);  
}; 
 
bool TicketSell::sell(int r, int n, int m) 
{ 
                 
        if( !record.checkAvailability(r,n,m))  
                return false; 
     
        string tdestination = location.city; 
         
        Ticket ticket(location.tripId,r,n,m,record.getcabinType(r,n,m),record.getTicketPrice(r,n,m, location.basePrice),date); 
        ticket.printTicket(tdestination); 
     
        record.cabinSold(int i, int j, int k); 
        return true; 
} 
 

void TicketSell::displayCabins() { 
        cout << "Location ID:" << location.tripId << "  "; 
        cout << "Date: " << date << endl; 
 
        for(int j=0; j<LEVELS; j++)    
        {    
                for(int k=0; k<ROWS; k++)    
                {    
                   for(int l=0; l<COLS; l++) 
                        { 
                         cout << record.getCabinsType(j,k,l); 
                        } 
                        cout << endl; 
                }  
                        cout << endl;   
        } 
 } 
 //======================================================================================================
int main()
{
    Cruise w; //declaring an object

  
  cout <<     "\t\t\tWELCOME TO HoliCrusing Company.\n\n\
            This Program will guide you to reserve cabins on  \n \n\n ";
  cout <<     "\t\t\tLITTLE SWAN CRUISE SHIP.\n\n" ;
                        
  cout << " ==================================================================== \n\n";
    cout << " \t=======================================================\n\n";
	  cout << "\t\t ========================================== \n\n";
   
   int ans = 0;
   char ch;
   do 
      {
           cout <<"Please select an action to perform below and press Enter \n\n";
           cout <<" [1] View Cabin configuration \n\n [2] Book Cabins\n\n"; 
           cout <<" [3] View summary of Reserved cabins\n\n" ;// (4)Display available Cabins  \n\n\t
           
           cout <<"\t"; cin >> ans;
 
           switch(ans)
           {
                case 1 :
                     cout << endl ;
                     cout << " \t Please Note: \n";
					 cout << " B -- Cabin with Balcony, W -- Cabin with window \n";
					 cout << " I -- Inside cabin,       X -- Cabin reserved \n\n" ;
					 cout <<"==================================================== \n";
                     w.displayCabinsConfig();
                     break;
           
                case 2 :
                     cout << endl;    
                     w.reserveCabin();
                     break;
                     
                case 3 :
                     cout <<"==================================================== \n";
                     w.displaySummmary();
                     break;
                     
                default:
                        cout << "illegal value! Program aborted.\n";
                        system ("pause");
                        exit(1);
            }            
                cout << "Anything more you would wish to do ?(y/n) ";
                   cin >> ch;
				   //cin.get(ch);
				   if (ch == 'N' || ch =='n')
				   {
					   cout << "\n";
					   cout << "\t\t\t\t Thank you ! Bye  Bye! \n\n\n";
				   }
                cout << "\n";
                 
        }while (ch == 'Y' || ch == 'y');   
   system ("pause");
    return 0;
 }





Is This A Good Question/Topic? 0
  • +

Replies To: reservation system

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1634
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: reservation system

Posted 09 April 2010 - 10:18 PM

Moved to C/C++
Was This Post Helpful? 0
  • +
  • -

#3 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: reservation system

Posted 09 April 2010 - 11:13 PM

You're missing a bracket:

	cout << "Date: " << date << endl << endl;
}  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//========================================TICKET CONTROL=================================================
class TicketControl {


Was This Post Helpful? 0
  • +
  • -

#4 wmugume2000  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 130
  • Joined: 18-March 10

Re: reservation system

Posted 09 April 2010 - 11:34 PM

Thank!

ERROR: `;' before '*' token

Does something seem to be wrong with the Ticketll *sells[500].Was trying to allocate 500 tickets to the Ticket sell class. so that the total ticket for sale becomes 500. is it ok?

class TicketControl {
      
private:
	TicketSell *sales[500];
    Trip locations[6]; 
	bool isFull(int, int, int);
	bool daysAvaliable(int);
	int salesTot;
	int tripTot;
public:
	    TicketControl() {
		salesTot = 0;
		tripTot = 0;
	}
    void addTrip(Trip);
	bool checkTrip(int, int);
	void ticketSell(int, int, int, int);
	void displayAvailability(int);
};


Was This Post Helpful? 0
  • +
  • -

#5 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 965
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: reservation system

Posted 09 April 2010 - 11:39 PM

TicketSell is defined UNDER TicketControl class, so it is an undeclared identifier. I have explained it in another topic of yours.
Was This Post Helpful? 0
  • +
  • -

#6 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: reservation system

Posted 09 April 2010 - 11:43 PM

The way your file is laid out you are defining class TicketSell after class TicketControl
Was This Post Helpful? 0
  • +
  • -

#7 wmugume2000  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 130
  • Joined: 18-March 10

Re: reservation system

Posted 10 April 2010 - 12:24 AM

I improved the code to remove error that were due to the merging of files.

ERROR: 574 F prototype for `bool TicketControl::isFull(int, int)' does not match any in class `TicketControl'


I put a match

#include<iostream>
#include<fstream>
#include<string>
#include <iomanip> 

//#include "cruise.h"
//#include "ticket.h"
//#include "booking.h"
//#include "ticketControl.h"
//#include "summary.h"

using namespace std; 

const int ROWS = 13;  
const int COLS = 4;  
const int LEVELS = 3;  

class Cruise  
{  
private:  
        char cabins[LEVELS][ROWS][COLS];  
        bool validate(char);       
 
public:         
        Cruise(){ReadInformation();}// constructor
        //~Cruise();
        
        void ReadInformation();
        void displayCabinsConfig(); 
        void writeInformation();
        void reserveCabin();
        void displaySummmary();
        bool checkAvailability(int r,int n, int m);
        char getCabinType(int j, int k, int l); 
        double getTicketPrice(int, int, int, double);
	    void cabinSold(int i, int j, int k) 
        {cabins[i][j][k] = 'X';}
}; 

//definition of the functions.  
//-----------------------------------------------------------------------------------------------------  
 
void Cruise :: ReadInformation() 
{
 std::cout << "Begin reading file.\n";  
      
   ifstream fin;
   char c;
   
   fin.open("cabinConfig.txt");
   if (fin.fail( ))
    {
        cout << "Input file opening failed.\n";
        exit(1);// executed if the file fails to open
    }
        fin.get(c); 
        while (!fin.eof())
      
  for(int level=0; level<LEVELS; level++)   
        {   
                for(int row=0; row<ROWS; row++)   
                {   
                        for(int col=0; col<COLS; col++)   
                        {   
                                if (col==0||col==3)   
                                {   
                                        cabins[level][row][col] = (row<5) ? 'B' : 'W';   
                                } else   
                                {   
                                        cabins[level][row][col] = 'I';   
                                } 
                                while (fin.get(c)) 
                                { 
                                        if (validate(c)) 
                                        { 
                                                cabins[level][row][col] = c; 
                                                break; 
                                        } 
                                }   
                        }   
                }   
        }   
 
 fin.close();  
 //std::cout << "File successfully read!\n" << endl;   
} 
//-------------------------------------------------------------------------------------------------------------  
void Cruise:: displayCabinsConfig() 
{
     cout << endl;
cout << " LITTLE SWAN CABIN CONFIGURATION \n\n\n";  
  
   ifstream fin;
   char c;
   fin.open("cabinConfig.txt");
   
   if (fin.fail( ))
        {
            cout << "Input file opening failed.\n";
            exit(1);
        }
    
    fin.get(c); 
    while (!fin.eof())
    {     
          for(int level=0; level<LEVELS; level++)   
            {   
                    cout<<endl;
                    cout << "------------- LEVEL " << (level + 1) << " ------------" << endl;
                    cout<<endl;
                    cout << "    ";   
                    //cout << '+';    
                    for(int col=0; col<COLS; col++) { cout << '\t' << (col+1); }    
                    cout << endl;   
     
                    for(int row=0; row<ROWS; row++)   
                    {   
                            cout << (row + 1);   
                            for(int col=0; col<COLS; col++)  
                            {   
                                    cabins[level][row][col]=c;
                                    cout << '\t' << cabins[level][row][col]; 
                                    fin.get(c);  
                            }   
                            fin.get(c);
                            cout << endl;   
                    }   
                    cout << endl;   
     
            }
      
     }
     fin.close(); 
} 
//----------------------------------------------------------------------------------------------------------------  
void Cruise::writeInformation()
{     
ofstream fin;
fin.open("cabinConfig.txt", ios::trunc);// open file, and replace text with new text
if (fin.fail())
   {
        cout << "Cannot write to file.\n";   
   }
    for(int level=0; level<LEVELS; level++) 
    {
        for(int row=0; row<ROWS; row++)  
        {      
             for(int col=0; col<COLS; col++) 
            {
              fin << cabins[level][row][col];
            }
            fin << endl;
        }      
    }
    
  fin.close();        
}
//------------------------------------------------------------------------------------------------------------------ 
bool Cruise :: validate(char c)   
{  
        if (c=='B' || c == 'I' || c == 'W' || c == 'X')  //Ensure the expected characters are what exist in file
                return true;  
        else   
                return false;  
}  
//--------------------------------------------------------------------------------------------------------------------
void Cruise::reserveCabin()
{
        int i1;
        int j1;
        int k1;
        char resv;
        int bookingId ;
        srand((unsigned)time(0)); 
              int random_integer;     
              int lowest=1, highest=10;    
              int range=(highest-lowest)+1;     
                 
      do
      {  
            cout << endl;
            cout <<" Welcome to the Cruise Reservation "  <<endl;
            cout <<" "  <<endl;
            while(true) 
            { 
                  cout <<"Enter Level 1 - 3 : ";
                  cin >> i1; 
                  cout << endl;
                  cout <<"Enter Row:1-13 : "; 
                  cin>> j1; 
                  cout << endl;
                  cout<<"Enter Column: 1-4 : "; 
                  cin >> k1; 
            if((i1>=0 && i1<=3)&&(j1>=1&&j1<=13)&&(k1>=1&&k1<=4)) 
                  break; 
            else 
                        cerr<<"************ INPUT NOT VALID ***********"<<endl; 
                         
            }
            cout << " ==========================================================\n";
               i1 = i1 - 1; //after array use
               j1 = j1 - 1; //after array use
               k1 = k1 - 1; //after array use
            
        if ((cabins [i1][j1][k1] == 'B') || (cabins [i1][j1][k1] =='I') || (cabins [i1][j1][k1] =='W'))
            {
                cabins[i1][j1][k1] = 'X';
            }
        else if (cabins [i1][j1][k1] == 'X')
            {
                cout << "Sorry!! The Cabin is already booked \n" << endl;
                break;
            }
          writeInformation();
               
          for(int index=0; index < 10; index++)// used to generate a booking Id at random
          {random_integer = (rand()%10);} 
          
          cout<<endl;
          cout << "Thank you for the time, A cabin on \n\n";
          cout << " Level  : " << (i1 + 1) << "\n Row    : " << (j1 + 1) << "\n Column: "<< (k1 + 1) << "\n Has been reserved for you!\n\n";
          cout << " Your booking ID is: " << random_integer << cout << endl;
          cout << " ==========================================================\n\n";
          cout << " Would you like to book another cabin? Y/N" << endl;
          cin >> resv;
          if (resv == 'N' || resv == 'n'){system("pause");}
    }
    while ((resv == 'Y') || (resv == 'y'));
}
//---------------------------------------------------------------------------------------------------------------------
char Cruise:: getCabinType(int r, int n, int m)
{
     //int r,n,m;
if(r>=0 && r<LEVELS && n >= 0 && n < ROWS && m >= 0 && m < COLS) {
		return cabins[r][n][m];
	} else {
		return 'O';
	}
}
//-----------------------------------------------------------------------------------------------------------
double Cruise::getTicketPrice(int r, int n, int m, double basePrice) {
	if(r>=0 && r<LEVELS && n >= 0 && n < ROWS && m >= 0 && m < COLS) {
		double price;
		switch (cabins[r][n][m]) {
			case 'A':
				price = basePrice;break;
			case 'B':
				price = basePrice *1.6;break;
			case 'C':
				price = basePrice *2.0;break;
			case 'D':
				price = basePrice *0.6;break;
			case 'E':
				price = basePrice *0.5;break;
			case 'F':
				price = basePrice *0.4;break;
			default:
				break;
		}		
		return price;
	} else {
		return -1;
	}
}
//----------------------------------------------------------------------------------------------
bool Cruise::checkAvailability(int r,int n, int m) {
	if(r>=0 && r<LEVELS && n >= 0 && n < ROWS && m >= 0 && m < COLS && cabins[r][n][m] !='X') {
		return true;
	} else {
		return false;
	}
}
//=============================================================================================
void Cruise:: displaySummmary()
{
         int lev, row, col;
         int t1 = 0, t2 = 0, t3 = 0;
               
       ifstream fin; 
       int letterCount[26]={0}; 
       string fileName; 
       char next; 
       int a= 0;
       int b =0, b1=0,b2=0,b3=0;
       int i =0, i1=0,i2=0,i3=0;
       int w =0, w1=0,w2=0,w3=0;  
   
       //fin.get word; 
 
       fin.open("cabinConfig.txt"); 
       if (fin.fail( )) 
       { 
           cout << "Sorry cannot read file \n"; 
           exit(1); 
       } 
       while (!fin.eof())  
             while (fin.get(next))   
        {           
                switch (next) 
                { 
                case 'X': 
                        a++; // If it does, increase the counter;  
                        break; 
                case 'B': 
                        b++; // If it does, increase the counter;  
                        break; 
                case 'I': 
                        i++; // If it does, increase the counter;  
                        break; 
                case 'W': 
                        w++; // If it does, increase the counter;  
                        break; 
                } 
        }     
 
        for (int lev = 0; lev < 3; lev++) 
        { 
                for(int row = 0; row < 13; row++) 
                {       
                        for (int col = 0; col < 4; col++) 
                        { 
                                // get next char from array 
                                next = cabins[lev][row][col]; 
 
                                switch (lev) 
                                { 
                                case 0: 
                                        switch (next) 
                                        { 
                                        case 'X': 
                                                t1++; // If it does, increase the counter;  
                                                break; 
                                        case 'B': 
                                                b1++; // If it does, increase the counter;  
                                                break; 
                                        case 'I': 
                                                i1++; // If it does, increase the counter;  
                                                break; 
                                        case 'W': 
                                                w1++; // If it does, increase the counter;  
                                                break; 
                                        } 
                                        break; 
 
                                case 1: 
                                        switch (next) 
                                        { 
                                        case 'X': 
                                                t2++; // If it does, increase the counter;  
                                                break; 
                                        case 'B': 
                                                b2++; // If it does, increase the counter;  
                                                break; 
                                        case 'I': 
                                                i2++; // If it does, increase the counter;  
                                                break; 
                                        case 'W': 
                                                w2++; // If it does, increase the counter;  
                                                break; 
                                        } 
                                        break; 
 
                                case 2: 
                                        switch (next) 
                                        { 
                                        case 'X': 
                                                t3++; // If it does, increase the counter;  
                                                break; 
                                        case 'B': 
                                                b3++; // If it does, increase the counter;  
                                                break; 
                                        case 'I': 
                                                i3++; // If it does, increase the counter;  
                                                break; 
                                        case 'W': 
                                                w3++; // If it does, increase the counter;  
                                                break; 
                                        } 
                                        break; 
                                } 
                        } 
                } 
        } 


      // Print how many 'X' are in the file. Should print 2 
      
       cout << "----------------------------------------------------------------\n";
       cout << "Total number of reverved cabins per Level :\n"; 
       cout << "----------------------------------------------------------------\n\n";
       cout <<"LEVEL 1\n\n";
       cout << "The number of reserved cabins on level 1 : " << t1 << endl;
       cout << "The number of cabins on Balcony available: "<< b1 << endl ;
       cout << "The number of cabins on windows available: "<< w1 << endl ;
       cout << "The number of cabins on Inside available: "<< i1 << endl ;
       cout << "----------------------------------------------------------------\n\n";
        cout <<"LEVEL 2\n\n";
       cout << "The number of reserved cabins on level 2 : " << t2 << endl;
       cout << "The number of cabins on Balcony available: "<< b2 << endl ;
       cout << "The number of cabins on windows available: "<< w2 << endl ;
       cout << "The number of cabins on Inside available: "<< i2 << endl ;
       cout << "----------------------------------------------------------------\n\n";
        cout <<"LEVEL 3\n\n";
       cout << "The number of reserved cabins on level 3 : " << t3 << endl;
       cout << "The number of cabins on Balcony available: "<< b3 << endl ;
       cout << "The number of cabins on windows available: "<< w3 << endl ;
       cout << "The number of cabins on Inside available: "<< i3 << endl ;
        cout << "---------------------------------------------------------------\n\n";
       cout << " Little Swan reservation General Summary. \n\n";
       cout << "----------------------------------------------------------------\n";
       cout << "The Total number of reserved cabins are       : "<< a << endl; 
       cout << "The number of available cabins on Balcony are : "<< b << endl; 
       cout << "The number of available cabins on Windows are : "<< w << endl; 
       cout << "The number of available cabins Inside are     : "<< i << endl;
       cout << endl;
       cout << "Press Enter to procced-----\n";
        
     cin.ignore(); 
     cin.get(); 
       //fin.close();
}
//============================================TRIP CLASS ===========================================
class Trip {
public:
	int tripId;
	string city;
	double basePrice;
	int departDate;
};
//========================================TICKET ====================================================
class Ticket {
private:
	int tripId;
	int cabinLevel;
	int cabinRow;
	int cabinCol;
	char cabinType;
	double price;
	int date;
public:
	Ticket();
    Ticket(int, int, int, int, char, double, int); 
	void printTicket(string);
};

Ticket::Ticket() { // constructor to set default for the ticket
	tripId = -1;
	cabinLevel = -1;
	cabinRow = -1;
	cabinCol = -1;
	cabinType = 'O';
	price = 0.0;
	date = 0;
}

Ticket::Ticket(int id, int r, int n, int m, char c, double p, int d){
	tripId = id;
	cabinLevel = r;
	cabinRow = n;
	cabinCol = m;
	cabinType = c;
	price = p;
	date = d;
}

void Ticket::printTicket(string location) {
	cout << "Trip Location : " <<  location << endl;
	cout << "Cabin : " << "Level " << (cabinLevel+1) 
         << ",Column " << (cabinCol+1) 
         << ",row " << (cabinRow+1)<< endl;
	cout << "Cabin Type: " << cabinType << endl;
	cout << "Price: $" << price << endl;
	cout << "Date: " << date << endl << endl;
}
//==========================================SELL TICKET==============================================
class TicketSell { 
private: 
        Trip location; 
        int date; 
        Cruise record;  
public: 
        void setTrip(Trip t ) {location = t;} 
        void setCruise(Cruise c) {record = c;} 
        void setDate(int d) {date = d;} 
        void displayCabins(); 
        int getTripID() { 
                return location.tripId; 
        } 
   int getTripDate() { 
                return date; 
        } 
 
        bool sell(int r, int n, int m);  
}; 
 
bool TicketSell::sell(int r, int n, int m) 
{ 
                 
        if( !record.checkAvailability(r,n,m))  
                return false; 
     
        string tdestination = location.city; 
         
        Ticket ticket(location.tripId,r,n,m,record.getCabinType(r,n,m),record.getTicketPrice(r,n,m, location.basePrice),date); 
        ticket.printTicket(tdestination); 
     
        record.cabinSold(r, n, m); 
        return true; 
} 
 

void TicketSell::displayCabins() { 
        cout << "Location ID:" << location.tripId << "  "; 
        cout << "Date: " << date << endl; 
 
        for(int j=0; j<LEVELS; j++)    
        {    
                for(int k=0; k<ROWS; k++)    
                {    
                   for(int l=0; l<COLS; l++) 
                        { 
                         cout << record.getCabinType(j,k,l); 
                        } 
                        cout << endl; 
                }  
                        cout << endl;   
        } 
 } 
//========================================TICKET CONTROL=================================================
class TicketControl {
      
private:
	TicketSell *sales[500];
    Trip locations[6]; 
	bool isFull(int, int, int);
	bool daysAvaliable(int);
	int salesTot;
	int tripTot;
public:
	    TicketControl() {
		salesTot = 0;
		tripTot = 0;
	}
    void addTrip(Trip);
	bool checkTrip(int, int);
	void ticketSell(int, int, int, int);
	void displayAvailability(int);
};

void TicketControl::ticketSell(int date, int lev, int row, int col) {
	for (int i=0;i<salesTot;i++) {
		if(sales[i]->getTripDate() == date) {
			if (sales[i]->sell(lev,row,col)) {
				cout << "You can come and pick your ticket.\n" << endl;
			} else {
				cout << "Sorry that ticket is not available.\n" << endl;
			}
		}
	}
	return;
}

bool TicketControl::daysAvaliable(int departure) {
	bool flag = true;
	for (int k=0;k<tripTot;k++) {
		if (Trip[k] != departDate) {
			flag = false;
			break;
		}
	}
	return flag;
}

bool TicketControl::isFull(int m, int n){
	if (type == 0) {
		if (tripTot + n >= 6) {
			cout <<" Trips are booked out " << endl;
			return true;
		} else {
			return false;
		}
	} else {
		if (salesTot + n >= 500) {
			cout <<" Tickets are sold out" << endl;
			return true;
		} else {
			return false;
		}
	}
}

void TicketControl::addTrip(Trip t) {

	if( !daysAvaliable(t.departDate)  {
		cout << "Sorry those dates are not available" << endl;
		return;
	}

	if (isFull(0,1) || isFull(1, t.departDate +1)) return;
    
	trip[tripTot++] = t;
    
	for (;int d= t.departDate;d++) {
		TicketSell *sale = new TicketSell;
		sale->setTrip(t);
		sale->setDate(d);
		Cruise c;
		sale->setCruise(c);
		cout << endl;
		cout << salesTot;
		cout << endl;
		cout << " Trip " + t.location + " on date ";
		sales[salesTot++] = sale;
		cout << sales[salesTot-1]->getTripDate();
		cout << " is generated." << endl; 
	}
}

void TicketControl::displayAvailability(int date) {
	for (int i=0;i<salesTot;i++) {
		if(sales[i]->getTripDate() == date ) {
		   sales[i]->displayCabins();
		   break;
		}	
	}
	return;
}	
//---------------------------------------------Customer class -----------------------------------------------
class customer:public Ticket
{
    public:
    void addCustomer();
    void dispCustomer();
    
    private:
    char name[];
    int payment;
};

 //======================================================================================================
int main()
{
    Cruise w; //declaring an object

  
  cout <<     "\t\t\tWELCOME TO HoliCrusing Company.\n\n\
            This Program will guide you to reserve cabins on  \n \n\n ";
  cout <<     "\t\t\tLITTLE SWAN CRUISE SHIP.\n\n" ;
                        
  cout << " ==================================================================== \n\n";
    cout << " \t=======================================================\n\n";
	  cout << "\t\t ========================================== \n\n";
   
   int ans = 0;
   char ch;
   do 
      {
           cout <<"Please select an action to perform below and press Enter \n\n";
           cout <<" [1] View Cabin configuration \n\n [2] Book Cabins\n\n"; 
           cout <<" [3] View summary of Reserved cabins\n\n" ;// (4)Display available Cabins  \n\n\t
           
           cout <<"\t"; cin >> ans;
 
           switch(ans)
           {
                case 1 :
                     cout << endl ;
                     cout << " \t Please Note: \n";
					 cout << " B -- Cabin with Balcony, W -- Cabin with window \n";
					 cout << " I -- Inside cabin,       X -- Cabin reserved \n\n" ;
					 cout <<"==================================================== \n";
                     w.displayCabinsConfig();
                     break;
           
                case 2 :
                     cout << endl;    
                     w.reserveCabin();
                     break;
                     
                case 3 :
                     cout <<"==================================================== \n";
                     w.displaySummmary();
                     break;
                     
                default:
                        cout << "illegal value! Program aborted.\n";
                        system ("pause");
                        exit(1);
            }            
                cout << "Anything more you would wish to do ?(y/n) ";
                   cin >> ch;
				   //cin.get(ch);
				   if (ch == 'N' || ch =='n')
				   {
					   cout << "\n";
					   cout << "\t\t\t\t Thank you ! Bye  Bye! \n\n\n";
				   }
                cout << "\n";
                 
        }while (ch == 'Y' || ch == 'y');   
   system ("pause");
    return 0;
 }



Was This Post Helpful? 0
  • +
  • -

#8 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: reservation system

Posted 10 April 2010 - 12:28 AM

You defined it: bool isFull(int, int, int); but are using it: bool TicketControl::isFull(int m, int n){
Was This Post Helpful? 0
  • +
  • -

#9 wmugume2000  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 130
  • Joined: 18-March 10

Re: reservation system

Posted 10 April 2010 - 12:44 AM

Fixed that:

ERROR:567 expected primary-expression before '[' token

Have no idea of this error!

#include<iostream>
#include<fstream>
#include<string>
#include <iomanip> 

//#include "cruise.h"
//#include "ticket.h"
//#include "booking.h"
//#include "ticketControl.h"
//#include "summary.h"

using namespace std; 

const int ROWS = 13;  
const int COLS = 4;  
const int LEVELS = 3;  

class Cruise  
{  
private:  
        char cabins[LEVELS][ROWS][COLS];  
        bool validate(char);       
 
public:         
        Cruise(){ReadInformation();}// constructor
        //~Cruise();
        
        void ReadInformation();
        void displayCabinsConfig(); 
        void writeInformation();
        void reserveCabin();
        void displaySummmary();
        bool checkAvailability(int r,int n, int m);
        char getCabinType(int j, int k, int l); 
        double getTicketPrice(int, int, int, double);
	    void cabinSold(int i, int j, int k) 
        {cabins[i][j][k] = 'X';}
}; 

//definition of the functions.  
//-----------------------------------------------------------------------------------------------------  
 
void Cruise :: ReadInformation() 
{
 std::cout << "Begin reading file.\n";  
      
   ifstream fin;
   char c;
   
   fin.open("cabinConfig.txt");
   if (fin.fail( ))
    {
        cout << "Input file opening failed.\n";
        exit(1);// executed if the file fails to open
    }
        fin.get(c); 
        while (!fin.eof())
      
  for(int level=0; level<LEVELS; level++)   
        {   
                for(int row=0; row<ROWS; row++)   
                {   
                        for(int col=0; col<COLS; col++)   
                        {   
                                if (col==0||col==3)   
                                {   
                                        cabins[level][row][col] = (row<5) ? 'B' : 'W';   
                                } else   
                                {   
                                        cabins[level][row][col] = 'I';   
                                } 
                                while (fin.get(c)) 
                                { 
                                        if (validate(c)) 
                                        { 
                                                cabins[level][row][col] = c; 
                                                break; 
                                        } 
                                }   
                        }   
                }   
        }   
 
 fin.close();  
 //std::cout << "File successfully read!\n" << endl;   
} 
//-------------------------------------------------------------------------------------------------------------  
void Cruise:: displayCabinsConfig() 
{
     cout << endl;
cout << " LITTLE SWAN CABIN CONFIGURATION \n\n\n";  
  
   ifstream fin;
   char c;
   fin.open("cabinConfig.txt");
   
   if (fin.fail( ))
        {
            cout << "Input file opening failed.\n";
            exit(1);
        }
    
    fin.get(c); 
    while (!fin.eof())
    {     
          for(int level=0; level<LEVELS; level++)   
            {   
                    cout<<endl;
                    cout << "------------- LEVEL " << (level + 1) << " ------------" << endl;
                    cout<<endl;
                    cout << "    ";   
                    //cout << '+';    
                    for(int col=0; col<COLS; col++) { cout << '\t' << (col+1); }    
                    cout << endl;   
     
                    for(int row=0; row<ROWS; row++)   
                    {   
                            cout << (row + 1);   
                            for(int col=0; col<COLS; col++)  
                            {   
                                    cabins[level][row][col]=c;
                                    cout << '\t' << cabins[level][row][col]; 
                                    fin.get(c);  
                            }   
                            fin.get(c);
                            cout << endl;   
                    }   
                    cout << endl;   
     
            }
      
     }
     fin.close(); 
} 
//----------------------------------------------------------------------------------------------------------------  
void Cruise::writeInformation()
{     
ofstream fin;
fin.open("cabinConfig.txt", ios::trunc);// open file, and replace text with new text
if (fin.fail())
   {
        cout << "Cannot write to file.\n";   
   }
    for(int level=0; level<LEVELS; level++) 
    {
        for(int row=0; row<ROWS; row++)  
        {      
             for(int col=0; col<COLS; col++) 
            {
              fin << cabins[level][row][col];
            }
            fin << endl;
        }      
    }
    
  fin.close();        
}
//------------------------------------------------------------------------------------------------------------------ 
bool Cruise :: validate(char c)   
{  
        if (c=='B' || c == 'I' || c == 'W' || c == 'X')  //Ensure the expected characters are what exist in file
                return true;  
        else   
                return false;  
}  
//--------------------------------------------------------------------------------------------------------------------
void Cruise::reserveCabin()
{
        int i1;
        int j1;
        int k1;
        char resv;
        int bookingId ;
        srand((unsigned)time(0)); 
              int random_integer;     
              int lowest=1, highest=10;    
              int range=(highest-lowest)+1;     
                 
      do
      {  
            cout << endl;
            cout <<" Welcome to the Cruise Reservation "  <<endl;
            cout <<" "  <<endl;
            while(true) 
            { 
                  cout <<"Enter Level 1 - 3 : ";
                  cin >> i1; 
                  cout << endl;
                  cout <<"Enter Row:1-13 : "; 
                  cin>> j1; 
                  cout << endl;
                  cout<<"Enter Column: 1-4 : "; 
                  cin >> k1; 
            if((i1>=0 && i1<=3)&&(j1>=1&&j1<=13)&&(k1>=1&&k1<=4)) 
                  break; 
            else 
                        cerr<<"************ INPUT NOT VALID ***********"<<endl; 
                         
            }
            cout << " ==========================================================\n";
               i1 = i1 - 1; //after array use
               j1 = j1 - 1; //after array use
               k1 = k1 - 1; //after array use
            
        if ((cabins [i1][j1][k1] == 'B') || (cabins [i1][j1][k1] =='I') || (cabins [i1][j1][k1] =='W'))
            {
                cabins[i1][j1][k1] = 'X';
            }
        else if (cabins [i1][j1][k1] == 'X')
            {
                cout << "Sorry!! The Cabin is already booked \n" << endl;
                break;
            }
          writeInformation();
               
          for(int index=0; index < 10; index++)// used to generate a booking Id at random
          {random_integer = (rand()%10);} 
          
          cout<<endl;
          cout << "Thank you for the time, A cabin on \n\n";
          cout << " Level  : " << (i1 + 1) << "\n Row    : " << (j1 + 1) << "\n Column: "<< (k1 + 1) << "\n Has been reserved for you!\n\n";
          cout << " Your booking ID is: " << random_integer << cout << endl;
          cout << " ==========================================================\n\n";
          cout << " Would you like to book another cabin? Y/N" << endl;
          cin >> resv;
          if (resv == 'N' || resv == 'n'){system("pause");}
    }
    while ((resv == 'Y') || (resv == 'y'));
}
//---------------------------------------------------------------------------------------------------------------------
char Cruise:: getCabinType(int r, int n, int m)
{
     //int r,n,m;
if(r>=0 && r<LEVELS && n >= 0 && n < ROWS && m >= 0 && m < COLS) {
		return cabins[r][n][m];
	} else {
		return 'O';
	}
}
//-----------------------------------------------------------------------------------------------------------
double Cruise::getTicketPrice(int r, int n, int m, double basePrice) {
	if(r>=0 && r<LEVELS && n >= 0 && n < ROWS && m >= 0 && m < COLS) {
		double price;
		switch (cabins[r][n][m]) {
			case 'A':
				price = basePrice;break;
			case 'B':
				price = basePrice *1.6;break;
			case 'C':
				price = basePrice *2.0;break;
			case 'D':
				price = basePrice *0.6;break;
			case 'E':
				price = basePrice *0.5;break;
			case 'F':
				price = basePrice *0.4;break;
			default:
				break;
		}		
		return price;
	} else {
		return -1;
	}
}
//----------------------------------------------------------------------------------------------
bool Cruise::checkAvailability(int r,int n, int m) {
	if(r>=0 && r<LEVELS && n >= 0 && n < ROWS && m >= 0 && m < COLS && cabins[r][n][m] !='X') {
		return true;
	} else {
		return false;
	}
}
//=============================================================================================
void Cruise:: displaySummmary()
{
         int lev, row, col;
         int t1 = 0, t2 = 0, t3 = 0;
               
       ifstream fin; 
       int letterCount[26]={0}; 
       string fileName; 
       char next; 
       int a= 0;
       int b =0, b1=0,b2=0,b3=0;
       int i =0, i1=0,i2=0,i3=0;
       int w =0, w1=0,w2=0,w3=0;  
   
       //fin.get word; 
 
       fin.open("cabinConfig.txt"); 
       if (fin.fail( )) 
       { 
           cout << "Sorry cannot read file \n"; 
           exit(1); 
       } 
       while (!fin.eof())  
             while (fin.get(next))   
        {           
                switch (next) 
                { 
                case 'X': 
                        a++; // If it does, increase the counter;  
                        break; 
                case 'B': 
                        b++; // If it does, increase the counter;  
                        break; 
                case 'I': 
                        i++; // If it does, increase the counter;  
                        break; 
                case 'W': 
                        w++; // If it does, increase the counter;  
                        break; 
                } 
        }     
 
        for (int lev = 0; lev < 3; lev++) 
        { 
                for(int row = 0; row < 13; row++) 
                {       
                        for (int col = 0; col < 4; col++) 
                        { 
                                // get next char from array 
                                next = cabins[lev][row][col]; 
 
                                switch (lev) 
                                { 
                                case 0: 
                                        switch (next) 
                                        { 
                                        case 'X': 
                                                t1++; // If it does, increase the counter;  
                                                break; 
                                        case 'B': 
                                                b1++; // If it does, increase the counter;  
                                                break; 
                                        case 'I': 
                                                i1++; // If it does, increase the counter;  
                                                break; 
                                        case 'W': 
                                                w1++; // If it does, increase the counter;  
                                                break; 
                                        } 
                                        break; 
 
                                case 1: 
                                        switch (next) 
                                        { 
                                        case 'X': 
                                                t2++; // If it does, increase the counter;  
                                                break; 
                                        case 'B': 
                                                b2++; // If it does, increase the counter;  
                                                break; 
                                        case 'I': 
                                                i2++; // If it does, increase the counter;  
                                                break; 
                                        case 'W': 
                                                w2++; // If it does, increase the counter;  
                                                break; 
                                        } 
                                        break; 
 
                                case 2: 
                                        switch (next) 
                                        { 
                                        case 'X': 
                                                t3++; // If it does, increase the counter;  
                                                break; 
                                        case 'B': 
                                                b3++; // If it does, increase the counter;  
                                                break; 
                                        case 'I': 
                                                i3++; // If it does, increase the counter;  
                                                break; 
                                        case 'W': 
                                                w3++; // If it does, increase the counter;  
                                                break; 
                                        } 
                                        break; 
                                } 
                        } 
                } 
        } 


      // Print how many 'X' are in the file. Should print 2 
      
       cout << "----------------------------------------------------------------\n";
       cout << "Total number of reverved cabins per Level :\n"; 
       cout << "----------------------------------------------------------------\n\n";
       cout <<"LEVEL 1\n\n";
       cout << "The number of reserved cabins on level 1 : " << t1 << endl;
       cout << "The number of cabins on Balcony available: "<< b1 << endl ;
       cout << "The number of cabins on windows available: "<< w1 << endl ;
       cout << "The number of cabins on Inside available: "<< i1 << endl ;
       cout << "----------------------------------------------------------------\n\n";
        cout <<"LEVEL 2\n\n";
       cout << "The number of reserved cabins on level 2 : " << t2 << endl;
       cout << "The number of cabins on Balcony available: "<< b2 << endl ;
       cout << "The number of cabins on windows available: "<< w2 << endl ;
       cout << "The number of cabins on Inside available: "<< i2 << endl ;
       cout << "----------------------------------------------------------------\n\n";
        cout <<"LEVEL 3\n\n";
       cout << "The number of reserved cabins on level 3 : " << t3 << endl;
       cout << "The number of cabins on Balcony available: "<< b3 << endl ;
       cout << "The number of cabins on windows available: "<< w3 << endl ;
       cout << "The number of cabins on Inside available: "<< i3 << endl ;
        cout << "---------------------------------------------------------------\n\n";
       cout << " Little Swan reservation General Summary. \n\n";
       cout << "----------------------------------------------------------------\n";
       cout << "The Total number of reserved cabins are       : "<< a << endl; 
       cout << "The number of available cabins on Balcony are : "<< b << endl; 
       cout << "The number of available cabins on Windows are : "<< w << endl; 
       cout << "The number of available cabins Inside are     : "<< i << endl;
       cout << endl;
       cout << "Press Enter to procced-----\n";
        
     cin.ignore(); 
     cin.get(); 
       //fin.close();
}
//============================================TRIP CLASS ===========================================
class Trip {
public:
	int tripId;
	string city;
	double basePrice;
	int departDate;
};

//========================================TICKET ====================================================
class Ticket {
private:
	int tripId;
	int cabinLevel;
	int cabinRow;
	int cabinCol;
	char cabinType;
	double price;
	int date;
public:
	Ticket();
    Ticket(int, int, int, int, char, double, int); 
	void printTicket(string);
};

Ticket::Ticket() { // constructor to set default for the ticket
	tripId = -1;
	cabinLevel = -1;
	cabinRow = -1;
	cabinCol = -1;
	cabinType = 'O';
	price = 0.0;
	date = 0;
}

Ticket::Ticket(int id, int r, int n, int m, char c, double p, int d){
	tripId = id;
	cabinLevel = r;
	cabinRow = n;
	cabinCol = m;
	cabinType = c;
	price = p;
	date = d;
}

void Ticket::printTicket(string location) {
	cout << "Trip Location : " <<  location << endl;
	cout << "Cabin : " << "Level " << (cabinLevel+1) 
         << ",Column " << (cabinCol+1) 
         << ",row " << (cabinRow+1)<< endl;
	cout << "Cabin Type: " << cabinType << endl;
	cout << "Price: $" << price << endl;
	cout << "Date: " << date << endl << endl;
}
//==========================================SELL TICKET==============================================
class TicketSell { 
private: 
        Trip location; 
        int date; 
        Cruise record;  
public: 
        void setTrip(Trip t ) {location = t;} 
        void setCruise(Cruise c) {record = c;} 
        void setDate(int d) {date = d;} 
        void displayCabins(); 
        int getTripID() { 
                return location.tripId; 
        } 
   int getTripDate() { 
                return date; 
        } 
 
        bool sell(int r, int n, int m);  
}; 
 
bool TicketSell::sell(int r, int n, int m) 
{ 
                 
        if( !record.checkAvailability(r,n,m))  
                return false; 
     
        string tdestination = location.city; 
         
        Ticket ticket(location.tripId,r,n,m,record.getCabinType(r,n,m),record.getTicketPrice(r,n,m, location.basePrice),date); 
        ticket.printTicket(tdestination); 
     
        record.cabinSold(r, n, m); 
        return true; 
} 
 

void TicketSell::displayCabins() { 
        cout << "Location ID:" << location.tripId << "  "; 
        cout << "Date: " << date << endl; 
 
        for(int j=0; j<LEVELS; j++)    
        {    
                for(int k=0; k<ROWS; k++)    
                {    
                   for(int l=0; l<COLS; l++) 
                        { 
                         cout << record.getCabinType(j,k,l); 
                        } 
                        cout << endl; 
                }  
                        cout << endl;   
        } 
 } 
//========================================TICKET CONTROL=================================================
class TicketControl {
      
private:
	TicketSell *sales[500];
    Trip locations[6]; 
	bool isFull(int, int);
	bool daysAvaliable(int);
	int salesTot;
	int tripTot;
public:
	    TicketControl() {
		salesTot = 0;
		tripTot = 0;
	}
    void addTrip(Trip);
	bool checkTrip(int, int);
	void ticketSell(int, int, int, int);
	void displayAvailability(int);
};

void TicketControl::ticketSell(int date, int lev, int row, int col) {
	for (int i=0;i<salesTot;i++) {
		if(sales[i]->getTripDate() == date) {
			if (sales[i]->sell(lev,row,col)) {
				cout << "You can come and pick your ticket.\n" << endl;
			} else {
				cout << "Sorry that ticket is not available.\n" << endl;
			}
		}
	}
	return;
}

bool TicketControl::daysAvaliable(int departure) {
	bool flag = true;
	for (int k=0;k<tripTot;k++) {
		if (Trip[k] = Trip.departDate) {
			flag = false;
			break;
		}
	}
	return flag;
}


bool TicketControl::isFull(int m, int n){
	if (m == 0) {
		if (tripTot + n >= 6) {
			cout <<" Trips are booked out " << endl;
			return true;
		} else {
			return false;
		}
	} else {
		if (salesTot + n >= 500) {
			cout <<" Tickets are sold out" << endl;
			return true;
		} else {
			return false;
		}
	}
}

void TicketControl::addTrip(Trip t) {

	if( !daysAvaliable(t.departDate))  {
		cout << "Sorry those dates are not available" << endl;
		return;
	}

	if (isFull(0,1) || isFull(1, t.departDate +1)) return;
    
	//Trip [tripTot++] = t;
    
	for (;int d= t.departDate;d++) {
		TicketSell *sale = new TicketSell;
		sale->setTrip(t);
		sale->setDate(d);
		Cruise c;
		sale->setCruise(c);
		cout << endl;
		cout << salesTot;
		cout << endl;
		cout << " Trip " + t.city + " on date ";
		sales[salesTot++] = sale;
		cout << sales[salesTot-1]->getTripDate();
		cout << " is generated." << endl; 
	}
}

void TicketControl::displayAvailability(int date) {
	for (int i=0;i<salesTot;i++) {
		if(sales[i]->getTripDate() == date ) {
		   sales[i]->displayCabins();
		   break;
		}	
	}
	return;
}	
//---------------------------------------------Customer class -----------------------------------------------
class customer:public Ticket
{
    public:
    void addCustomer();
    void dispCustomer();
    
    private:
    char name[];
    int payment;
};

 //======================================================================================================
int main()
{
    Cruise w; //declaring an object

  
  cout <<     "\t\t\tWELCOME TO HoliCrusing Company.\n\n\
            This Program will guide you to reserve cabins on  \n \n\n ";
  cout <<     "\t\t\tLITTLE SWAN CRUISE SHIP.\n\n" ;
                        
  cout << " ==================================================================== \n\n";
    cout << " \t=======================================================\n\n";
	  cout << "\t\t ========================================== \n\n";
   
   int ans = 0;
   char ch;
   do 
      {
           cout <<"Please select an action to perform below and press Enter \n\n";
           cout <<" [1] View Cabin configuration \n\n [2] Book Cabins\n\n"; 
           cout <<" [3] View summary of Reserved cabins\n\n" ;// (4)Display available Cabins  \n\n\t
           
           cout <<"\t"; cin >> ans;
 
           switch(ans)
           {
                case 1 :
                     cout << endl ;
                     cout << " \t Please Note: \n";
					 cout << " B -- Cabin with Balcony, W -- Cabin with window \n";
					 cout << " I -- Inside cabin,       X -- Cabin reserved \n\n" ;
					 cout <<"==================================================== \n";
                     w.displayCabinsConfig();
                     break;
           
                case 2 :
                     cout << endl;    
                     w.reserveCabin();
                     break;
                     
                case 3 :
                     cout <<"==================================================== \n";
                     w.displaySummmary();
                     break;
                     
                default:
                        cout << "illegal value! Program aborted.\n";
                        system ("pause");
                        exit(1);
            }            
                cout << "Anything more you would wish to do ?(y/n) ";
                   cin >> ch;
				   //cin.get(ch);
				   if (ch == 'N' || ch =='n')
				   {
					   cout << "\n";
					   cout << "\t\t\t\t Thank you ! Bye  Bye! \n\n\n";
				   }
                cout << "\n";
                 
        }while (ch == 'Y' || ch == 'y');   
   system ("pause");
    return 0;
 }



Was This Post Helpful? 0
  • +
  • -

#10 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: reservation system

Posted 10 April 2010 - 12:50 AM

Where is the error reported??
Was This Post Helpful? 0
  • +
  • -

#11 wmugume2000  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 130
  • Joined: 18-March 10

Re: reservation system

Posted 10 April 2010 - 12:54 AM

Report

Error - reported at flag=false;

bool TicketControl::daysAvaliable(int departure) {
	bool flag = true;
	for (int k=0;k<tripTot;k++) {
		if (Trip[k] = Trip.departDate) {
			flag = false;
			break;
		}
	}
	return flag;
}


Was This Post Helpful? 0
  • +
  • -

#12 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: reservation system

Posted 10 April 2010 - 12:58 AM

if(Trip[k].depart > depart) ) {

Trip is a class, not a variable.
Was This Post Helpful? 0
  • +
  • -

#13 wmugume2000  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 130
  • Joined: 18-March 10

Re: reservation system

Posted 10 April 2010 - 01:03 AM

Bring up an error!

expected primary-expression before '[' token
Was This Post Helpful? 0
  • +
  • -

#14 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 965
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: reservation system

Posted 10 April 2010 - 01:04 AM

You also need the <ctime> header file included.
Was This Post Helpful? 0
  • +
  • -

#15 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: reservation system

Posted 10 April 2010 - 01:12 AM

if (Trip[k] = Trip.departDate) {

Trip is a class, not a variable.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3