EECS 183 Labs

EECS 183 Lab 2: College Admissions

Lab due on your scheduled lab day, September 3-9 (Monday labs meet on Sept. 9 due to Labor Day holiday)

Lab accepted for full credit until Tuesday, September 10, 11:59 pm Eastern

In this lab, you are writing your first program in C++. As many aspiring computer scientists have, you will begin by writing the most common first program when learning a new language: Hello World. Then you will create a short, interactive program. While working on the lab, you will learn some of the tools you need to master Project 1 and beyond.

By completing this lab assignment, you will learn to:

Requirements

You will complete the lab in teams of around 4 students. For all labs in EECS 183, each student must submit their code individually to the autograder to receive a grade. If unable to work in a team, you may work independently.

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:

Lab Assignment

Your task for this lab is to create your first program in C++. Your initial program will display the message “Hello World!”, the canonical first programming experience. However, in software engineering, the majority of effort put into commercial software occurs after the initial release to the customers. So, we will then update your new Hello World program to create a College Admissions Calculator Program.

Hello World

Once you have started a new project with a source file — the distribution code file admissions.cpp — you will begin writing your “Hello World!” program.

Program Comment

First, start by modifying the block comment at the top of the file.

/**
 * admissions.cpp
 *
 * <#Name(s)#>
 * <#Uniqname(s)#>
 *
 * EECS 183: Lab 2
 *
 * <#description#>
 */

Replace the #Name(s)# and #Uniqname(s)# with your name and uniqname, along with the names and uniqnames of your teammates if you are working in a team. Also, replace the #description# with a (very) brief summary of the lab.

As you can see from the admissions.cpp file, there are only two lines of C++ source code, which appear below the comment.

The following lines will appear in all of your labs and projects for this course (at the top of the file, before the program statements you write) and are included in the distribution code file admissions.cpp.

#include<iostream>
using namespace std;

You do not need to understand precisely how these lines work in order to use them in your programs. You only need to know that they enable you to use programs someone else has already written. The above lines will allow you to write text and receive input from the terminal of your computer. The details of how that is accomplished are abstracted away, allowing you to focus on writing programs that solve the problem at hand.

To get started, you need to write a new function for your program. A function is a group of program statements that accomplish a certain task. Functions are a way we can organize our programs to make them more readable, extensible, and reusable.

Now, we will write a function named main, which is required for all C++ programs. This function is where you will write your program statements for the lab.

Every function you write should end in a return statement. A function ends when all of its statements have been executed, or when executing a return statement. The 0 in the statement return 0; is a return value that tells the Operating System (e.g., Windows) that your program ended without an error.

NOTE: The return statement should be the last statement in your main function; all other statements go before it.

int main() {

    return 0;
}

Every C++ program will have exactly one main function. Functions and their components will be explored in depth in future lectures, labs, and projects — they are a major topic in the course. We have included this function for you in admissions.cpp.

NOTE: All of the C++ statements you write for the function must appear between the curly braces {}, which define the scope of the function.

At this point, you will have completed the most basic program in C++. It does not accomplish the task of the lab. However, it is a complete program that you can run with your IDE. Run your program now. To review how to run a program using your IDE, see the guide for Getting Started with Visual Studio or Getting Started with Xcode. When you run your program, there will be nothing printed at the terminal and there should be no error messages.

IMPORTANT: Testing your code as you write it is an essential way to ensure that your code is correct. It will take less time overall when completing your projects.

Once you have a working program, it is time to write the code which will display Hello World!. To accomplish this, write the cout statement, which will have multiple parts:

NOTE: All C++ statements end in a semicolon, like how all English sentences end with a period. Not all lines in your code are statements — e.g. #include<iostream> and int main() { are not. In C++, a statement is a program instruction. Each statement usually appears on its own line.

A statement to print Hello World! to the terminal:

cout << "Hello World!";

Multiple cout statements will continue printing on the same output line unless an endl is used. An endl will start the next output on a new line.

cout << endl;

Printing multiple things can be done with one cout statement by using the insertion operator << before each item to be printed.

cout << "Hello World!" << endl;

Now, you have seen all the C++ source code necessary to write a “Hello World!” program. Add the cout statement and run your program. Confirm that you see Hello World! in your terminal. If you are not seeing Hello World!, verify the following:

NOTE: When using Visual Studio, you may see the terminal momentarily open and then immediately close. When this happens, add a breakpoint to your program. See the section for Running the Program in the Getting Started with Visual Studio documentation.

Once you have tested your program and verified it prints Hello World!, move on to the next part of the lab.

