Homework 2: Ticket Pricing

Assigned
  • January 31, 2024
Due
  • February 5, 2024 11:59pm
Collaboration
    Regular policies for collaboration apply to this homework assignment. Make sure you review and understand the policies on the syllabus before you discuss your work on this assignment with anyone else.

You’ve been asked by a local community theater to write a small program to calculate the price of a ticket for the box office staff. The problem is that the price of a ticket depends upon several factors:

  • The seat location in the theater (main floor middle section, main floor sides, or balcony)
  • Age of the ticket holder
  • Time of show (matinees are less expensive than evening shows)

The price schedule for tickets is:

Location Matinee Evening
Main floor - middle section $25.00 $30.00
Main floor - sides $20.00 $25.00
Balcony $15.00 $20.00

Valid ages for ticket holders are between 0 and 150 (inclusive). Tickets for children 5 and under are free regardless of time and location. Children between 6 and 10, inclusive, and senior citizens (age 55 and older) receive a \$5.00 discount.

Requirements

Your program should implement the following behaviors:

  1. Ask the user how many tickets they intend to purchase.
  2. Ask the user for the information required to calculate the price of that ticket.
  3. Print the user-provided information collected in step 2, as well as the calculated ticket price. If there are additional tickets to purchase, go to step 2. Please print the options the user selected, not just the number they typed to select each one.
  4. Once all ticket prices have been calculated, print the total price for the order.

All prices should be printed with a dollar sign before the number, using two decimal places just as the numbers in the table above.

Handling Inputs

When you present users with a choice of several options, print them with numbers and ask them to type the number corresponding to the option they want. We will explore alternative ways to collect input from users later in the semester.

Your program must check the validity of all inputs; an age that is less than zero or greater than 150 should be rejected, as should any attempt to select an option that does not exist. When a user provides an invalid input, print a message to report that the input was invalid (include an explanation of why) and ask them to try again. We haven’t yet looked at how we can read non-numeric data, so you may assume users will always type a number when you ask them to. Just don’t assume the number will be acceptable without checking it first.

What to Submit

You will submit your work for this homework assignment on gradescope. Please upload your implementation in a file named boxoffice.c, along with a testing transcript. You can create a testing transcript by running:

$ script tests.txt

The command above will record the commands you run and any outputs to a file named tests.txt. Run the program as many times as you need to thoroughly test your implementation, then run exit to end the transcript. Include tests.txt with your implementation when you submit your work to gradescope.

You should make sure your testing covers at least the following cases:

  • Valid inputs for several combinations of time, location, and age group
  • Ages that fall precisely on the age group dividing points (5, 10, 55) and at the edge of the valid range.
  • Ages less than zero
  • Ages greater than 150
  • Invalid selections for time (e.g. option N when fewer than N options are presented)
  • Invalid selections for location

It is in your interest to be thorough with your testing. Your tests must cover these cases to receive credit for the testing portion of your grade, but testing your code will help you find bugs that might otherwise have hurt your score in other parts of the assignment.

Grading

Your assignment will be graded on a scale of 0–100 points based on the following criteria:

  • Correct computation of ticket prices adults in all time and location combinations (25 points)
  • Correct computation of free tickets for five and under (10 points)
  • Correct computation of discounted ticket prices 6–10 and 55+ (10 points)
  • Testing transcript that covers at least the cases listed above (30 points)
  • Helpful prompts and feedback for users, especially when they provide invalid inputs (25 points)

There will be potential deductions for any code quality violations. For now, there are six requirements for quality code:

  1. Indent the body of all loops and conditionals one level deeper than the code just outside the loop. Be consistent with your indentation style.
  2. Use curly braces for every loop or conditional body, regardless of the number of lines.
  3. Include comments that explain what your code does. There should be at least one comment by the start of each loop and ifelse block that explains what the purpose of that code is. The comment should not simply restate the code; it should add information for a human who reads the code and is confused.
  4. Give variables descriptive names that help a reader understand what they will be used for.
  5. Do not read from or display the value of any variable without first initializing it.
  6. Your code must compile with no errors and no warnings.