The program addtime.cpp is supposed to add two time values (minutes and seconds) and output the result in hours, minutes, and seconds. However, the program has both syntax errors (found by the compiler) and logic errors (not found by the compiler). When you open the file in your editor, fill in your name and date in the comment section at the top of the program in the space provided (put this information at the top of every program you write).
Frist try to compile this program. It should not compile because it has some syntax errors. You should correct all syntax errors before continuing to the next part. But be careful of cascading errors! Often times, the first syntax error in your program causes other spurious syntax errors. To avoid this trap, practice fixing one error at a time (i.e., fixing the first syntax error, then recompiling the program, etc.).
The first step to finding logic errors is to write test cases to verify that your program behaves like you think it should. For this program, and all future assignments, you will be asked to turn in tests that verify your program works. To test your program, you should think of (but not simply enter) all the possible different data your program may encounter. To create tests for your program, you should group similar data into a single test case, and pick a candidate data value that represents that test case. For this program, the following cases are suggested:
| both times are zero minutes and zero seconds (empty case) | |
| the two times' minutes added together sum to less than one hour (standard case) | |
| the two times' minutes added together sum to more than one hour (overflow case) | |
| the two times' minutes added together sum to exactly one hour (boundary case) | |
| the two times' seconds added together sum to less than one minute (standard case) | |
| the two times' seconds added together sum to more than one minute (overflow case) | |
| the two times' seconds added together sum to exactly one minute (boundary case) |
You should make a separate call to addTime in the function testAddTime for each test case (the first one is done for you). Additionally, you should print out the time value you expect to result from adding your two values. To better help you discover the logic error, you should try to identify what part of the code corresponds to each test case.
At this point, you should know which case causes the incorrect output from your program. You should now fix the logic error before continuing. To fix the error, do not rewrite the program, but rather make as few changes as possible to correct the program.
Once you have completed and tested all three functions, discuss their
similarities and differences in your README file. From your observations,
can you write a single function that handles all three cases? Why
or why not?
![]()