Hi, there, I have written a program here which shows plane to book a seat, and enter flight info(this part works fine)... but having some small problem here I am using gotoxy and it gives me an error, it says that gotoxy undeclared. Could anyone help me with this please, correct the code or tell me how to do it. I am using Dev C++. Thanks in advance.

heres the code for it:

#include <iostream>
#include <cstring>
#include <string>
#include <iomanip>
#include <stdlib.h>
#include <conio.h>
//#include <stdio.h>
//#include "cursor.h"
#include <windows.h>

using namespace std;
       
struct  FlightDetails
{  	
     string ID;
     string departure;
     string destination;
     string airlineName;
     //double adultPrice = 200;
     //double childPrice = 50;
     //double totalPrice = 0;     
};
typedef struct FlightDetails F;

struct Flight
{    F flightRecord;
	 struct Flight *link;
};
typedef struct Flight node;

//SHOW PLANE
const int MAX_PAX = 120;
const int ROWS = 30;
const int START_X = 9;
const int START_Y = 4;

char menu();
void showPlane();
void checkMouseAtSeat(char letters[], int rows[], int serials[], int& pax);
int getRefNumber(int serials[], int pax);
void populatePlane(char letters[],int rows[], int pax);
bool seatBooked (char letter, int ROW, char letters[], int rows[], int pax);
bool isUniqueSerial(int serial, int serials[], int pax);
void cancelBooking(int serials[], char letters[], int rows[], int& pax);
int cancelInput (char input[]);
void drawLine1();
void drawLine2();
void drawLine3();
void drawLine4();
//void gotoxy(int x, int y);
void printList (char letters[], int rows[], int serials[], int pax);
//SHOW PLANE END

node * createList(node * head, F flightRecord, node ** last);
node * createFlightNode(node * newNode, F flightRecord);
void displayList(node * head);

