Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This the code #include <iostream> #include <string> using namespace std; void pr

ID: 3588441 • Letter: T

Question

This the code

#include <iostream>
#include <string>
using namespace std;

void pr_message(string s)
{
cout << s << endl;
}

int main()
{
int x = 1, y = 1;
pr_message("Hello world!");
--x;
y = x;
pr_message("Hmm, what to do next?");
// Later on, un-comment out the following line, run it without
// the debugger, and then choose to debug when it crashes.
// A new VC++ debugger sessions starts.
x = y / x; // divide by zero run-time error!
pr_message("Ooh, that was close!");
x = 7;
pr_message("OK, let's quit.");
return 0;
}

Directions: Copy the program "msvs_exp.cpp" into Microsoft Visual Studios. Then follow the steps below and answer the following questions.

Question 1: Place a breakpoint at the line "int x = 1, y = 1;" and run the program using Debug, Start Debugging. The program stops at the first breakpoint. What are the values of x and y at this point in the program?

Question 2: Use the Step Over command once. What now are the values of x and y at this point in the program?

Question 3: In your own words, explain why the change in the values of x and y that occurred in Step 2 was not visible at the breakpoint in Step 1.

Question 4: The yellow arrow should be pointing to the line "pr_message("Hello world!");". Use the Step Into command to enter this function. Explain what you see.

Question 5: Now use the Step Out command to return to "pr_message("Hello world!");". What is the command you used for this action?

Question 6: Now in the main function, place a breakpoint on the line "x = y / x;". Keep an eye on the window as you continously use the Step Over command until you reach this breakpoint. What line in the program sets the denominator to cause the divide-by-zero error?

Question 7: Based on your answer in Question 6, correct the code to allow the program to run to completion.

PLEASE THIS IS THE 3RD time I post this ONLY QUESTIONS 1 THROUGH 7 is what I need to be answered

Explanation / Answer

1.

at first breakpoint the variable x any y are not declared since they are not declared so there will be no value assigned to them

2.use step over command the value of xnad y will be 1

3. at breakpoint in step 1 already mentioned the variables x and y were not declared when we exected the step over command the variable x and y will be declared and their initial value will be assigned i.e. 1 which is mentioned at the time of declaration

4.on pressing the step into command over the function call pr_message( ) debugger will enter inside the function and will execute the function

in this case cout statement inside the function will print the message / string which is passed to the function as an argument

5. pres f8 for step out from the function

this command can vary from IDE

6. at line 12 the statement --x; will make the value of x to 0,

so when you place the breakpoint at line  x = y / x; and when you exectue the code it will give the null pointer exception

7. to overcome the error for the null pointer exception i am checking the value of x if the value of x is 0 i am printing the message cannot divide by zero using the function pr_message( ) else if the value is not zero then i am performing the division

code-----

#include <iostream>
#include <string>
using namespace std;
void pr_message(string s)
{
cout << s << endl;
}
int main()
{
int x = 1, y = 1;
pr_message("Hello world!");
--x;
y = x;
pr_message("Hmm, what to do next?");
// Later on, un-comment out the following line, run it without
// the debugger, and then choose to debug when it crashes.
// A new VC++ debugger sessions starts.
if(x == 0 )
pr_message("Cannot divide the number by 0");
else
x = y / x; // divide by zero run-time error!
pr_message("Ooh, that was close!");
x = 7;
pr_message("OK, let's quit.");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote