ECS 30-A

Homework #2

Fall 2008

Due: Monday, October 13. 

Written: 4:00pm in 2131 Kemper. 

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

Filenames: reimbursement.c, numbers.c, score.c, grass.c, triple.c, jet.c

 

Written:  #2 on page 89,   #4, #5, #7 on page 90.

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. 

 

#1.  Filename: reimbursement.c

You should use a macro 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…]$

 

#5.  Filename: numbers.c

 

[@pc…]$ numbers.out

Please enter two numbers> 86.3 1348.9874

86.300000 + 1348.987400 = 1435.287400

86.3 - 1348.99 = -1262.687

86.30 * 1348.99 = 116417.61

86.300000 / 1348.987400 = 0.0640

[@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…]$

 

 

#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…]$