int main()
{	
   //plane
   system ("CLS");
   //system ("COLOR F1");
	
   char letters[MAX_PAX];
   int rows[MAX_PAX] = {0};
   int serials[MAX_PAX] = {0};
    
   int serial = 0;
   int pax = 0;

   char choice;  
   //plane   
        
   //char choice;   
   node *head=NULL; 
   node *last=head; //initial value//&last is a double pointer
   F flightRec;
    do
    {              
              //main menu  
              //system("CLS");
              cout << "\n\n\n\n\n\n";
              
              cout << setw(40) << " Menu \n\n";
              cout << setw(40) << " 1:" << " Enter Flight Details:\n " << endl;
              cout << setw(40) << " 2:" << " Display Flight Details:\n " << endl;
              cout << setw(40) << " 3:" << " Book a Seat:\n " << endl;
			  cout << setw(40) << " 4:" << " Exit\n " << endl;
              cin >> choice;  
              cin.get();
              
              //start of switch statement
              switch(choice)
             {
              case '1' : system("CLS");  //ENTER FLIGHT DETAILS
               {                         
                  ///// FLIGHT /////
			      //FlightNode * createFlightList(FlightNode * head);
				    node * createFlightNode(node * newNode, F flightRecord);
					{							     
						 cout << "Enter Flight ID: " << " ";
						 cin  >> flightRec.ID;
						 cout << endl;
							     
						 while( flightRec.ID != "!")
			              {
                              //cout << "Enter Flight ID:";
			                  //cin  >> flightRec.ID;
			                  //cout << endl;
							     
			                  cout << "Enter Departure Airport: " << " ";
			                  cin >> flightRec.departure;
			                  cout << endl;
							     
			                  cout << "Enter Destination Airport: " << " ";
			                  cin >> flightRec.destination;
			                  cout << endl;
							     
			                  cout << "Enter Airline Title: " << " ";
			                  cin >> flightRec.airlineName;
			                  cout << endl;
			                  system("CLS");
								 
							  cout << "Enter - ! -  to exit:";
							  cout << endl;
							  cout << " or " << endl;
                              cout << endl;
                                                     
							  head=createList(head,flightRec,&last); 
							                     								                     
                              //this passes back the double pointer &last for the next position 
                              cout << "Enter Flight ID: " << " ";
                              cin >> flightRec.ID;
                              system("CLS");          
                          }//end while
				     }//end node
                   }//case A end
                   break; 
                   
                   case '2' : system("CLS");
                   {
                        displayList(head);
                        cout << endl;
                        system("pause");
                        system("CLS");
                   }//case B end
                   break;         
                   
                   case '3' : system("CLS");
                   {
                        char choice;
                        do
                         {
                             system ("CLS");
	 	                     cout << "\n\n\n";
                             cout << setw(35) <<"" << "MENU:" << endl;
		                     cout << setw(37) << right << "B : "; cout << "Book a seat\n";
		                     cout << setw(37) << right << "C : "; cout << "Cancel booking\n";
		                     cout << setw(37) << right << "E : "; cout << "Exit\n";
		                     cout << setw(37) << right << "Enter choice : ";
                             cin >> choice;
                             choice = toupper(choice);
                          } 
                          while ((choice != 'B') &&	(choice != 'C') && (choice != 'E'));	
                          return choice;
                        do
                        {
                          choice = menu();
        
                          if (choice == 'B')
                          {
                          system ("CLS");
                          showPlane();
                          populatePlane(letters, rows, pax);
                          checkMouseAtSeat(letters, rows, serials, pax);
                          cout << endl << setw(15) << ""; 
                          system("pause");
                          }
                          else if (choice == 'C')
                          {
                          system ("CLS");
                          showPlane();
                          populatePlane(letters, rows, pax);
                          cancelBooking(serials, letters, rows, pax);   
                          system("pause");     
                          }
                          else (choice == 'E'); 
                          {
                          return 0;
                          }      
                        }//do end
                         while (choice != 'E');
                    }//case 3 end
             }//end switch
       }//do end
   while (choice != '4'); 
}//int end

 //function to create one node with details
 node * createFlightNode(node * newNode, F flightRecord)
 {
    newNode = new node;
    newNode-> flightRecord = flightRecord;    
    newNode->link = NULL;
    
    return newNode;
 }
 //adds one record at a time to the list, double pointer last returned with new last value
 node *createList(node * head, F flightRec, node ** last)
 {  
   if( head == NULL)
    {        
    head = createFlightNode(head, flightRec);
    //the contents of the double pointer same as original last
    //pointer
    *last = head; 
    }
   else 
    {      
    //(*last) refers to old last pointer		
    (*last)-> link = createFlightNode(  (*last)->link, flightRec);
    //*last refers to old last single pointer
    *last = (*last)->link;
    }
   return head;
 }
 
 void displayList(node * head)
  {
     node * current;             
     //current now contains the address held of the 1-st node similar to head
     current = head;
     cout << "\n\n" <<endl;

     if(current == NULL)
     {
     cout << "Empty List\n\n" << endl;
     }
    else
    {
     while(current!= NULL)
     {
      cout << "Flight ID            :" << "  "<< current->flightRecord.ID << endl;
      cout << "Departure Airport    :" << "  "<< current->flightRecord.departure << endl;
      cout << "Destination Airport  :" << "  "<< current->flightRecord.destination << endl;
      cout << "Airline Name         :" << "  "<< current->flightRecord.airlineName << endl;
      current = current->link;
      cout << endl << endl;
     }//end while
    }//end else
   }//end void

//plane
void drawLine1()
{
   for(int i = 0; i < ROWS - 1; i++)
   {
      cout << (char)205 << (char) 203;
   }
}

void drawLine2()
{
   cout << (char)186;
   
   for(int i = 0; i < ROWS; i++)
   {
      cout << ' ' <<  (char)186;
   }
}

void drawLine3()
{
   cout << (char)204;
   
   for(int i = 0; i < ROWS - 1; i++)
   {
      cout << (char)205 << (char) 206;
   }
   
   cout << (char)205 << (char)185;
}

void drawLine4()
{
   for(int i = 0; i < ROWS - 1; i++)
   {
      cout << (char)205 << (char)202;
   }
}

