From 88ef655a6ef739795664b9be1d80e631da185335 Mon Sep 17 00:00:00 2001 From: CEOofOogaBooga Date: Tue, 18 Oct 2022 21:39:53 -0700 Subject: Chp9 Finished --- CST116-Ch9-Debugging/CST116 Output Ch9.txt | 7 +++++++ CST116-Ch9-Debugging/CST116 Pseudo Code Ch9.txt | 20 ++++++++++++++++++++ CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp | 16 ++++++++++++---- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 CST116-Ch9-Debugging/CST116 Output Ch9.txt create mode 100644 CST116-Ch9-Debugging/CST116 Pseudo Code Ch9.txt diff --git a/CST116-Ch9-Debugging/CST116 Output Ch9.txt b/CST116-Ch9-Debugging/CST116 Output Ch9.txt new file mode 100644 index 0000000..9a965d1 --- /dev/null +++ b/CST116-Ch9-Debugging/CST116 Output Ch9.txt @@ -0,0 +1,7 @@ +Please enter your age: 19 +19! Boy are you old! +Did you know that you are at least 6935 days old? + + +C:\Users\furyf\OneDrive\Desktop\Homework\CST Homework\CST116 Chp9\CST116-Ch9-Debugging\x64\Debug\CST116-Ch9-Debugging.exe (process 29304) exited with code 0. +Press any key to close this window . . . \ No newline at end of file diff --git a/CST116-Ch9-Debugging/CST116 Pseudo Code Ch9.txt b/CST116-Ch9-Debugging/CST116 Pseudo Code Ch9.txt new file mode 100644 index 0000000..19e514c --- /dev/null +++ b/CST116-Ch9-Debugging/CST116 Pseudo Code Ch9.txt @@ -0,0 +1,20 @@ +Under main +set and place age and days as 0 +age is equal to GetAge function +under GetAge +set age +output "please enter your age: " +input age +return age +days is equal to CalcDays(age) +under CalcAge (set years) +set days +days is equal to years*days per year (365) +return days +Printresults(day and age) +under PrintResults +output age with "! Boy are you old!" +new line +output "did you know that you are at least " with days with "days old?" +new line +dont return \ No newline at end of file diff --git a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp index f78a1b6..3be9c13 100644 --- a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp +++ b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp @@ -19,12 +19,13 @@ * 7) The execution continues to the function header for GetAge. * 8) Step into one more time. * 9) Why did the address of age and value change? -* E +* It changed because "age" became undefined as there are 2 different "age" * 10) Step over the cout and cin statements. * 11) Verify the value entered is stored properly in age. * 12) Step into until the flow returns to main. * 13) Step over one more time. * 14) Why didn't the value entered get transferred back to main? +* because the "age" are different between the one under main and the one in GetAge * 15) Stop debugging and fix the error. * 16) Run to Breakpoint 1. * 17) Step over the function call to GetAge. @@ -40,6 +41,7 @@ * 4) Step into one more time so that the current line is the * calculation. * 5) Why is age greyed out in your watch window? +* The reason age is greyed is because years is a parameter * 6) Stop debugging. * * Debugging Exercise 3 @@ -51,6 +53,7 @@ * 4) Step into the PrintResults function. * 5) Age is 7300? Not even Ralph is that old. * 6) Why did the values for both variables change? +* Because the "age" and "day" were inputed in the wrong order * 7) Stop debugging and fix the error. * * Debugging Exercise 4 @@ -72,7 +75,7 @@ const int DAYS_PER_YEAR = 365; int GetAge(); int CalcDays(int age); -void PrintResults(int age, int days); +void PrintResults(int days, int age); int main() { @@ -81,12 +84,12 @@ int main() // Breakpoint 1 // Put breakpoint on the following line - GetAge(); + age = GetAge(); days = CalcDays(age); // Breakpoint 2 // Put breakpoint on the following line - PrintResults(age, days); + PrintResults(days, age); return 0; } @@ -107,6 +110,11 @@ int CalcDays(int years) return days; } +/// +/// It prints results +/// +/// The days to be displayed +/// the age to be displayed void PrintResults(int days, int age) { cout << age << "! Boy are you old!\n"; -- cgit v1.2.3