Question: This lab assignment will show you how to use the debugger with VS Code. Also, how to step into functions and you will get even

This lab assignment will show you how to use the debugger with VS Code. Also, how to step into functions and you will get even better understanding what gets passed into functions when the parameters are call by value vs. call by reference. One part of the lab will be converting value-returning function into void functions and the last part consists of manually tracing a program and writing out the output.

  1. Create a subdirectory called lab7
  2. Copy the program min_sum.cc from the course directory
  3. Open lab7 folder in VS Code and configure the debugger for your project.
  4. Debugging via VS Code
  1. You will be using min sum.cc to step through line by line using the debugger
  2. Set a breakpoint on line 18 Click to the left of the line number. You should see a red dot indicating the breakpoint
  3. Start the debugging session by clicking on "Run and Debug" in the left panel, then click on the green arrow (top left)
  4. Line 18 should be highlighted showing you that this line will be executed next.
  5. You should also see a debugging toolbar as shown below
  6. You should be able to see all the main program variables and their values in the left panel
  7. Step over line 18 and line 20
  8. Answer question 1 on the answer sheet
  9. Step into the function get_num () by clicking the "Step into" button on the debug toolbar
  10. Examine the address of the variable num: Click on the "Debugging console" in the bottom of the screen. Enter the command "-exec p &num". This will display the address of the variable num
  11. k. Answer questions 2 and 3 on the Answer Sheet

    l. Step over twice (lines 40 and 41) and enter 15 in the terminal panel

    m. Step over to go back to the main program (Line 24 should be highlighted to be executed next)

    n. Answer question 4 on the answer sheet

    o. Step over twice

    p. Step into find min and sum all functions the same way as before

    q. Answer questions 5-7 on the Answer Sheet

    Look at the local variables, watch them change as you move through the code when you click Step over. If you wish you can continue the program execution (without stepping through each line of code) by clicking on Continue on the debug toolbar.

    Continue will run the code and stops at the next breakpoint or run the rest of the code if there are no additional breakpoints.

    Finish by typing -1 to exit the program execution.

    r. After you finish debugging click on Stop on the toolbar.

    1. (30 pts) Rewrite the Single value returning function sum all as a void function. The declaration (prototype) will be as follows: void sum all (int &cur sum, int cur num); Don't forget to change the function call in the main function. Compile and run the program with several values to make sure your changes are correct.
Answer sheet
  1. (10 pts) Write down the address of the variable number
  2. 2. (10 pts) At the first function call to get_num (before the while loop) write down the address of the formal parameter num
  3. (10 pts) Are the above two addresses the same? If so explain.
  4. 4. (10 pts) Once you are in the main function and the current line is minimum = number; Examine the value of number in the debugger window. Is the value of number the same as the value entered from the keyboard (15)? If so explain.
  5. (10 pts) Function find_min: write down the values of the formal parameters after you step into the function cur min= cur num=
  6. (10 pts) Explain the difference between cur_min and cur_num

7. (10 pts) Function sum all: write down what is cur sum cur num

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!