void showPlane()
{
   int start_x = START_X + 1;
   int start_y = START_Y + 1;
   
   gotoxy(start_x, start_y -1);
   for(int i = 0; i < ROWS; i++)
   {
      cout << setw(2) << i + 1;
   }
   
   gotoxy(start_x, start_y);
   cout << (char)201;
   drawLine1();
   cout << (char)205 << (char)187;
   
   gotoxy(start_x - 1, start_y + 1);
   cout << 'A';
   drawLine2();
   
   gotoxy(start_x, start_y + 2);
   drawLine3();
   
   gotoxy(start_x - 1, start_y + 3);
   cout << 'B';
   drawLine2();
   
   gotoxy(start_x, start_y + 4);
   cout << (char)204;
   drawLine4();
   cout << (char)205 << (char)185;
   
   gotoxy(start_x, start_y + 5);
   cout << (char)186;
   for(int i = 0; i < ROWS-1; i++)
   {
      cout << "  ";
   }
   cout << ' ' << (char)186;
   
   gotoxy(start_x, start_y + 6);
   cout << (char)204;
   drawLine1();
   cout << (char)205 << (char)185;
   
   gotoxy(start_x - 1, start_y + 7);
   cout << 'C';
   drawLine2();
   
   gotoxy(start_x, start_y + 8);
   drawLine3();
   
   gotoxy(start_x - 1, start_y + 9);
   cout << 'D';
   drawLine2();
   
   gotoxy(start_x, start_y + 10);
   cout << (char)200;
   drawLine4();
   cout << (char)205 << (char)188;
   
   cout << endl<<endl;
  
}

void checkMouseAtSeat(char letters[],int rows[], int serials[], int& pax)
{
     bool mouseAtSeat;
     char letter;
     int mouseX, mouseY, ROW;

     do
     {
         mouseAtSeat = true;
         //where_mouse (mouseX, mouseY);
         if (mouseX < START_X + 2 || mouseX > START_X + ROWS * 2) mouseAtSeat = false;
         if (mouseY < START_Y + 2 || mouseY == START_Y + 6) mouseAtSeat = false;
         if (mouseY > 15) mouseAtSeat = false;
         if ((mouseY - START_Y)%2 != 0 || mouseY == START_Y + 6) mouseAtSeat = false;
         ROW = (mouseX - START_X);
         if (ROW % 2 != 0) mouseAtSeat = false;
         if (mouseAtSeat)
         {
            ROW = ROW/2;
            const int a = START_Y + 2;
            const int b = START_Y + 4;
            const int c = START_Y + 8;
            const int d = START_Y + 10;
            switch (mouseY)
            {
                   case a: letter = 'A'; break;
                   case b: letter = 'B'; break;
                   case c: letter = 'C'; break;
                   case d: letter = 'D'; break;
            } // close switch
            
            mouseAtSeat = seatBooked (letter, ROW, letters, rows, pax);
            
         } 
     } while (!mouseAtSeat);
     
     gotoxy(mouseX, mouseY);
     cout <<(char)219;
          
     letters[pax] = letter;
     rows[pax] = ROW;
     gotoxy(0, 18);
     cout << setw(25)<< "Seat: " << letters[pax] << rows[pax] << endl;
     serials[pax] = getRefNumber(serials, pax);
     pax++;
}

int getRefNumber(int serials[], int pax)
{
    int serial = 0;
    bool isUniqueRefNumber;
    
    do
    {
        srand((int)time(0));
        int span = 10000;
        int start = 10000;
        serial = rand() % span + start;
        isUniqueRefNumber = isUniqueSerial(serial, serials, pax);
    } while (!isUniqueRefNumber);
    
    cout << setw(25)<< "Ref. Number: " << serial << endl << endl;
    
    return serial;
}

void populatePlane(char letters[],int rows[], int pax)
{
     int x = 0, y = 0;
     for(int i=0; i<pax; i++)
     {          
          int x = 0, y = 0;   
          x = START_X + rows[i]*2;
          if (letters[i] == 'A') y = START_Y + 2;
          if (letters[i] == 'B') y = START_Y + 4;
          if (letters[i] == 'C') y = START_Y + 8;
          if (letters[i] == 'D') y = START_Y + 10;
          if (pax != 0)
          {
             gotoxy(x,y);
             cout << (char)219;
          }
     }
}

bool seatBooked (char letter, int ROW, char letters[], int rows[], int pax)
{
     bool mouseAtSeat = true;
     for (int i=0; i<pax; i++)
     {
         if ((letters[i] == letter) && (rows[i] == ROW)) mouseAtSeat = false;
     }
     return mouseAtSeat;
}

