EECS 183 Lab 9: Classes
Lab attendance Due at your scheduled lab time and day, Thursday or Friday, April 1st or 2nd
Lab assignment Due Monday, April 5, 2021, 11:59 pm Eastern
In this lab, you are writing code to master the use of classes. You will also get a head start on Project 4.
Attend the discussion with your lab instructor at your assigned lab time. Check here for the lab section Zoom link
You will complete this lab in small groups of about 4 students. For all labs in EECS 183, to receive a grade, every student must individually submit the Lab assingment.
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:
After downloading and unzipping, you will find the following files in the starter-files folder:
Position.cpp: source code file you will use for the exercise. This file is identical to one of the files for Project 4.
Position.h: header file with the Position class definition.
utility.h: header file with declarations you will need for Project 4 and this lab.
test.cpp: source file you will use to test your Position class functions for
grid1.txt: text data file you may use for testing.
grid2.txt: text data file you may use for testing.
IMPORTANT: For this lab, you must include all files in a single project in Xcode or Visual Studio.
IMPORTANT: Do not change any part of the header file
Tasks to Complete
- To complete this portion of the lab, you need to do the following steps:
- Start a new project with your IDE using the starter files according.
- Write your test cases in
test.cppto test the functions you will implement in
- Write the implementations for the functions in
- Test your functions using the test cases you have written.
- Submit your
and data2.txtto the autograder.
data2.txtare optional to submit to the autograder. They may help you with your test cases for the lab.
NOTE: The functions
Position::writehave identical implementations to the
writefrom Lab 8.
IMPORTANT: This is the same file you will use for Project 4: Battleship. Once you complete the lab you may use your lab solutions for Project 4.
- This file contains the definition (implementation) of a class that represents a Position for the game Battleship – think a two-dimensional coordinate system: (row, column).
- Each Position has an row value and a column value.
- The values for row and col must always be within specified bounds, accomplished using the
check_range()function declared in
- A valid position is any position on a valid grid (grid of max size
- When reading a Position, it will be in one of two forms:
- The form
(row,col), which includes the parentheses and comma
- The form
rowcolwith no space between the row and column characters
grid1.txtfor an example of how points are represented.
- The form
- When writing a coordinate, it will be in only one form:
- The form
(row, col), which includes the parentheses and comma
- The form
IMPORTANT: A Position of (1,A) will be stored as having row being 0 and col being 0
- Now test all the member functions you wrote for the
test.cpp. With classes, you can have compile errors that do not show up until you call the individual member functions. Testing is critical when programming with classes. To get you started, we provided you with sample test cases in the
test.cppfile. You’ll need more tests than this to catch all the bugs on the Autograder.
- For testing, you may submit two data files to the Autograder, but they must be called
NOTE: The first text file
grid1.txtserves as an example of the two different forms a Position. You should use this file to test your
Position::read()function. The other text file,
grid2.txtis empty. You can use this file to test your
File Locations - Xcode
There are a few things that must be done for Xcode. First, ensure that Derived Data is stored relative to your project folder. Select Xcode > Preferences in the menu bar, click on Locations icon at the top on the window and choose Relative next to Derived Data. This will ensure that executables are saved in your Project folder.
Then, tell Xcode to look for files in the folder where all other project files are stored. From the menu bar, choose Product > Scheme > Edit Scheme.
Select Run on the left, Options on top and then select the checkbox Use custom working directory and navigate to your Project folder where you will store input files.
Now you can place input
txt files right with your
NOTE: If you move your project folder, you’ll have to reset the project’s working directory.
File Locations - Visual Studio
Fortunately, Visual Studio’s working directory is the project folder itself. So head to the project folder that is named the same as the project. There should be another folder with that same name. Place the input files in that second folder.
How to Submit
When ready to submit to the autograder, visit https://autograder.io/web/project/993. You will submit your
- NOTE: it is possible to receive full credit for this lab without submitting one or both of
data2.txtto the autograder. You will definitely need both to fully test your
Position::write()functions on your computer.
IMPORTANT: For all labs in EECS 183, to receive a grade, every student must individually submit the Lab Submission. Late submission for Labs will not be accepted for credit. For this lab, you will receive ten submissions per day with feedback.
- Once you receive a grade of 5 of 5 points from the autograder you will have received full credit for this lab.