College Admissions Algorithms (5 points of 10)

Disclaimer: This portion of the lab was adapted from the College Admissions Algorithms assignment developed by Dr. Casey Fiesler at University of Colorado, Boulder.

As you know, the college admissions process involves many types of data from prospective students to make decisions. With the number of applicants increasing, colleges may begin relying on algorithms to select which applications should receive more intensive human review. An algorithm could use quantitative data–such as GPA and SAT score–to provide initial recommendations. Many colleges even track data about prospective student engagement (e.g. whether they open emails, visit the college website, engage on social media, etc.). This creates a “demonstrated interest” value.

Based on a recent survey of college admissions officers, we know some of the weights that humans tend to give to these different types of data. Your task will be to create a program that takes in student data and calculates an expected chance of admission. This recommendation score will be based on the following data:

Your program should:

When approaching a problem or writing a new function, there are five steps you should take. You should not begin by immediately writing statements in your program.

Define the problem

Begin by defining the problem you are tasked with solving. Take time to understand what you are attempting to accomplish. What is the purpose of the program? What do you need to provide the program for it to work? What do you expect to be the effects of running the program? What might be modified?

These questions are answered in the College Admissions Algorithms problem statement above. Consider what input your program will take and what it will print, then proceed to create an algorithm.

Writing an Algorithm

An algorithm is a series of steps used to solve a problem. You will need an algorithm to write the College Admissions Calculator. An algorithm can be written using different languages, but it must contain the steps required to solve the problem. You could write an algorithm using English (or another language) prose. However, it is more helpful to write an algorithm using pseudocode. Pseudocode is an informal description of an algorithm.

Write an algorithm for the problem using the pseudocode from the lecture as a guide. It is important to note that there is no universal pseudocode, and yours may look a little different.

Start by breaking down the program description.

From the Hello World! program, you can see that you will use a cout statement to print this message. But for now, just write the step in the algorithm as pseudocode.

1. Print "College Admissions Calculator"

The next part of the program description was:

There is more than one task in this statement. Add them to your algorithm.

1. Print "College Admissions Calculator"
2. Print "Please enter your GPA out of 5.0: "
3. User enters their GPA

Unfortunately, this is still too vague to describe well enough how to solve the problem. How will the user enter their GPA? What will we use to represent that number? Reviewing the algorithm to count the number of people in a room, you see the statement Let N = 0, which can be used as an example. Update our pseudocode to be more descriptive of what steps you will take in your algorithm.

1. Print "College Admissions Calculator"
2. Print "Please enter your GPA out of 5.0: "
3. Let GPA = 0
4. Input the GPA

The above pseudocode describes the steps to ask the user for their GPA and store that information. Now, revisit the last line of the program description to finish the algorithm.

As before, this line contains multiple tasks. Now, write your pseudocode for the remaining tasks, which include:

Your algorithm should now contain all of the steps necessary to solve the problem. You can also see how it can be more readily translated into C++ source code for your program.

How to Test

Before writing the C++ code for the program, first, stop and consider how you will test the program you write. What do you expect the effects of your program to be? If your program takes input, what will the results be for a range of inputs? For instance, if a student’s GPA is 2.5, SAT score is 1300, Demonstrated interest is 10, and Curriculum strength is 5, with weights of 0.4, 0.3, 0.1, 0.2 respectively, what would you expect the program to print for the student’s expected chance of admission? You can assume that the above values will be within their given range so you do not end up with a chance greater than 100.

NOTE: It is important to consider how to test your program before writing the code using your IDE. This method is called test-driven development and is the best approach to writing programs.

In this case, we would expect the prompts we have indicated to appear in the terminal, and if we input the values above, the effects of the program should be to tell us there that the student has a 63/100 chance of admission.

Translate your Algorithm to C++

Starting with the Hello World! program you have already written, add your C++ code. Here’s what the first few lines from your algorithm might look like in C++.

NOTE: Remove the cout statement for Hello World and put your new code in its place, but before the statement return 0;.

cout << "College Admissions Calculator " << endl;
cout << "Please enter your GPA out of 5.0:  " << endl;
double GPA = 0;

The first two statements are similar to how you printed Hello World!. The third statement is declaring a variable to hold the student’s GPA. A variable represents a memory location used to store data. The location is like a “box” that can store a value. The statement double GPA = 0; defines a new variable named GPA and gives it an initial value of 0.

IMPORTANT: Stop at this point and run your program to test what you have completed. You should see the prompts printing in the terminal, and your program should run without errors.

