EECS 183 Labs

EECS 183 Lab 7: Classes

Lab due on your scheduled lab day (March 6-10)

Lab accepted for full credit until Tuesday, March 14, 2023, 11:59 pm Eastern

In this lab, you are writing code to master the use of classes. You will complete part of Project 4 in the lab.

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:

After downloading and unzipping, you will find the following files in the starter-files folder:

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 files Position.h or utility.h.

Lab Assignment

Tasks to Complete

  1. Start a new project with your IDE using the starter files according.
  2. Write your test cases in test.cpp to test the functions you will implement in Position.cpp.
  3. Write the implementations for the functions in Position.cpp:
  4. Test your functions using the test cases you have written.
  5. Submit your Position.cpp, test.cpp, data1.txt, and data2.txt to the autograder.
    • NOTE: data1.txt and data2.txt are optional to submit to the autograder. They may help you with your test cases for the lab.

Position.cpp

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.

IMPORTANT: A Position of (1,A) will be stored as having row being 0 and col being 0

test.cpp

NOTE: The first text file grid1.txt serves 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.txt is empty. You can use this file to test your Position::write() function.

File I/O

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 .h and .cpp files.

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