IC210 Debug Lab

Pre-lab homework: none

Overview: In this lab, we will primarily practice how to fix (or debug) programs that are not working. Everyone makes mistakes when they write programs, so learning how to fix things is one of the most important things you can do!

Instructions

Below are a number of programs that do NOT work correctly. For EACH program, do the following:

  1. Copy and paste the program into a file.
  2. Compile and run the program (use sample input provided in the screenshot, if present).
  3. Compare the results you get to the provided screenshot or description of the correct behavior.
  4. Fix the program. We especially encourage you to use cout statements to (a) establish which parts of the code are actually executing and (b) to output the values of different variables while the program is running. Ask for help if you don't understand how to do this, or get stuck on a program.
  5. NOTE: many of these programs you have seen before. However, do NOT try to find solutions for them in the class notes -- the whole point is to practice debugging a program using cout and/or by inspecting the program.
  6. When the program works, take a screenshot, select "Copy to Clipboard", and paste the screenshot into a document (use Applications->Office->Word Processor to start a new document). You should paste all of your working screenshots into a single document.
  7. When all finished or time runs out, ask your instructor how to demonstrate your progress.

Programs to Fix

  1. Evaluating a polynomial: eval_poly.cpp. Screenshot of correct output.
  2. This program to calculate interest rates only works properly on every other year. Why?
  3. A previous year's homework assignments had the students write a loan calculator. This student's solution to the problem appears to work, but gives different answers than the instructor's screenshot -- what is wrong?
  4. Computing average and minimum: compute_avg.cpp. Screenshot of correct output.
  5. A solution to a mini-practicum that doesn't quite work: minipract.cpp. Screenshot of correct output.
  6. This program is supposed to report when two vectors are perpendicular. But, it always reports the vectors as not perpendicular regardless of the vectors input. For example, try (3, 0) and (3, 90). Why? (FIRST try using cout to see what is happening -- take a look at what values get computed! If you are still stuck, review the notes for Class 13. If you are still stuck after a few minutes, ask for help rather than taking too long on this one.)
  7. Checking uppercase/lowercase/neither: check_char.cpp. Screenshot of correct output. NOTE: you need to try other inputs to see the problem here. For instance, try entering an asterisk.
  8. Summing integers from standard input (console input): sum_ints.cpp. Screenshot of correct output.
  9. Multiplying integers from standard input: mult_nums.cpp. Screenshot of correct output.
  10. For the following programs, you will need to download 24md.txt and save it in the same directory as your files.
  11. Hankel matrix: hankel.cpp. Screenshot of correct output.
  12. Add up 5 numbers: sum_ints2.cpp. Screenshot of correct output.
  13. (For this program you need this data file: grades1-input.txt). Finding the student with the highest grade: grades.cpp. Screenshot of correct output.

More Programs

If time permits, work on this:

Valid XHTML 1.1! This page last modified