bool isUniqueSerial(int serial, int serials[], int pax)
{
     bool isUniqueRefNumber = true;
     for (int i=0; i<pax; i++)
     {
         if (serials[i] == serial) isUniqueRefNumber = false;
     }
     return isUniqueRefNumber;
}

void cancelBooking(int serials[], char letters[], int rows[], int& pax)
{
     char input[5];
     int refNumber = 0;
     bool itemFound = false;     
     int i = 0;
     int z = 0;
     gotoxy(0, 18);
     cout << setw(15) << ""<< "Canceling. To exit enter 0 below.";
     cout << endl;
     cout << setw(15)<< "" << "Please provide your 5 digit Ref. Number: ";
     do
     {          
          refNumber = cancelInput(input);
          if (refNumber)
          {
              for (i=0; i<pax; i++)
              {
                  if (refNumber == serials[i])
                  {
                     itemFound = true;
                     cout << endl << setw(15) << "" << "Booking for seat " <<
                     letters[i] << rows[i] << " canceled.\n\n";
                     for (z=i; z<pax-1; z++)
                     {
                       serials[z] = serials[z+1];
                       letters[z] = letters[z+1];
                       rows[z] = rows[z+1];
                     }
                     pax--;
                     showPlane();
                     populatePlane(letters, rows, pax);
                     gotoxy(0,21);
                     cout << endl << setw(15) << ""; system("pause");
                     input[0] = '0';
                  }
              }
          }
          if (!itemFound && refNumber)
          {
               cout << endl << setw(15) << "" << "Number " <<
               refNumber << " not found!\n\n";
               cout << endl << setw(15) << ""; system("pause");
               break;
          }
     } while (input[0] != '0');
}

int cancelInput(char input[])
{
    int refNumber = 0;
    bool itemOk = false;
    do
    {
        cin >> input;
        refNumber = atoi (input);
        if (atoi (input)) itemOk = true;
        else itemOk = false;
        if (input[0] == '0') itemOk = true;
    } while (!itemOk);
    return refNumber;
}

void printList (char letters[], int rows[], int serials[], int pax)
{
     cout << "Seat" << "  " << "Ref." << endl;
     for (int i=0; i<pax; i++)
     {
         cout << letters[i] << rows[i] << "  " << serials[i] << endl;     
     }
     cout << pax << " passengers\n\n";
}

/*void gotoxy(int x, int y) 
{ 
HANDLE hConsoleOutput; 
COORD dwCursorPosition; 
cout.flush(); 
dwCursorPosition.X = x; 
dwCursorPosition.Y = y; 
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); 
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition); 
} */

Recommended Answers

All 23 Replies

Hi , does it still give the error when you uncomment line 50 and the function definition in lines 535 - 544? Because from the above code as it is, I dont see the declaration of the function gotoxy as i expected, neither is the function definition activated.

Cheers.

Hi, there, I have written a program here which shows plane to book a seat, and enter flight info(this part works fine)... but having some small problem here I am using gotoxy and it gives me an error, it says that gotoxy undeclared. Could anyone help me with this please, correct the code or tell me how to do it. I am using Dev C++.

In the Dev C++ documentation, what does it say about the gotoxy() function? What ate the parameters? What header is needed?

I believe it's a non-standard BGI function from Borland's library. It's probably not going to be included with the Dev-C++ gcc.

I believe it's a non-standard BGI function from Borland's library. It's probably not going to be included with the Dev-C++ gcc.

That's why I asked dinamit875. He's using the compiler. :icon_wink: I already know about Borland. I don't know Dev well enough, though.

I already know about Borland.

I kinda thought you would've but since it came out after TECO I figured it was worth mentioning. :D I'm not expert on Dev either but I'm fairly certain that the gcc doesn't have it in the libraries (and I went through this with another poster trying to find an alternative).

The solution ends up being a library like pdcurses which has equivalent constructs.

Hi , does it still give the error when you uncomment line 50 and the function definition in lines 535 - 544? Because from the above code as it is, I dont see the declaration of the function gotoxy as i expected, neither is the function definition activated.

Cheers.

hi, when I uncomment those lines. which you ave mentioned, it doesn't give me an error, the program compiles and runs fine,first and second menu function works fine, but when I come to "book a seat" number 3 in main menu, it starts fine but when I enter "A" or "B" or "C" it just stops and debugger just closes(((( i can't figure out why, I have system("pause") added into it, but it doesn't helps either(((

