0
#include <algorithm>
    #include <cassert>
    #include <cstdint>
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <vector>
    // Use these constants for your arrays.
    const int MAX_ROWS   = 100;
    const int MAX_WIDTH  = 100;
    // Side of an airplane, port or starboard. These terms are more
    // precise than "left" and "right," which vary depending on whether
    // you're facing forward or backward.
    enum Side { 
       NotStowed = -1,
       Port, 
       Starboard 
    };
    class Passenger;
    // TODO: From here on, you need to implement all of the member functions and
    // add all of the member variables.
    // --------------------------------------------------------------------------
    // Represents a carryon bag owned by a passenger.
    // Each bag has a single owner.
    class Bag {
    public:
       // Owner is a pointer to a Passenger object. A bag is
       // initialized not "stowed," meaning that it hasn't been 
       // stored in an overhead bin.
       Bag(const Passenger* owner) { 
          assert(owner); 
       }
       const Passenger* owner() const { 
          return nullptr; 
       }
       // Return true if the bag is stowed.
       bool is_stowed() const { 
          return false; 
       }
       // Stow the bag at the given bin location. 
       void stow(Side side, int row) {
          assert(side != Side::NotStowed);
          assert(row >= 0); 
          assert(row < MAX_ROWS); 
       }
       // Getters for the stow location.
       Side side() const { return Side::NotStowed; }
       int row() const { return -1; }
    private:
       // TODO add member variables here.
    };
    // Represents one passenger, who may or may not have one carryon bag.
    class Passenger {
    public:
       // Create a passenger. id is a unique number which must be
       // positive. row and seat designate a seat location, which each must
       // also be positive. The passenger is created with no bags.
       //   
       // Row and seat are a zero based indices.
       Passenger(int id, int row, int seat) {}
       // getters
       int id() const { return -1; }
       int row() const { return -1; }
       int seat() const { return -1; }
       // Create a bag and assign it to this passenger.
       void bring_carryon() {}
       // Returns nullptr if passenger has no bags.
       Bag* carryon() { return nullptr; }
    private:
       // TODO add member variables here.
    };
    // Represents a model of airplane, use static arrays to store the Passengers and 
    // their carryons.
    class Airplane {
    public:
       // Initialize an airplane with a given number of rows of seats, and
       // width (number of passengers per row). Each argument must be
       // positive.
       Airplane(int rows, int width) {
          assert(rows >= 0);
          assert(rows < MAX_ROWS);
          assert(width >=0 );
          assert(width < MAX_WIDTH);
          // TODO: code that initializes the Airplane to an empty state.
       }
       int rows() const { return -1; }
       int width() const { return -1; }
       /*
       Prints out the passenger seating in a table.
       Each column is separated by a single space.
       The first column is 3 characters wide and displays the row number.
       The following columns are 6 characters wide and display the Seat numbers.
       The first line has the title of the printout "Seats"
       The second line are the column titles "Row Seat 1 Seat 2 Seat 3 Seat 4 Seat N".
       Empty seats display '------'.
       This is what a printout for an airplane with 10 rows, 4 wide, 36 passengers
       looks like:
       Seats
       Row Seat 1 Seat 2 Seat 3 Seat 4 
         1      1      2      3      4 
         2      5      6      7      8 
         3      9     10     11     12 
         4     13     14     15     16 
         5     17     18     19     20 
         6     21     22     23     24 
         7     25     26     27     28 
         8     29     30     31     32 
         9     33     34     35     36 
        10 ------ ------ ------ ------ 
       Please follow these instructions to make yours look just like this, 
       it'll make grading a lot easier for me.
       */   
       void PrintSeats() const {}
       /* Follow similar rules to above, print out the overhead bin configuration:
          Overhead Bins
          Row Port Starboard
            1   27   32 
            2   30   17 
            3   22   19 
            4 [  ] [  ]
            5 [  ] [  ]
            6 [  ] [  ]
            7 [  ] [  ]
            8 [  ] [  ]
            9 [  ] [  ]
           10 [  ] [  ]
       */
       void PrintOverheadBins() const {}
       // Attempt to place a passenger's carryon bag in an overhead bin.
       // Returns true if successful (or the passenger had no bag), 
       // false if there was a problem sotwing a bag.
       //
       // If the passenger has a carryon, try to find a location for it using the following
       // algorithm:
       // Try row 1 port side; if full, 
       // try row 1 starboard side; if full, 
       // try row 2 port side; if full, 
       // try row 2 starboard side; if full, 
       // try row 3 port side; etc. 
       //
       // The bag is stored in the plane's bin 2D array and 
       // the carryon's stow() function is called to record where the bag is.  
       bool place_carryon(Passenger* p) {
          assert(p);
          // No spot found.
          return false; 
       }   
       // Seat the passenger at the correct row and seat. 
       bool seat_passenger(Passenger* p) {
          assert(p);
          assert(p->row() >= 0);
          assert(p->row() < rows());
          assert(p->seat() >= 0);
          assert(p->seat() < width());
          return false;
       }
    private:
       // TODO add your member variables here.
    };
3
Contributors
3
Replies
15
Views
1 Year
Discussion Span
Last Post by Shattered
0

I really need help, I do not understand how the plane works, with passangers and bags. I do not get how to fill in the blank spots.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.