EECS 183 Labs
EECS 183 Lab 7: Classes
Lab due on your scheduled lab day (October 21-25)
Lab accepted for full credit until Tuesday, October 29, 2024, 11:59 pm
Direct submission link
In this lab, you are writing code to master the use of classes. You will also use your solutions for Project 4.
Starter Files
You can download the starter files using this link.
After downloading and unzipping, you will find the following files in the starter-files folder:
Point.cpp
: source code file you will use for the exercise. This file is identical to one of the files for Project 4.Point.h
: header file with the Point 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 Point class functions forPoint.cpp
start.cpp
: source file with the main() function for your program, which calls your test cases intest.cpp
data1.txt
: text data file you may use for testing.data2.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
Point.h
.
Lab Assignment
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.cpp
to test the functions you will implement inPoint.cpp
. - Write the implementations for the functions in
Point.cpp
: - Test your functions using the test cases you have written.
- Submit your
Point.cpp
,test.cpp
,data1.txt
, anddata2.txt
to the autograder.- NOTE:
data1.txt
anddata2.txt
are optional to submit to the autograder. They may help you with your test cases for the lab.
- NOTE:
Point.cpp
IMPORTANT: This is the same file you will use for Project 4. Once you complete the lab you may use your lab solutions for Project 4, even if you worked with people other than your project partner on the lab.
- This file contains the definition (implementation) of a class that represents a point on the Project 4 canvas – think a two-dimensional coordinate system: (x, y).
- Each Point has a x value and a y value.
- The values for row and col must always be within specified bounds, accomplished using the
check_range()
function declared inPoint.h
- A valid point is any point on a valid grid (grid of max size
DIMENSION
*DIMENSION
).DIMENSION
is defined inutility.h
. - Points are stored in files in the following format:
(x,y)
which includes the parentheses and comma- Example: (1,-4)
test.cpp
- Now test all the member functions you wrote for the
Point
class intest.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 thetest.cpp
file. 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
data1.txt
anddata2.txt
.
NOTE: The first text file
data1.txt
serves as an example of points to read from a file. You should use this file to test yourPoint::read()
function. The other text file,grid2.txt
is empty. You can use this file to test yourPoint::write()
function.
File I/O
File Locations - Xcode
Follow along with Emma to set up your Xcode project the right way.
NOTE: The steps and videos below were created for project 4. The process is exactly the same for the lab, there will just be a different set of starter files.
- Condensed walkthrough to set up your Xcode project.
- Full, detailed instructions and troubleshooting guide to set up your Xcode project.
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 > Settings… (may be called Preferences in older versions of Xcode) 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. You’ll find bmp
files created by your program in the
same place.
NOTE: If you move your project folder, you’ll have to reset the project’s working directory.
Visual Studio
Following the instructions for Setting Up Project 1 in the Getting Started with Visual Studio document will put the starter files in the correct folder. The only difference from Project 1 is that there are more starter files to add. These steps are replicated for project 4 in the video below. This process is the same for this lab, there will just be a different set of starter files.
Verifying File IO and Project Setup
It is imperative that your Xcode/Visual studio project is set up correctly to read and write text files. Be sure to edit the scheme for Xcode and that the files are in the correct directory in Visual Studio.
Here is a test case that you can add to your test.cpp
to check if your text files, like data1.txt
and data2.txt
, are in the correct directory. Be sure to call file_check
in your start_tests
function!
void file_check() { // open one of the text files that are part of the starter code ifstream ins; ins.open("data1.txt"); // if the file was not in the correct directory, the stream state is fail if (ins.fail()) { cout << "Could not open data1.txt" << endl; } else { cout << "Success! Text files are in the right directory." << endl; } ins.close(); return; }
If you get the message "Could not open data1.txt"
try editing the scheme again (Mac) or checking that you have the project files in the correct directory (Windows).
If you cannot get the text files in the correct directory, then try adding the following to your file_check test.
// if the file is not in the right directory, try this: ofstream outs; outs.open("crazyfilename"); outs << "find the file named crazyfilename in windows explorer or finder"; outs.close();
Then open Windows Explorer (Windows) or Finder (Mac) and search for the file named crazyfilename
. Once you find the folder with that file name, copy all of the .txt
files from the project starter files to that directory. Then try the file_check test again.
How to Submit
-
When ready to submit to the autograder, visit https://autograder.io/web/project/2832. You will submit your
Point.cpp
,test.cpp
, anddata1.txt
files. -
NOTE: it is possible to receive full credit for this lab without submitting one or both of
data1.txt
anddata2.txt
to the autograder. However, you will definitely need both to fully test yourPoint::read()
andPoint::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 submissions for Labs will not be accepted for credit.
- Once you receive a grade of 10 of 10 points from the autograder you will have received full credit for this lab.