Lab 4

Overview

This lab is intended to help you to become more familiar with object-oriented code. You will use the debugger to assist in this.

Directions

If you already have a workspace on your M drive, use File, Open Workspace to open it. If not, use File, New, Workspace to create a new workspace on your M drive. Then create a new project within it named showcars by using File, New, Project. Use MyComputer to copy the files in the lab4 folder of your Cs111 network drive to the showcars directory within your workspace directory on M. (For example, you can use "CTRL click" to select all of the files and then use Edit, Copy, move to the new location and use Edit, Paste.) In Visual Studio, use Project, Add to Project, Files to add these files to the showcars project.

Use Build, Rebuild All to compile the program. Run the program once to see how it works. For example, try a price range of 2500 to 5500 dollars.

Now use the debugger to see how objects can be examined while your program is running. Make sure that the showcars.cpp file is shown on the screen. Click on the line containing do, the beginning of the loop. Use Build, Start Debug, Run to Cursor so that the debugger runs to the cursor location.

At this point the CarArray should be filled with data. Let's check on this. First, make sure that the debug toolbar is visible. (If not, use Tools, Customize, Toolbars, Debug.) Make sure that you have an Auto Variables window at the bottom of the screen. If not, click on the appropriate button on the debug toolbar. Also make sure that you have a Watch window at the bottom of the screen. (This one lets you enter the names of variables whose values you want to see.) CarArray should show in the Auto Variables window. (If not, enter it into the Watch window.) Click on the + in front of this variable to expand your view of it. You should then see the six locations in this array, indexed 0 through 5. Click on the + in front of the 0 to expand your view of what is at index 0. You should then see Doors, HorsePower, and Product. Product is shown because this object inherits fields from the Product class. Click on the + in front of Product to see the inherited fields. Now try the same process to view the data at index 3 in CarArray.

Next click on the Step Into button on the debug toolbar so as to step into the Lookup function. Once inside try examining the data in CarArray. You will note that once we are out of the function where the array was created, the debugger isn't smart enough to realize that there is more than one item in the array. So, you can only see the first item in the array. To get around this, enter CarArray[3] in the Watch window and expand the view so that you can see all of this data.

Use the Step Over button on the debug toolbar to step over the next several lines of code. Watch carefully the values shown for the variables. Note that you will have to enter a minimum and maximum value in the DOS window when the code asks for them and you will need to occasionally press ENTER when prompted. Watch that the if test correctly picks out which cars to print. Then press the button to exit the debugger (second button on the debug toolbar).

If you have extra time, use it to work on your homework and to ask your instructor for assistance on this homework.