This is an individual activity. You do not
create a lab notebook entry for this lab.
Note to returning students: If
you previously completed this lab
then do Ch
Hwk Set 2 #1 and Supplemental
Problem #2 .
Use "handin" and name the programs lab6A.c and lab6B.c.
A car and a train are both travelling toward a railroad crossing on a collision course. The train is 1200 feet from the crossing and traveling at a constant speed of 40 feet per second. The car is 1500 feet away and travelling at 55 feet per second. Write a program named car_train_1.c to calculate and print each vehicles distance from the crossing at one second intervals. (Don't use the "formula" for distance; instead, substract the distance travelled in one second each time through the loop). If the car gets to the crossing first, print "Made it." If the train gets to the crossing first, print "Crash". (If they arrive at the same time, it's a crash). The initial distances and speeds may be "hard coded" in the program. The results will appear something like this:
1 1445 1160
2 1390 1120
3 1335 1080
4 1280 1040
Be sure to display the distances until
one of the distances is less than or equal to zero.
Write another program, car_train_2.c that is a modification of the previous program so that it prints a table of results for car speeds from 10 to 1000 feet per second, at increments of 10. You should write another loop that surrounds the loop you wrote for part 1.
The results will appear something like
980 Made it
990 Made it
1000 Made it
If you have time, decompose your solution so that the loop you
created in part 1 is in a function. You have to decide what
would be the appropriate parameters to this
1. Handin the source code files car_train_1.c and car_train_2.c as you’ve done for previous labs
handin graderjd Lab06 car_train_1.c car_train_2.c