Starting from:
$30

$24

Homework/Lab #1 Solution




Question #1




The goal of this lab is to get familiar with the process of building a program, as well as learning how to read input from a keyboard, compute a simple result and display this result on the screen.




You are asked to write a program that computes the braking distance for a car. It will prompt for a speed (in kilometers per hour) and will display the braking distance (in meters), under “normal” circumstances (dry road, and alert driver).




The braking distance is composed of two parts, which have to be summed up:




-­‐ How long it takes for a conductor to react (a signal is transmitted from the

eyes to the brain, the brain processes is, and sends to the foot the order to




press the brake pedal). This takes on average 1s (it can be less, but can

also take much longer for somebody who is tired, distracted – talking on a




cell-­‐phone -­‐ or intoxicated). During this second, the car travels a distance.




-­‐ How long it takes for the brakes, once in action, to stop the car, or in other

words to dissipate the kinetic energy of the car. The formula for this




second part is the square of the speed divided by 2gμ, where g is the




gravity of Earth (you’ll use 9,8m per s2), and μ is the coefficient of friction

between the road and the tires. A commonly used value for μ is 0.7 (if you




are interested by the derivation of the formula, check Wikipedia).




On a wet road, friction diminishes strongly and the distance to stop the car is usually multiplied by 1.5.







Sample input and output




Input the speed: 50




<speed in 50.00km/h <b.d.=34.98m on wet road <b.d=27.95m on dry road

Question2




You are going to modify in this lab the program written in lab1 to make it generate tables showing the braking distance for different distances and road conditions. Generating tables mean repeating something for each line and this will be our first program with a loop.




We have used in lab1 a coefficient of friction μ between the road and the tires and we have used value 0.7, which is for a dry road. For a wet road, a more correct coefficient would be 0.4.




Your program will ask for a “start speed”, and for a “top speed”, and will generate a table in which you will display on each row (b.d. stands for “braking distance”)




<speed in km/h <b.d. on wet road <b.d on dry road




Speeds will go from the “start speed” to the “top speed” with a 5km/h increment between two successive rows. If the start speed is NOT a multiple of 5, you will start from the multiple of 5 immediately inferior to the start speed entered. If the top speed is NOT a multiple of 5, the last row will contain the smallest multiple of 5 greater than the top speed that was provided.




Sample input and output




Input the
start speed: 13
Input the
top speed: 23
<speed in
10km/h
<b.d.=3.76m on wet road <b.d=3.34m on dry road
<speed in
15km/h
<b.d.=6.38m on wet road <b.d=5.43m on dry road
<speed in
20km/h
<b.d.=9.49m on wet road <b.d=7.81m on dry road
<speed in
25km/h
<b.d.=13.10m on wet road <b.d=10.46m on dry road





More products