Assignment 0


Important dates

Assigned16 Sep 2016 @ 16:59h
Due23 Sep 2016 @ 23:59h


Warm up your programming skills and make sure you can submit assignments though Subversion.

In this first assignment, you need to recall how to write a function that deals with local variables and an array. You will also need to learn how to submit code through the revision control system called Subversion. We will explore Subversion in Lab 1, but in the meantime, you should read the first two parts of Lab 1’s “Theory” section.

Remember, assignments are individual work: you must complete the assignment yourself.

Start with the following header file:

This file contains the declaration for the average function. You should define this function in a file called average.cpp.


The function that you wrote won’t do much by itself: it needs to be incorporated into a larger program. This program might be a large, complex application with a sophisticated user interface and lots of “moving parts” — this can make it difficult to test that your code is working correctly. One approach to make testing more practical is to test small units of code by themselves, hence the name unit testing.

We will employ a unit testing approach for “real” assignments, but for this test assignment we can approximate the approach by compiling average.cpp together with the following test code:


You can write your assignment code in a C++ IDE if you like, but I would also encourage you to explore the command line (and I will require it in the labs). To compile your C++ function into a complete program at the command line, type:

engi3891$ c++ -std=c++11 average.cpp test0.cpp -o test

Here’s what this command line means:

Run the C++ compiler. This may be spelled g++ on some versions of Linux or using the MinGW environment on Windows.
Use the C++11 standard rather than C++98. This allows you to use nice, modern C++ features like we’ll discuss in our lectures.
average.cpp test0.cpp
These are the C++ files that we want to compile.
-o test
Save the compiled program as test.


Finally, you can run the resulting test program by running ./test. You should see output like this:

engi3891$ ./test
The message you have chosen to display is: 'Hello, world!'.


You should submit your code to your personal Subversion directory (/engi3891/2016/students/${username}). This directory is for your individual work, and assignments are individual work. Use the svn add and svn commit commands from Lab 1 to put the average.h and average.cpp files into a directory called assignments/0/ within your personal directory. After you commit your work, you shold receive a confirmation email and you should be able to see your submitted work in a browser at /viewvc/engi3891/2016/students/${username}/assignments/0/average.cpp.