EECS 183 Labs

EECS 183 Lab 3: Functions and Debugging

Lab assignment Due Wednesday, September 22, 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 will 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 Submission.

  1. Create a project using the debugit.cpp from the starter files, shown below.
  2. Head to the Google form for Debugit here while signed into Google with your own @umich account and follow on-screen instructions while using the debugger.
  3. Create a second project using the lab3.cpp from the starter files, shown below.
  4. Modify the lab3.cpp starter file with your solution to the lab with your peer group in the Lab Assignment.
  5. Submit your debugged lab3.cpp file to the autograder here

NOTE: Your lab 3 assignment grade will require both submissions for full credit.

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

Debugit

2 Points of 6 total for Lab 3 assignment grade

One primary tool that saves your time developing and testing is a debugger. Debuggers are simple to use, and run your code line-by-line as a computer sees it. Bugs that would take hours to find by hand can be found in a few minutes with a debugger. Debuggers help you find why and where your code is incorrect. The key to debugging is setting breakpoints, investigating variables, watching variables, step into, step out of, and step over. That’s about all the EECS 183 staff use and it can save hours of work. So we will teach you how to use a debugger with this exercise.

IMPORTANT: For all labs in EECS 183, to receive a grade, every student must individually submit the Lab. Late submission for Labs will not be accepted for credit.

How to Submit Debugit

During the exercise, you should follow along in the Google form above while using the debugger in your IDE. Be sure to submit the Google form when you are done. You should receive a confirmation email to your @umich email address when you have successfully submitted the form.

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-5 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 lab3.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 lab3.cpp is on your disk, right-click on lab3.cpp in the tab above the Code pane and choose Open Containing Folder.

IMPORTANT: Late submission 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 5 of 5 points for lab3.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 exepcted 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.