In the Dev C++ documentation, what does it say about the gotoxy() function? What ate the parameters? What header is needed?

hi there, sorry but i don't really know about all these documentations, but one thing I know and everyone is being talking about is that gotoxy is Borland function((

Why do people read one post and ignore all others? Maybe one or two of the others have some useful information or necessary questions...

the program compiles and runs fine

This wasn't what you said in your first post. How did you get it to work?

Why do people read one post and ignore all others? Maybe one or two of the others have some useful information or necessary questions...

:-O

This wasn't what you said in your first post. How did you get it to work?

you see, it compiles when i have uncommented line 50 and last function in the program, it runs fine, but the function to "book a seat" is not working, it was supposed to show plane and by clicking on certain seat should give you a seat number and reference to it, the only thing it does is first two menu functions "book flight" and "show flight"

In the Dev C++ documentation, what does it say about the gotoxy() function? What ate the parameters? What header is needed?

hi there, sorry but i don't really know about all these documentations, ...

Then how do you know how to use the compiler? You need to "know about all these documentations" to know what the compiler is capable of.

... but one thing I know and everyone is being talking about is that gotoxy is Borland function((

Yeah, I know, too. I wish he didn't bring it up because Borland is not Dev, and everything's now confused. Ignore all mention of Borland.

Where is the definition of menu()? I see it declared and I see it called but nothing else. It seems to be where it's crashing.

I wish he didn't bring it up

That's my bad. I misinterpreted the whole thing up until I finally saw that OP had written his own function gotoxy as it was commented out -- no excuse I know(I only saw the prototype before). I thought he was trying to get something originally done under Borland with graphics.h to work under Dev. by declaring the prototype just to quell the compiler. Wow. Yeah...

Where is the definition of menu()? I see it declared and I see it called but nothing else. It seems to be where it's crashing.


That's my bad. I misinterpreted the whole thing up until I finally saw that OP had written his own function gotoxy as it was commented out -- no excuse I know(I only saw the prototype before). I thought he was trying to get something originally done under Borland with graphics.h to work under Dev. by declaring the prototype just to quell the compiler. Wow. Yeah...

well, about menu, it is declared and called ...what am I missing in my code? is it a piece of code at the end??

You need a definition, yes. If your program is trying to call a function that wasn't defined it will crash (I haven't attempted to fill in a definition for menu()).

You need a definition, yes. If your program is trying to call a function that wasn't defined it will crash (I haven't attempted to fill in a definition for menu()).

so, the menu has to be defined, but where will i define that function, could you help me with it, please))

Close but no cigar as usual. I'm really on a roll tonight. It's right here on line 165: [b]return choice;[/b] It looks like you dumped your Menu() routine into the main code body and never took out the return statement.

where will i define that function

I would just clear out line 168 completely (and the prototype at the top). You already have the "choice" value from the prompt above that.

Close but no cigar as usual. I'm really on a roll tonight. It's right here on line 165: [b]return choice;[/b] It looks like you dumped your Menu() routine into the main code body and never took out the return statement.


I would just clear out line 168 completely (and the prototype at the top). You already have the "choice" value from the prompt above that.

well, i have cleared line 168, but i just don't get it about line 165, will i remove return choice? or what should i do?

Ok. You're in main and at the end you hit a return 0; what happens to the program? Exit time. Not what you want. Take it out.

Ok. You're in main and at the end you hit a return 0; what happens to the program? Exit time. Not what you want. Take it out.

I have it done and it shows the plane as it should be, but another error has come, its on the line 366..
//where_mouse(mouseX, mouseY);
it is commented, but when I get it uncommented, the compiler tells me that where_mouse is undeclared, how can I get it declared? because this has to be used to book a seat.Thanks.

That one I have no idea. It may be in the library associated with cursor.h that you included and then commented out. You wrote the code so I assume you know where that came from.

That one I have no idea. It may be in the library associated with cursor.h that you included and then commented out. You wrote the code so I assume you know where that came from.

I wrote that code about 2 years ago, and now I need to use it in a different program, but I can't remember how to solve most of its errors(((unfortunately. About corsor.h when I uncomment it, it tell me that there is no such file or directory((

I got it working, thanks for your help everyone!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.