diff options
Diffstat (limited to 'CST116-Ch9-Debugging.cpp')
| -rw-r--r-- | CST116-Ch9-Debugging.cpp | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/CST116-Ch9-Debugging.cpp b/CST116-Ch9-Debugging.cpp index eff8980..9c8bf56 100644 --- a/CST116-Ch9-Debugging.cpp +++ b/CST116-Ch9-Debugging.cpp @@ -1,3 +1,6 @@ +//William Bishop
+
/********************************************************************
* File: CST116-Ch9-Debugging.cpp
*
@@ -11,16 +14,16 @@ * 3) Place a watch on age and days.
* 4) Add another watch using &age for the name. This will display
* the address of age.
-* 5) Write down the address of age.
+* 5) Write down the address of age. 0x000000ee717cf554{0}
* 6) Step Into the code for the function GetAge.
* 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?
+* 9) Why did the address of age and value change? It changed because we went through age in the from GetAge function and set us up for some new address in the new function.
* 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?
+* 14) Why didn't the value entered get transferred back to main? It looks we need to pass by reference into fain. When we went into calcdays we felt that we haven't gotten the right age into that function yet. We were in a different function and we ran through the main function to change the work in the name value of the age.
* 15) Stop debugging and fix the error.
* 16) Run to Breakpoint 1.
* 17) Step over the function call to GetAge.
@@ -35,7 +38,7 @@ * 3) Step into CalcDays.
* 4) Step into one more time so that the current line is the
* calculation.
-* 5) Why is age greyed out in your watch window?
+* 5) Why is age greyed out in your watch window? It is stale do to a problem that came with evaluating it.
* 6) Stop debugging.
*
* Debugging Exercise 3
@@ -46,7 +49,7 @@ * is 7300.
* 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?
+* 6) Why did the values for both variables change? We needed to fix the work of what is the Calcdays function and add that into the main function.
* 7) Stop debugging and fix the error.
*
* Debugging Exercise 4
@@ -66,40 +69,45 @@ using std::endl; const int DAYS_PER_YEAR = 365;
-int GetAge();
-int CalcDays(int age);
+void GetAge(int age);
+void CalcDays(int age,int days);
void PrintResults(int age, int days);
-int main()
+int main(int age, int days)
{
- int age = 0;
- int days = 0;
+
+
+ GetAge(int age);
+ CalcDays(int days, int age);
+ int days;
+ int age;
+
// Breakpoint 1
// Put breakpoint on the following line
- GetAge();
- days = CalcDays(age);
+
// Breakpoint 2
// Put breakpoint on the following line
- PrintResults(age, days);
-
+ void PrintResults(int age,int days);
+
+
return 0;
}
-int GetAge()
+void GetAge(int age)
{
- int age;
-
+
+ int age;
cout << "Please enter your age: ";
cin >> age;
return age;
}
-int CalcDays(int years)
+void CalcDays( int days,int age)
{
- int days;
+ int days;
- days = years * DAYS_PER_YEAR;
+ days = age * 365;
return days;
}
|