diff options
Diffstat (limited to 'CST116-Ch7-Debugging')
| -rw-r--r-- | CST116-Ch7-Debugging/CST116-Ch7-Debugging-Batbold.txt | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Batbold.txt b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Batbold.txt new file mode 100644 index 0000000..3cd764a --- /dev/null +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Batbold.txt @@ -0,0 +1,84 @@ +/******************************************************************** +* File: CST116-Ch7-Debugging.cpp +* +* General Instructions: Complete each step before proceeding to the +* next. +* +* Debugging Exercise 1 +* +* 1) Insert a breakpoint on the lines indicated in the code. Done +* 2) Run to Breakpoint 1. Done +* 3) When prompted, enter your age. Done +* 4) When the execution stops, add a watch on age and verify that Done +* the value in age is what you typed in. Yes. It is correct. +* 5) Step over the if statement. Done +* 6) Why did the value in age change? No. It should not change. +* +* 7) Fix the problem and repeat Steps 2 � 5 to verify the +* problem was corrected. Problem solved and commented at the spot +* 8) Stop debugging. Done +* +* Debugging Exercise 2 +* +* 1) Run to Breakpoint 1. Done +* 2) When prompted, enter the value 25 for your age. Done +* 3) Step over the if statement. Execution of the program should +* continue on the else if statement. Yes. It does. +* 4) Verify that 25 is still stored in age. Yes. It is stored +* 5) Step over the else if. Done +* 6) Why is the program going to print "Teenager" for an age of 25? Because it used OR instead of AND. +* The both of conditions should be satisfied. +* So, I changed || into &&. +* 7) Fix the problem and repeat Steps 1 � 5 to verify the Done +* problem was corrected. +* 8) Stop debugging. Done +* 9) Remove Breakpoint1. Done +* +* Debugging Exercise 3 +* +* 1) Run the program without debugging. Yes, I did +* 2) When prompted, enter the value of 10 for your age. Yes, I did +* 3) Why does the program print both "Child" and "Adult"? Because of ; after else +* 4) Re-run the program this time with debugging and run to +* Breakpoint 2. Done +* 5) Why is the action with the else executing? ; means the end of the line and it stops right there. +* +* 6) Fix the problem and re-run to verify the problem was corrected. Done +*/ + +#include <iostream> + +using std::cout; +using std::endl; +using std::cin; + +int main() { + + int age = 0; + + cout << "Enter your age: " <<endl; + cin >> age; + + // Breakpoint 1 + // Put a breakpoint on the following line + if (age == 1) // In C++, == means equal, so I corrected it. + cout << "First Birthday" << endl; + else if (age >= 12 && age <= 19) // && should be used here not || + cout << "Teenager" << endl; + else if (age < 12 && age > 1) + cout << "Child" << endl; + else if (age >= 62 ) + cout << "Senior" << endl; + // Breakpoint 2 + // Put a breakpoint on the following line + else + cout << "Adult" << endl; + + return 0; + } + + + + + + |