CMSC 104, Section 01, Fall 2016
Problem Solving and Computer Programming

Project 8

Due Date: Tuesday, December 13th @ 5:30 PM

Point Value: This project is graded with a 75 point max score.


To become more familiar with:

  1. (35 points) A small airline has just purchased a computer system for its new automated reservations system. The president has asked you to program the new system. You will write a program called campusid_airline.c to assign seats on each flight of the airline's only plane (capacity: 10 seats). Your program should display the following menu of options:

    Please type 1 for "First Class"
    Please type 2 for "Economy"

    If the agent types 1, then your program should assign a seat in the first class section (seats 1-4). If the person types 2, then your program should assign a seat in the economy section (seats 5-10). Your program should then print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane.

    Use a one-dimentional array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding element of the array to 1 to indicate that the seat is no longer available. Your program should never assign a seat that has already been assigned. When the first class section is full, your program should ask the agent if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message "Next flight leaves in 3 hours."

    Your boarding pass should exactly like this:
    **       UMBC Airlines        **
    **          Economy           **
    **          Seat 7            **

  2. (40 points) Can a knight move around a chess board touching each square exactly once? To try and find out, I've created a program called knight.c to run a series of simulations, and I need you to finish some functions to make it work!

    A chess board is an 8x8 grid of squares and a knight moves around the board according to one of the following rules:
    • two squares in the x-direction and one square in the y-direction
    • one square in the x-direction and two squares in the y-direction

    The knight.c program conducts the knight's tour 10,000 times, recording each tour length (a tour is defined as the number of moves through the board until the knight cannot move anymore), the average tour length, the longest tour length, and a printout of the longest tour. The tour begins by selecting a random starting position, and for each move, one of the possible available moves is selected randomly. In essence, each of the 10,000 tours is different.

    To finish the program, you must implement the following functions:

    void ClearBoard(int chessBoard[BOARD_WIDTH][BOARD_WIDTH]);
    void PrintBoard(int chessBoard[BOARD_WIDTH][BOARD_WIDTH]);
    void CopyBoard(int src[BOARD_WIDTH][BOARD_WIDTH], int dest[BOARD_WIDTH][BOARD_WIDTH]);
    int HasMoreMoves(int x, int y, int chessBoard[BOARD_WIDTH][BOARD_WIDTH]);
    int IsValidMove(int x, int y, int chessBoard[BOARD_WIDTH][BOARD_WIDTH]);

    The function header comments describe what the function should do, although you will also need to read the program's main function to fully understand how the program works. When you have completed the program, the output should look similar to this:

    $ ./a.out
    Total simulations run: 10000
    Best run move list:
      -1  45  50  41  12  31  34  -1
      49  42  47  58  33  40  13  30
      46  51  44  11  14  29  32  35
      43  48  57  28  59  36  39  22
      52  27  10  15  56  23  60  37
       5   2  55  26   9  38  21  18
       0  53   4   7  16  19  24  61
       3   6   1  54  25   8  17  20
    Total moves in best run: 61
    Average moves per run:   33.615600

    Use the following command to download knight.c to your GL account, and be sure to rename it to campusid_knight.c before submitting.

    curl -O

  3. (10 points EXTRA CREDIT) Make a copy of your campusid_airline.c called campusid_airline_enhanced.c and update it so that the agent is prompted to enter the passenger's name after it has been verified that a seat is available. Then print the passenger name on the boarding pass, centered below the seat number.

    • The maximum length of the passenger name should be 26 characters.
    • You do not need to implement error checking to verify the name is less than 26 characters.
    • You do not need to save the passenger's name after it has been printed.
    • Aside from prompting for (and printing) the passenger name, your campusid_airline_enhanced.c should work EXACTLY the same as your campusid_airline.c.

    Your boarding pass should look exactly like this:
    **       UMBC Airlines        **
    **        First Class         **
    **          Seat 3            **
    **  William Henry Gates III   **

When you have finished, submit your campusid_airline.c and campusid_knight.c files using the following commands:

curl -L -F file=@campusid_airline.c

curl -L -F file=@campusid_knight.c

curl -L -F file=@campusid_airline_enhanced.c

Additionally, email your campusid_airline.c, campusid_knight.c, and (optionally) campusid_airline_enhanced.c files as an attachment to using the subject line Project Submission - 8 - Lastname, Firstname, replacing Lastname, Firstname with your name.

Last Modified: December 1st, 2016 6:52 PM