Week 2 Exercises

  1. Sales tax in New York City is 8.25%. Write a program that accepts a price on the command line and prints out the appropriate tax and total purchase price.
  2. Modify the sales tax program to accept an arbitrary number of prices, total them, calculate the sales tax and print the total amount.
  3. Write a program that reads two numbers from the command line, the number of hours worked by an employee and their base pay rate. Then output the total pay due.
  4. Modify the previous program to meet the U.S. Dept. of Labor's requirement for time and a half pay for hours over forty worked in a given week.
  5. Add warning messages to the payroll program if the pay rate is less than the minimum wage ($5.15 an hour as of 1998) or if the employee worked more than the number of hours in a week.
  6. Write a program that reads an integer n from the command line and calculates n! (n factorial).
  7. There are exactly 2.54 centimeters to an inch. Write a program that takes a number of inches from the command line and converts it to centimeters.
  8. Write the inverse program that reads a number of centimeters from the command line and converts it to inches.
  9. There are 454 grams in a pound and 1000 grams in a kilogram. Write programs that convert pounds to kilograms and kilograms to pounds. Read the number to be converted from the command line. Can you make this one program instead of two?
  10. The equivalent resistance of resistors connected in series is calculated by adding the resistances of the individual resistors. Write a program that accepts a series of resistances from the command line and outputs the equivalent resistance.
  11. The formula for resistors connected in parallel is a little more complex. Given two resistors with resistances R1 and R2 connected in parallel the equivalent resistance is given by the inverse of the sum of the inverses, i.e.

                 1
    Requiv =  --------
               1    1
              --  + --
              R1    R2
    

    If there are more than two resistors you continue to invert the sum of their inverses; e.g. for four resistors you have:

                      1
    Requiv =  ------------------
               1    1     1    1
              --  + -- + -- + --
              R1    R2   R3   R4
    

    Write a program that calculates the resistance of a a group of resistors arranged in parallel. The resistances will all be passed as command line arguments.


Start | Previous | Cafe au Lait

Copyright 1997-8, 2005 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified June 8, 2005