Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [30pts] Complete the program p1.cpp by writing the "main()" function, so that the program operates as shown below. You can use the function lenUnitCF(fromUnit, toUnit) I've already defined, which will be useful!
    Example Runs of the Program: (user input in red!)
    ~/$ ./p1
    convert to kilometers 45 miles + 3987 feet ;
    73.6357 kilometers
    ~/$ ./p1 
    convert to inches 2354 millimeters + 0.00022 nautical-miles ;
    108.718 inches
    ~/$ ./p1 
    convert to nautical-miles 2 miles + 2 kilometers ;
    2.81786 nautical-miles
    ~/$ ./p1 
    convert to light-years 1234 miles + 5678 kilometers ;
    8.10095e-10 light-years
  2. [30pts] Complete the program p2.cpp by writing the prototype and definition for the "harm(n)" function which computes the sum of the first n terms in the harmonic series, i.e. it computes 1/1 + 1/2 + 1/3 + 1/4 + ... + 1/n.
    Example Runs of the Program: (user input in red!)
    ~/$ ./p2
    Enter x: 2.5
    the 7th harmonic number is 2.59286, which is the first greater than 2.5
    ~/$ ./p2 
    Enter x: 3.25
    the 14th harmonic number is 3.25156, which is the first greater than 3.25
    ~/$ ./p2 
    Enter x: 3.5
    the 19th harmonic number is 3.54774, which is the first greater than 3.5
    ~/$ ./p2 
    Enter x: 9.75
    the 9631th harmonic number is 9.75001, which is the first greater than 9.75
  3. [40pts] Program p3.cpp is a complete functioning program. Here it is in action:
    ~/$ ./p3
    Enter first time: 3:12:42
    Enter second time: 4:06:19
    Ellapsed time is 3217 seconds
    This program uses no functions. Pull out repeated code into a a function in order to simplify the program. The new program needs to give the same results as before!