From 1ff428c375db9a43cbeb8fac663e28c5341bc70a Mon Sep 17 00:00:00 2001 From: Musa Ahmed Date: Wed, 12 Oct 2022 11:29:42 -0700 Subject: Answered questions & added text file --- .../CST116-Ch7-Debugging-Ahmed.cpp | 83 ++++++++++++++++++++++ .../CST116-Ch7-Debugging-Ahmed.txt | 24 +++++++ CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp | 73 ------------------- CST116-Ch7-Debugging/CST116-Ch7-Debugging.vcxproj | 5 +- .../CST116-Ch7-Debugging.vcxproj.filters | 7 +- 5 files changed, 117 insertions(+), 75 deletions(-) create mode 100644 CST116-Ch7-Debugging/CST116-Ch7-Debugging-Ahmed.cpp create mode 100644 CST116-Ch7-Debugging/CST116-Ch7-Debugging-Ahmed.txt delete mode 100644 CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp (limited to 'CST116-Ch7-Debugging') diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Ahmed.cpp b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Ahmed.cpp new file mode 100644 index 0000000..9563dba --- /dev/null +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Ahmed.cpp @@ -0,0 +1,83 @@ +/******************************************************************** +* 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. +* 2) Run to Breakpoint 1. +* 3) When prompted, enter your age. +* 4) When the execution stops, add a watch on age and verify that +* the value in age is what you typed in. +* 5) Step over the if statement. +* 6) Why did the value in age change? +* In the if statement, the conditional was written as "age = 0" +* instead of "age == 1", thus the age is set to 1 everytime. +* 7) Fix the problem and repeat Steps 2 – 5 to verify the +* problem was corrected. +* 8) Stop debugging. +* +* Debugging Exercise 2 +* +* 1) Run to Breakpoint 1. +* 2) When prompted, enter the value 25 for your age. +* 3) Step over the if statement. Execution of the program should +* continue on the else if statement. +* 4) Verify that 25 is still stored in age. +* 5) Step over the else if. +* 6) Why is the program going to print "Teenager" for an age of 25? +* The else if statement was checking if the age was greater than +* or equal to 12 OR less than or equal to 19. Instead it should be +* checking if the age is between 12 AND 19 inclusively. +* 7) Fix the problem and repeat Steps 1 – 5 to verify the +* problem was corrected. +* 8) Stop debugging. +* 9) Remove Breakpoint1. +* +* Debugging Exercise 3 +* +* 1) Run the program without debugging. +* 2) When prompted, enter the value of 10 for your age. +* 3) Why does the program print both "Child" and "Adult"? +* There is a cout statement at the end of all the else if statements +* which is executing every time main is run. +* 4) Re-run the program this time with debugging and run to +* Breakpoint 2. +* 5) Why is the action with the else executing? +* The else statement has a semicolon at the end of it, so the statement +* is not included in the else statement and runs regardless of any conditions. +* Everytime main is executed, it will print adult at the end. +* 6) Fix the problem and re-run to verify the problem was corrected. +********************************************************************/ + +#include +using std::cout; +using std::endl; +using std::cin; + +int main() +{ + int age = 0; + + cout << "Enter your age: "; + cin >> age; + + // Breakpoint 1 + // Put a breakpoint on the following line + if (age == 1) + cout << "First Birthday" << endl; + else if (age >= 12 && age <= 19) + cout << "Teenager" << endl; + else if (age < 12) + 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; +} \ No newline at end of file diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Ahmed.txt b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Ahmed.txt new file mode 100644 index 0000000..94266c1 --- /dev/null +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Ahmed.txt @@ -0,0 +1,24 @@ +FOR CHILD : + + Enter your age: 10 +Child + +C:\Users\macho\Source\Repos\cst116-ch7-debugging-M005A\CST116-Ch7-Debugging\x64\Debug\CST116-Ch7-Debugging.exe (process 18964) exited with code 0. + +FOR TEENAGER : +Enter your age: 15 +Teenager + +C:\Users\macho\Source\Repos\cst116-ch7-debugging-M005A\CST116-Ch7-Debugging\x64\Debug\CST116-Ch7-Debugging.exe (process 18828) exited with code 0. + +FOR ADULT : +Enter your age: 55 +Adult + +C:\Users\macho\Source\Repos\cst116-ch7-debugging-M005A\CST116-Ch7-Debugging\x64\Debug\CST116-Ch7-Debugging.exe (process 14928) exited with code 0. + +FOR SENIOR : +Enter your age: 65 +Senior + +C:\Users\macho\Source\Repos\cst116-ch7-debugging-M005A\CST116-Ch7-Debugging\x64\Debug\CST116-Ch7-Debugging.exe (process 5912) exited with code 0. \ No newline at end of file diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp deleted file mode 100644 index f64adfe..0000000 --- a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************** -* 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. -* 2) Run to Breakpoint 1. -* 3) When prompted, enter your age. -* 4) When the execution stops, add a watch on age and verify that -* the value in age is what you typed in. -* 5) Step over the if statement. -* 6) Why did the value in age change? -* 7) Fix the problem and repeat Steps 2 – 5 to verify the -* problem was corrected. -* 8) Stop debugging. -* -* Debugging Exercise 2 -* -* 1) Run to Breakpoint 1. -* 2) When prompted, enter the value 25 for your age. -* 3) Step over the if statement. Execution of the program should -* continue on the else if statement. -* 4) Verify that 25 is still stored in age. -* 5) Step over the else if. -* 6) Why is the program going to print "Teenager" for an age of 25? -* 7) Fix the problem and repeat Steps 1 – 5 to verify the -* problem was corrected. -* 8) Stop debugging. -* 9) Remove Breakpoint1. -* -* Debugging Exercise 3 -* -* 1) Run the program without debugging. -* 2) When prompted, enter the value of 10 for your age. -* 3) Why does the program print both "Child" and "Adult"? -* 4) Re-run the program this time with debugging and run to -* Breakpoint 2. -* 5) Why is the action with the else executing? -* 6) Fix the problem and re-run to verify the problem was corrected. -********************************************************************/ - -#include -using std::cout; -using std::endl; -using std::cin; - -int main() -{ - int age = 0; - - cout << "Enter your age: "; - cin >> age; - - // Breakpoint 1 - // Put a breakpoint on the following line - if (age = 1) - cout << "First Birthday" << endl; - else if (age >= 12 || age <= 19) - cout << "Teenager" << endl; - else if (age < 12) - 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; -} \ No newline at end of file diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.vcxproj b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.vcxproj index 45b2819..f9cc4e8 100644 --- a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.vcxproj +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.vcxproj @@ -127,7 +127,10 @@ - + + + + diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.vcxproj.filters b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.vcxproj.filters index a245946..6d3c958 100644 --- a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.vcxproj.filters +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.vcxproj.filters @@ -15,8 +15,13 @@ - + Source Files + + + Source Files + + \ No newline at end of file -- cgit v1.2.3