Once you have tested your program, move on with the rest of your algorithm.

C++ Input

In C++, reading input is achieved using a statement as such, which we will use in our program:

cin >> GPA;

The statement reads a user-entered value and stores the value in the given variable.

IMPORTANT: For the statement cin >> GPA; to work, the variable declaration double GPA = 0; must always come before the cin statement. In C++, all variables must be declared before they can be used. This is true for all variables you will use in your programs.

Now, test your program by running it. Before you move on, you should be able to run your program without errors, see statements printing to the terminal, and be able to type input to the program. Once your program runs and you can enter a number, move on to writing the remainder of the program from your algorithm.

Sample Output

The input to the program is given in red in these sample runs. Assume we are using the same weights from above:

GPA_WEIGHT = 0.4 
SAT_WEIGHT = 0.3
DEM_INTEREST_WEIGHT = 0.1
CURRICULUM_STRENGTH_WEIGHT = 0.2 

Sample Run 1

College Admissions Calculator
Please enter your GPA out of 5.0: 2.5
Please enter your SAT score out of 1600: 1300
Please enter your demonstrated interest out of 10: 10
Please enter your high school curriculum strength out of 10: 5

Expected chance of admission: 64/100

Sample Run 2

College Admissions Calculator
Please enter your GPA out of 5.0: 3.5
Please enter your SAT score out of 1600: 1400
Please enter your demonstrated interest out of 10: 7
Please enter your high school curriculum strength out of 10: 5

Expected chance of admission: 71/100

Sample Run 3

College Admissions Calculator
Please enter your GPA out of 5.0: 4.9
Please enter your SAT score out of 1600:  1370
Please enter your demonstrated interest out of 10: 3
Please enter your high school curriculum strength out of 10: 6

Expected chance of admission: 79/100

Autograder

The autograder is used in EECS 183 to submit your labs. It is also used to determine grades earned on the labs. For all labs in the course, you must submit your solutions to the autograder web interface. Each assignment will have its own autograder webpage.

How to Submit

Note: If you’re using Xcode and don’t know how where exactly admissions.cpp is located on your disk, right-click (or click while holding down the Control key) on the file in the Navigator area on the left side of the Xcode window and choose Show in Finder.

If you’re using Visual Studio and would like to know where admissions.cpp is on your disk, right-click on admissions.cpp in the tab above the Code pane and choose Open Containing Folder.

IMPORTANT: Late submissions for labs will not be accepted for credit.

For all projects and labs in the course, we grade your highest submission score. In future projects, you will be allowed a limited number of submissions with feedback per day.

In projects in EECS courses at Michigan, you are allowed a very limited number of submissions with feedback, typically four per day. However, for this lab, you are allowed ten submissions per day with feedback. Once you receive a grade of 5 points for admissions.cpp from the autograder, you will have received full credit for this portion of the lab.

Don’t forget to also submit the google form to receive full credit for the entire lab!

Autograder Feedback

You can see the grade and feedback from your submissions by selecting My Submissions in the upper-left corner. Selecting a submission from the left tab will show the tests and feedback for the lab. When your submissions fail one or more tests, feedback about the test will be displayed. The autograder will show a line-by-line difference between the expected output for a correct solution and the output of your program.

IMPORTANT: Differences in blank lines will not cause your program to fail tests for this lab. There must be another reason for the test to fail — look closer.

If your output is displayed on the same line as the input prompt, add a statement to print a new line immediately after using cin.

For example, if your output looks like this on the autograder:

Then add the following additional cout statement after the cin statement.

cin >> GPA;
cout << endl;

Things to look out for

When reviewing your program to make sure you are getting the correct output, it can be easy to miss small errors so here are some things to keep an eye out for.

Diffchecker is also a really helpful website to catch any differences between your program’s output and the sample outputs.

Once you have submitted your solution to the autograder and received full credit, continue onto part 2 of the lab.

Part 2: Biased Algorithms (5 points of 10)

Consider ways that the above algorithm might systematically miss certain edge cases. For example, what if a student has a 0 for demonstrated interest because they don’t use social media or have access to a home computer? Consider ways that this algorithm may not cover all cases and discuss with your partners how you would create a more well-rounded algorithm.

Respond to the four following reflection questions in the attendance google form linked on your section’s lab slides.

You will receive an email confirmation of your submission. Like all other lab assigments you are encouraged to work with your peers to develop a shared solution but everyone must submit the assignment to receive credit.

Once you have submitted both admissions.cpp to the autograder and responded to the reflection questions in the google form you will have successfully completed lab 2!