CS 157 Spring 2001                       Assignment 9 – Debugging using the Microsoft Debugger                              50 points

 

Assigned: 03/28/2001

Due: 04/04/2001 at the start of class

 

Pre-Lab (Do Before Lab): Try to understand what the program being debugged is supposed to do (study this handout)

 

Main Assignment:

                There is a buggy version of a program described below, named cs157a9wrong.c, available on my WWW page. Copy it to your  hard disk, and create a project for it (do not save space by not generating Debug Info – we need that!). Compile it and try it out. This version has one or more bugs.

1)       Use the Microsoft debugger to track down the bug(s), by stepping and displaying values for variables. Don’t find bugs in other ways, you want to learn how to use the debugger.

2)       Hand in or e-mail me (redmond@lasalle.edu):  a) a clear complete description of what the bug(s) are. Do not send me a fixed version of the program and b) what were the values of the variables: i) fine immediately before returning from calcFine for the first time, ii) miles when printing the bill the first time, iii) totalFines the first time the program reaches line 188, and  iv) numSpeeding the first time the program reaches line 195.

3)       Note that everything below was taken from a description of a task for a previous class. It is not your task. Your task is to use the debugger to find the problem(s)!! The skills learned here can also be useful for debugging your own programs.

 

The Description of What the Program Was Supposed to Do:

The PA State Police are working on a new program in conjunction with the EZ Pass system. This program is a simplification. It should ask the user how many cars will be processed in a batch. Then, for each car, the program should ask the user for the number of minutes spent on the turnpike and the number of miles traveled, and the speed limit on the stretch of turnpike traveled - see below (in real life these would be obtained via the scanning process)). The program should then calculate the miles/hour  (mph) and display the speed. The program should then call a function to calculate the fine (see details below). If the person is to be fined, the program should display a bill for the person (see below). After processing all of the cars in the batch, the program should display a report including how many cars were speeding, the percent of cars speeding, the total fines charged, and averages (details below).

 

Details:

   1) The schedule for fines is as follows:

        On or under speed limit - no fine

        - less than or equal to 5 mph over the limit - $20 fine

        - more than 5 mph and less than or equal to 10 mph over the speed limit -

              fine is $20 plus $2 for each mph over the speed limit.

        - more than 10 mph and less than or equal to 20 mph over the speed limit -

              fine is $20 plus $4 for each mph over the speed limit.

        - more than 20 mph over the speed limit -

              fine is $50 plus $5 for each mph over the speed limit.

   2) Details of what the program should present in the bill and the final report are shown in the example below.

   3) The program should ensure that the user types in valid data (i.e. positive number of cars, minutes, and miles, speed limit no lower than 35, and no higher than 65). Loop to ensure they cannot in any circumstances get invalid data into your calculations.

 

Sample interaction with the user:

 

How many cars will be logged in this batch? 3

Car  1

Time on Turnpike (in minutes): 23.0

Miles on Turnpike: 34.0

Speed Limit on Turnpike: 65

 

Speed:  88.7

 

===========================< CUT HERE>============================

                               Bill

 

   You traveled   34.0 miles in   23.0 minutes

      - an average speed of  88.7 miles per hour

   This compares to a speed limit of 65

   The fine of  168.48 has been charged to your account

 

===========================< CUT HERE >===========================

 

Car  2

Time on Turnpike (in minutes): 0

Please enter a positive number of minutes: 0

Please enter a positive number of minutes: 60

Miles on Turnpike: 63

Speed Limit on Turnpike: 55

 

Speed:  63.0

 

===========================< CUT HERE >===========================

                               Bill

 

   You traveled   63.0 miles in   60.0 minutes

      - an average speed of  63.0 miles per hour

   This compares to a speed limit of 55

   The fine of   36.00 has been charged to your account

 

===========================< CUT HERE >===========================

 

Car  3

Time on Turnpike (in minutes): 115.0

Miles on Turnpike: 122.6

Speed Limit on Turnpike: 25

Please enter a speed limit between 35 and 65: 75

Please enter a speed limit between 35 and 65: 65

 

Speed:  64.0

 

 

                     Final Report

                     ------------

 

 In a batch of  3 cars  2 were speeding

 This represents  66.67 percent of cars

 

 The total fines charged were   204.48

 This represents an average per speeding car of 102.24

 OR an average for all cars of  68.16

 

 The average speed of all cars was  71.89  miles per hour

 

Goodbye