Introduction to Computer Science
CompSci 101 : Spring 2014

Problem Solving

Work in teams to write an algorithm, in English, for the following problems. Then, together, write a program to implement your algorithm.

  1. Adding Time

    Consider the problem of adding units of measure together (like minutes and seconds). When you add the smaller units, e.g., seconds, they may "overrun" into the larger unit, e.g., minutes, you must update the larger unit and remove its value from the seconds total. For example, adding 20 seconds to 30 seconds results in 50 total seconds. But adding 20 seconds to 50 seconds, results in 1 minute and 10 seconds.

    1. Write a program to add time, i.e., adds together minutes and seconds and outputs the result in hours, minutes, and seconds
    2. What cases might you try to determine if your program works?
    3. Change your program to add distances, i.e., adds together feet and inches and outputs the result in miles, feet, and inches
    4. Change your program to add money, i.e., adds together English shillings and pence and outputs the result in pounds, shillings, and pence
    5. Write a general Python method to add any two units together

       

  2. Pricing the Movies

    Consider the problem facing the owner of a movie theater who has complete freedom in setting ticket prices. The more he charges, the fewer the people who can afford tickets. In a recent experiment the owner determined a precise relationship between the price of a ticket and average attendance. At a price of $5.00 per ticket, 120 people attend a performance. Decreasing the price by a dime ($.10) increases attendance by 15. Unfortunately, the increased attendance also comes at an increased cost. Every performance costs the owner $180. Each attendee costs another four cents ($0.04). The owner would like to know the exact relationship between profit and ticket price so that he can determine the price at which he can make the highest profit.

    1. Describe an algorithm that computes the theater's profit based on a given ticket price.
    2. Choose several reasonable values to test which one might yeild the most profit.
    3. Choose several reasonable values to test which one might yeild no profit.
    4. Describe an algorithm to find which ticket price would yeild the most profit.