EECS 183 Labs

EECS 183 Lab 3: Functions and Debugging

Lab due on your scheduled lab day (September 10 to 16)

Lab accepted for full credit until Tuesday, September 17, 2024, 11:59 pm Eastern

In this lab, you are writing code and solving practice exam questions to master the use of functions, and to learn a new resource for finding bugs in your programs.

By completing this lab assignment, you will learn:

Requirements

You should complete this lab in small groups of about 4 students.

IMPORTANT: For all labs in EECS 183, to receive a grade, every student must individually submit the lab assignment.

  1. Create a project using the debugme.cpp from the starter files, shown below.
  2. Modify the debugme.cpp starter file with your solution to the lab with your peer group in the Lab Assignment.
  3. Submit your debugged debugme.cpp file to the autograder here

Starter Files

You can download the starter files using this link.

The IDE setup tutorials for Visual Studio and XCode include a video about how to set up a project using the starter files. You can access the tutorials here:

Lab Assignment

Debugging the Code

Now that you are familiar with the basic operations of the debugger, you can practice your new skills with buggy code. In this part of the assignment, you will start with a program that has several bugs. Use the debugger to find the bugs in the program and rewrite the code to eliminate the bugs.

NOTE: In fixing the bugs, you must not change the parameters for the given functions! The autograder will give you a score of zero if you do. This is the case for all Projects 1-4 in EECS 183. There are no compile errors in the code, only bugs that result in incorrect output.

// set your first breakpoint on the following line
int newHunger = feedPet(careForPet, hunger);

HINT: Look carefully at the values for hunger and food in the feedPet() function. This is your first bug to find. Remember, you cannot change the parameters for the functions you are given so you must instead change the statement in main() where this function was called!

HINT: Look carefully at the Effects of the RME and the variables and operators used in the feedPet() function. This is your next set of bugs to find. The use of the hunger and newHungervariables is not correct. What should the assignment operation be to the newHunger variable? Which variable should be used in the return statement?

Sample Runs

Sample Run 1

TamagotchEECS Pet Simulator
Please enter pet name: Grumpy Cat
Please enter pet initial hunger: 100
Please enter pet initial happiness: -50
Please enter number to be used for feeding and petting: 50
After caring for Grumpy Cat, current hunger is: 50 and happiness is: 0
Thanks for using TamagotchEECS Pet Simulator! Good luck!

Sample Run 2

TamagotchEECS Pet Simulator
Please enter pet name: Taco
Please enter pet initial hunger: 500
Please enter pet initial happiness: 77
Please enter number to be used for feeding and petting: 42
After caring for Taco, current hunger is: 458 and happiness is: 119
Thanks for using TamagotchEECS Pet Simulator! Good luck!

Sample Run 3

TamagotchEECS Pet Simulator
Please enter pet name: Jabba
Please enter pet initial hunger: 7000
Please enter pet initial happiness: 100
Please enter number to be used for feeding and petting: -250
After caring for Jabba, current hunger is: 7250 and happiness is: -150
Thanks for using TamagotchEECS Pet Simulator! Good luck!

Sample Run 4

TamagotchEECS Pet Simulator
Please enter pet name: Punxsatawny Phil
Please enter pet initial hunger: 42
Please enter pet initial happiness: 42
Please enter number to be used for feeding and petting: 42
After caring for Punxsatawny Phil, current hunger is: 0 and happiness is: 84
Thanks for using TamagotchEECS Pet Simulator! Good luck!

How to Submit Debugging the Code

Note: If you’re using Xcode and don’t know how where exactly debugme.cpp is located on your disk, right-click (or click while holding down the Control key) on the file in the Navigator area on the left side of the Xcode window and choose Show in Finder.

If you’re using Visual Studio and would like to know where debugme.cpp is on your disk, right-click on debugme.cpp in the tab above the Code pane and choose Open Containing Folder.

IMPORTANT: Late submissions for Labs will not be accepted for credit.

For all projects and labs in the course, we grade your highest submission score. In future projects, you will receive a limited number of submissions with feedback per day.

In projects in courses at Michigan, you receive very limited submissions with feedback per day, typically four times per day. However, for this lab, you will receive ten submissions per day with feedback. Once you receive a grade of 10 of 10 points for debugme.cpp from the autograder you will have received full credit for this lab.

Autograder Feedback

You can see the grade and feedback from your submissions by selecting My Submissions in the upper-left corner. Selecting a submission from the left tab will show the tests and feedback for the lab. When your submissions fail one or more tests, feedback about the test will be displayed. The autograder will show a line-by-line difference between the expected output for a correct solution and the output of your program.

IMPORTANT: Differences in blank lines will not cause your program to fail tests for this lab. There must be another reason for the test to fail, look closer.