ECS 30-B

Homework #2

Winter 2009

Due: Monday, January 19th. 

 

Programs: 11:59pm using handin to cs30b, p1 directory.

Other filenames: reimbursement.c, f2c.c, score.c, grass.c, fraction.c, triple.c, jet.c

 

Programming, (pp. 90-93). All programs should be able to compile with no warnings, e.g. gcc –Wall reimbursement.c –o reimbursement.out.  You should put your name  in a comment on the first line of each file.  The prompts and output format of each program must match the following outputs exactly. 10 points each problem except 11 points for #4, and  13 points for #11, for a total 80 points.

 

#1.  Filename: reimbursement.c

You should use a #define to store the $.35 rate in a constant.  However, there is no simple way to print the rate as “$.35” , so do not try to use “%lf” with the constant—just printf  “$.35”  literally.

 

[@pc…]$ reimbursement.out

MILEAGE REIMBURSEMENT CALCULATOR

Enter beginning odometer reading > 13505.2

Enter ending odometer reading > 13810.6

 

You traveled 305.4 miles. At $.35 per mile,

Your reimbursement is $106.89.

[@pc…]$

 

#4.  Except, do it the other way: convert Centigrade to Fahrenheit Filename: f2c.c   (CAREFUL!!)

 

[@pc…]$ f2c.out

Please enter Centigrade tempature > 100.0

     (9/5)*100.0 + 32  = 212.0 Fahrenheit

[@pc…]$

 

#6 Filename: score.c

 

[@pc…]$ score.out

Enter desired grade > B

Enter minimum average required > 79.5

Enter current average in course > 74.6

Enter how much the final counts

as a percentage of the course grade > 25

 

You need a score of 94.20 on the final to get a B.

[@pc…]$

 

#9. Filename: grass.c (the numbers are integers)

 

[@pc…]$ grass.out

Please enter the length and width of the yard > 100 95  

Please enter the length and width of the house > 45 38

7790 square feet will take 64 minutes and 55 seconds to cut.

[@pc…]$



 

#11 Filename: fraction.c (input numbers should be integers) and also (in addition) compute the result as a floating point.
       CAREFUL!!


          

[@pc…]$ fraction.out

Please enter two numerators > 3  3

Please enter two denominators > 4 5

The numerator of the sum is 27 and the denominator is 20.
The resulting quotient value is 1.35

    [@pc…]$

 

#12. Filename: triple.c (the numbers are integers)

 

[@pc…]$ triple.out

Please enter two integers with the first larger than the second > 15 9

The Pythagorean triple of 15 and 9 is 144, 270, and 306.

[@pc…]$

 

#13. Filename: jet.c

 

[@pc…]$ jet.out

Please enter the takeoff speed of the jet in km/hr > 278

Please enter the catapult distance in meters > 94

The jet would accelerate at 31.72 m/s^2 for 2.43 seconds.

[@pc…]$