Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
cs-142:airplane-seating-and-checking [2015/06/04 12:19]
cs142ta created
cs-142:airplane-seating-and-checking [2015/06/09 13:03]
cs142ta [Problem]
Line 3: Line 3:
 * You’ve been hired by Delta to write a program to book, assign seating, and track checked baggage for passengers for a flight * You’ve been hired by Delta to write a program to book, assign seating, and track checked baggage for passengers for a flight
 * The program should have a main menu: * The program should have a main menu:
-* * Add passenger (this just books them, not seats them) +** Add passenger (this just books them, not seats them) 
-* * Lookup passenger by name (for seating, checking, etc) +** Lookup passenger by name (for seating, checking, etc) 
-* * Lookup passenger by seat (for seating, checking, etc) +** Lookup passenger by seat (for seating, checking, etc) 
-* * Display all passengers (all booked, seated or not) +** Display all passengers (all booked, seated or not) 
-* * Display seating chart+** Display seating chart
 * Use a vector to track a list of all passengers and a 2D array to represent a seating chart * Use a vector to track a list of all passengers and a 2D array to represent a seating chart
 * When a passenger is looked up by name or seat, a passenger summary should appear and an edit menu should provide functionality to * When a passenger is looked up by name or seat, a passenger summary should appear and an edit menu should provide functionality to
-* * Assign seat +** Assign seat 
-* * Check baggage +** Check baggage 
-* * Return to the main menu+** Return to the main menu
 * The plane has 10 rows and 4 seats per row (A, B, C, & D) * The plane has 10 rows and 4 seats per row (A, B, C, & D)
 ==Solution== ==Solution==
Line 373: Line 373:
 void display_seating_chart(Passenger * seating_chart[][SEATS_PER_ROW]) void display_seating_chart(Passenger * seating_chart[][SEATS_PER_ROW])
 { {
 +        //First print a row of seat labels (e.g., A, B, C, D)
  cout << " ​   ";  cout << " ​   ";
  for (int seat = 0; seat < SEATS_PER_ROW;​ seat++)  for (int seat = 0; seat < SEATS_PER_ROW;​ seat++)
Line 380: Line 381:
  cout << " ​  ";​  cout << " ​  ";​
  }  }
 +                // NOTE: the NOTE in the lookup_passenger_by_seat function explains ​
 +                //       the relationship between the seat label (e.g., '​A'​) and the seat index (e.g., 0)
  char seat_char = FIRST_SEAT + seat;  char seat_char = FIRST_SEAT + seat;
  cout << seat_char << " ";  cout << seat_char << " ";
  }  }
  cout << endl;  cout << endl;
 +
 +        // Print the 2D seating chart matrix
  for (int row = 0; row < ROWS; row++)  for (int row = 0; row < ROWS; row++)
  {  {
- cout << row << " | ";+ cout << row << " | "; ​// row label and left cabin wall
  for (int seat = 0; seat < SEATS_PER_ROW;​ seat++)  for (int seat = 0; seat < SEATS_PER_ROW;​ seat++)
  {  {
  if (seat == SEATS_PER_ROW / 2)  if (seat == SEATS_PER_ROW / 2)
  {  {
- cout << " ​  ";​+ cout << " ​  "; ​// aisle
  }  }
- if (seating_chart[row][seat] == NULL)+ if (seating_chart[row][seat] == NULL) // if seat is unoccupied
  {  {
- cout << "_ ";+ cout << "_ "; ​// unoccupied
  }  }
  else  else
  {  {
- cout << "X ";+ cout << "X "; ​// occupied
  }  }
  }  }
- cout << "​|"​ << endl;+ cout << "​|"​ << endl; // right cabin wall
  }  }
  
cs-142/airplane-seating-and-checking.txt · Last modified: 2015/06/09 13:03 by cs142ta
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0