lab8-fileIO
EECS 183 Lab 8: File IO
Lab attendance Due at your scheduled lab time and day, Thursday or Friday, March 25th or 26th
Lab assignment Due Monday, March 29, 2021, 11:59 pm Eastern
Direct submission link
In this lab, you are writing code to master the use of File IO and pass-by-reference. You will also get a head start on Project 4.
Prerequisite
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.
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:
lab8.cpp
: source code file you will use to test the functions you write. You will not submit this file for grading.coordinates.h
: header file with the RMEs and declarations for the functions you will implement for this lab.coordinates.cpp
: soruce code file for the functions you will write and submit for this lab assignment.grid2.txt
: text data file you may use for testing. All coordinates in this file are within the valid range specified below.grid2_output.txt
: text data file you may use for testing. This is an example of an output file written with input coordinates from grid2.txt.gridBad.txt
: text data file you may use for testing. This file contains coordinates that are outside of the valid ranges shown below.
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
coordinates.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
lab8.cpp
to test the functions you will implement incoordinates.cpp
. - Write the implementations for the functions in
coordinates.cpp
: - Test your functions using the test cases you have written.
- Submit your
coordinates.cpp
to the autograder.
Coordinates
Think a two-dimensional coordinate system: (row, column).
- Each coordinate 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 incoordinates.h
- A valid position is any position on a valid grid (grid of max size
MAX_GRID_SIZE
*MAX_GRID_SIZE
)- The constant
MAX_GRID_SIZE
is declared incoordinates.h
- The constant
- When reading a coordinate, it will be in one of two forms:
- The form
(row,col)
, which includes the parentheses and comma - Example:
(1,B)
- The form
rowcol
with no space between the row and column characters - Example:
1B
. Seegrid2.txt
for 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 - Example:
(1,B)
- See
grid2_output.txt
for an example of how points are represented.
- The form
IMPORTANT: A Position of (1,A) will be stored as having row being 0 and col being 0
check_range()
This function is used to ensure a value is within the valid range for a valid grid, shown above.
[0,MAX_GRID_SIZE)
read()
This function will read a value from the input stream is
and modify row
and col
with the values read.
- Your implementation must use the check_range function so that
row
andcol
remain in valid
The RME for read() states: col is NOT case senstive, so reading should work for, e.g., “(1,a)” or “1a” or “(1,A)” or “1A”.
A useful function to help with this is toupper()
, which you can find in zyBooks Chapter 9 Section 1.
Be careful though - toupper()
returns an int
.
Make sure to explicitly cast it to a char
before using it!
NOTE: You may assume that the row and column values read are single characters. You may also assume that the row value will be in the range (0,9) and column value will be in the range (A,Z) or (a,z). You must utilize check_range to make sure
row
andcol
are withing the correct bounds.
write()
This function will write the values of row
and col
to the output stream os
Writes position in form (row,col) where row is in range [1, 8] and col should be an uppercase letter in range [A, H].
To accomplish this, you must:
- convert
row
from the range of [0,MAX_GRID_SIZE) to the range of [1,MAX_GRID_SIZE], and - convert
col
from the range of [0,MAX_GRID_SIZE) to the range of [A, H]
Note: your write function will not write coordinates in pairs of lines!
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
- When ready to submit to the autograder, visit https://autograder.io/web/project/992. You will submit only your
coordinates.cpp
file.
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.