CS117 Debugging Assignment

Fall 1999

Goal

Below is the design for a programming problem. On the pages following is a solution to the problem, written in the language you are learning. Unfortunately, the solution has a major bug in it. Your task is to find the bug, using the methods outlined in class, and fix it in the simplest way you can.

Deliverables

    1. Printouts of testing you did to locate the bug. You should annotate these with to show how you found the bug, and include any extra code (assertions, trace statements, testing code) that you may have written.
    2. A printout of your fix to the code that removes the bug. Insert comments or annotate the listing to show what you did.
    3. A printout of a typical case test showing that the bug has been removed.

Source code

You will need to compile and run the attached program.

You can download it by shift-clicking here: C, C++, Fortran, Java.

Problem statement:

Fit tracks on a CD to minimize the wasted space.

Problem description:

Read track times in mins:secs from a file. Allocate tracks on a CD by track number to minimize the wasted space. The total time available is 74 mins. Print out the tracks by number with their time on the screen. Print the total time used on the screen. If all the tracks can be allocated, print a warning message on the screen that not all the space has been used.

TDSR (for C and Fortran)

(see handout)

Object analysis (for C++)

Read track times in mins:secs from a file. Allocate tracks on a CD by track number to minimize the wasted space. The total time available is 74 mins. Print out the tracks by number with their time on the screen. Print the total time used on the screen. If all the tracks can be allocated, print a warning message on the screen that not all the space has been used.

track HAS-A time

track HAS-A number

CD HAS-A sequence of track

CD HAS-A timeAvailable

CD HAS-A timeUsed

Track

int time

unsigned int number

CD

Track track[]

int timeAvailable

int timeUsed

Method Analysis

Read track times in mins:secs from a file. Allocate tracks on a CD by track number to minimize the wasted space. The total time available is 74 mins. Print out the tracks by number with their time on the screen. Print the total time used on the screen. If all the tracks can be allocated, print a warning message on the screen that not all the space has been used.

TrackAllocator

CD cd

run()

CD

Track track[]

int timeAvailable

int timeUsed

allocate()

printTracks()

printTime()

printNotAllUsed()