EECS 183 Labs
EECS 183 Lab 4: Loops
Lab due on your scheduled lab day
Lab accepted for full credit until Monday, February 14, 2022, 11:59 pm Eastern
Direct submission link
In this lab, you are writing code and solving practice exam questions to master the use of loops.
By completing this lab assignment, you will learn:
- To understand how loops work in C++.
- To practice writing answers to exam questions and receive early self-assessment of preparedness for the exams.
Prerequisite
You will need to use and be able to understand RMEs (Requires, Modifies, Effects) to complete this lab. You can find a reference for RMEs on Google drive here. You should 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:
loops.cpp
: source code file you will use for the Loops exercise.loops.h
: header file you will use for the Loops exercise.test.cpp
: source code file you will use for the Loops exercise.
IMPORTANT: For this lab, you must include all three files in a single project in Xcode or Visual Studio.
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.
- Stub all of the functions in
loops.cpp
- see Function Stubs for details. - Write your test cases in
test.cpp
to test the print functions you will implement inloops.cpp
. - Write the implementations for the functions in
loops.cpp
:printRectangle()
printRight()
printRightJustified()
printIsosceles()
- Test your functions using the test cases you have written.
- Submit your
loops.cpp
andtest.cpp
to the autograder.
Multiple Files
-
Most programs in the real world are written in more than just one file so as to break down the functionality into smaller parts and to keep the program’s organization clean. As you start writing more complex and more involved (and more exciting!) programs, you too will work with multiple files.
-
For Project 1, you worked with just one file, such as
focaccia.cpp
. It had amain()
function, where the execution began, and then some other functions that were called frommain()
or from other functions. But as a program gets more complicated, you can imagine that the file would just get longer and it would be much more difficult to keep it organized, let alone test the program. -
And so a common practice is to put (at least some) functions into separate files. The functions declarations (aka prototypes) go in what are known as header files that end in
.h
, and the functions definitions (aka implementations) go in.cpp
files. Each.cpp
file will#include
the.h
files that contain the declarations for the functions it implements or calls. For example, in this lab you will find#include "loops.h"
in theloops.cpp
file.
Function Stubs
A function stub is a temporary substitute for a to be implemented function. In all projects and labs so far in EECS 183, we have provided all of the function stubs for you. Starting with this lab, you will need to create function stubs for all of the functions you will implement.
- For example, here is a function stub for
printRectangle()
:
void printRectangle(int rows, int cols) { // TODO - implement return; }
- If you submit to the autograder without all function stubs or completed definitions, you will see an error for any missing function stub or definition. If you see an error message like
undefined reference to printRectangle(int, int)
it is a missing or incorrect function stub for the function named.
Testing
-
We have started the function
testPrintRectangle()
for you. -
You will add more test functions, such as
testprintRight()
. Do not forget to call your test functions withinint main()
oftest.cpp
.
Bugs To Expose
There are a total of 4 unique bugs to find in our implementations of loops.h
functions. Your tests will need to expose all of the bugs to receive full points for the lab. The autograder will tell you the names of the bugs that you have exposed, from the following set:
- PRINT_ISOSCELES
- PRINT_RECTANGLE
- PRINT_RIGHT
- PRINT_RIGHT_JUSTIFIED
loops.cpp
IMPORTANT: Differences in whitespace do matter for the functions that you will define in
loops.cpp
.
You will create function definitions for the following functions, all declared in loops.h
:
Everything you need to be able to define these functions is found in the RME’s in loops.h
.
You can find a reference for RMEs on Google drive here.
How to Submit
- When ready to submit to the autograder, visit https://autograder.io/web/project/1378. You will submit your
loops.cpp
andtest.cpp
files which should contain your solution for this lab as one program.
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 10 of 10 points from the autograder you will have received full credit for this lab.