Thread: Help with Airplane Seating Code

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    1

    Help with Airplane Seating Code

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    void initialize_seat(char seat[20][10], char req_seat[20][10]);
    int getrow();
    int getcol();
    int checkseat(char req_seat[20][10], char seat[20][10], int row, int col);
    void print_rpt(char seat[20][10]);
    int main(void)
    {
     char req_seat[20][10], seat[20][10], cont = 'Y';
     int row, col;
     int status;
     initialize_seat(seat, req_seat);
     while (cont == 'Y' || cont == 'y')
     {
      row = getrow();
      col = getcol();
      req_seat[row][col] = 'X';
      status = checkseat(req_seat, seat, row, col);
      if (status) 
      {
       seat[row][col] = req_seat[row][col];
      }
      printf("Do You Want To Continue (Y/N)?  \n");
      scanf("%c", &cont);
     }
     /* print report */
     print_rpt(seat);
     return(0);
    }
    void initialize_seat(char seat[20][10], char req_seat[20][10])
    {
     int col, row;
     for (row = 0; row < 20; ++row)
     {
      for (col = 0; col < 10; ++col)
      {
       req_seat[row][col] = 'A';
       seat[row][col] = 'A';
      }
     }
    }
    int getrow()
    {
     int row;
     printf("Plese Enter Seat's Row: ");
     scanf("%d", &row);
     return(row);
    }
    int getcol()
    {
     int col;
     /* Insert Code Here */
     printf("Please Enter Seat's Column: ");
     scanf("%d", &col);
     return(col);
    }
    int checkseat(char req_seat[20][10], char seat[20][10], int row, int col)
    {
     int status = 0;
     /* Add Code To Check for Seat[col][row] Here! */
     /* Check to make sure that seat[col][row] is still blank */
     /* If so set seat[col][row] = req_seat[col][row] */
     /* If not then print the message "Seat Not Available" */
     /* and ask user to reinput req_seat */
     while(seat[row][col] == req_seat[row][col])
     {
      /* Add Code To Re-Input Here! */
      printf("Seat Not Available!!\n\nPlease Re-Enter Your Selection!\n\n");
      /* Call back to getseat() */
      row = getrow();
      col = getcol();
      req_seat[row][col] = 'X';
     }
     status = 1;
     /* Add code Here to set seat[col][row] = req_seat[col][row] */
     return(status);
    }
    void print_rpt(char seat[20][10])
    {
     int col, row;
     for (row = 0; row < 20; ++row)
     {
      for (col = 0; col < 10; ++col)
      {
       printf("%c ", seat[row][col]);
      }
      printf("\n");
     }
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    So what is your question or problem?

    Jim

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    cross-posted here -> Any ideas? - C++ Forum
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with seating chart thingy
    By gcn_zelda in forum C++ Programming
    Replies: 2
    Last Post: 05-01-2003, 09:07 AM
  2. Seating Program
    By gcn_zelda in forum C++ Programming
    Replies: 2
    Last Post: 04-26-2003, 06:01 PM
  3. Airplane game
    By JoshG in forum Game Programming
    Replies: 4
    Last Post: 06-08-2002, 03:47 PM
  4. airplane again
    By edshaft in forum C++ Programming
    Replies: 5
    Last Post: 12-11-2001, 02:31 PM

Tags for this Thread