ESc 014

Lab 1 -- Grade Counter
Thursday, April 4, 2002


Lab summary

Given a data file of letter grades (A, B, C, D, F), write a program that will count the number of grades there are of each type.

Getting the data file from a machine running UNIX

In this course, you'll interact with a machine running a different operating system (OS) than Windows. The UNIX OS is not a "click-and-drag" interface the way Windows is, but it can still do everything Windows can (store files, run C++ programs, etc.) Files are stored hierarchically in UNIX using directories in the same way that Windows uses folders (and subfolders) to store files. For example, in UNIX, the file "sample.txt" might be stored in the directory /public/classes/myfiles. This means that there is a directory (think folder) called public containing a directory called classes containing a directory called myfiles. And in the myfiles directory is the "sample.txt" file.

All external files that you'll need for labs will be stored on a machine called blackduck running the UNIX OS. You can transfer the files to your local PC using the "SSH Secure File Transfer" application. You can launch it from your desktop. Once its running, do the following:

  1. Under the File menu, click Connect...
  2. In the dialogue box that appears, type in for the host. Then type in your username (same as your user name in your union email address).
  3. Type in your password. It will be "esc014" and then your username (with no spaces in between).
  4. Click OK.

You should now be logged into blackduck. The right-hand window shows all of the directories and files in your account on blackduck. All you have to do now is get to the correct directory and transfer the files. Do the following:

  1. You should see a directory named "esc014pub". Go into this directory by double-clicking on it.
  2. Inside the "esc014pub" directory is another directory called "lab1". This is the directory you need for your lab. Download this from blackduck by dragging the entire lab1 folder to your desktop -- put it in the DesktopAnnex folder where all temporary files should go.
  3. You've just transferred the file! You can make sure it worked by going to the DesktopAnnex folder on your desktop, opening it, and looking for a folder named "lab1". That's the directory you just transferred! Inside should be a text file named "examdata.txt". That's the data file you need for this lab.
  4. Once you are sure that the transfer worked, you can exit the file transfer application.
Notice how the file transfer application let you transfer files between machines using a "click-and-drag" method, even though the UNIX OS itself does not have such an interface. Later in the course, we'll use the UNIX OS directly so you can see and use this very different interface for yourself.

Count the Grades

Now that you have the data file on your PC, it's time to get to the programming part of this lab. The file is a list of letter grades: A, B, C, D, or F, one grade on each line. You may want to open the data file just to see what the input looks like. There are three important things to note about this file:

  1. There are no + or - grades. Just whole letter grades.
  2. Grades may be listed using capital or lower-case letters.
  3. There may be invalid entries in the file (something not A, B, C, D, or F).

You are to write a program that uses a switch statement to count the total number of each grade and display the totals to the user. The total number of As should include both capital and lower-case As. The other grades should be treated similarly. The total number of invalid entries should also be displayed. Be sure to name your program with your FULL NAME along with the lab number. For example, I might name my program chrisfernandes_lab1.cpp

How to turn in this lab

In all labs, you will be graded on the correctness of your implementation, neatness, presentation, and style of your program code, and good use of the C++ language. It's important to comment your code where appropriate and to do little things like space things properly, use readable indentation, and also to make sure the overall design and logic of the program are coherent.

You should turn in a hard copy of your source code with the output appended at the bottom as a comment. For practice, you'll also turn this lab in electronically on BlackBoard. Go to and drop your source code (just the .cpp file) into the dropbox as demonstrated by your instructor. Be sure the file is named with your FULL NAME and lab number!

Return to Lab Index