JMU CS488 - Computer Graphics Applications
Help Policies Solutions Study-Aids Syllabus Tools
Programming Assignment 2


1 Overview

For this assignment you must implement version 2 of the Vector class from programming assignment 1.

This assignment is both about vector arithmetic and about C++. With regard to the former, you must implement various operations. With regard to the latter, you must use return by reference, operator overloading, exceptions, and initializer lists.

2 Background

Though we've only discussed the special cases of 2-dimensional and 3-dimensional vectors in lecture (so that we can visualize them), most of the operations we've discussed are generalizable to \(n\) dimensions (which is must you must implement for this assignment).

Multiplication by a Scalar: Given \(\alpha \in \mathbb{R}\) and \(\bs{p} \in \mathbb{R}^n\), \(\alpha \bs{p} = (\alpha p_1, \alpha p_2, \ldots, \alpha p_n)\).

Addition: Given \(\bs{q} \in \mathbb{R}^n\) and \(\bs{r} \in \mathbb{R}^n\), \(\bs{q} + \bs{r} = (q_1 + r_1, q_2 + r_2, \ldots, q_n + r_n)\).

Subtraction: Given \(\bs{q} \in \mathbb{R}^n\) and \(\bs{r} \in \mathbb{R}^n\), \(\bs{q} - \bs{r} = (q_1 - r_1, q_2 - r_2, \ldots, q_n - r_n)\).

Inner Product: Given \(\bs{q} \in \mathbb{R}^n\) and \(\bs{r} \in \mathbb{R}^n\), \(\bs{q} \cdot \bs{r} = q_1 r_1 + q_2 r_2 + \ldots + q_n r_n\) (or, using summation notation, \(\bs{q} \cdot \bs{r} = \sum_{i=1}^{n} q_i r_i\)).

3 Detailed Specification

The specifications for the classes in this assignment are available in "documentation format". That is, you are being provided with the documentation for the classes, and your implementation must conform to the documentation.

Note that the setValues() method is now protected (rather than public) and has been overloaded with a version that is passed a pointer to an array of double values. Note also that the setValue() method has been eliminated.

4 Help with Initializer Lists

The begin() method returns a pointer to the first element of an initializer list. So, in the following example, values points to the first double (in the array of double values) that is associated with v.
void doSomething(std::initializer_list<double> v) {
    const double*  values;

    values = v.begin();

    // Work with the array
}

Remember to use the -std=c++17 flag when compiling (since initializer lists of this kind are a fairly recent feature of C++).

5 Unit Testing

You are responsible for testing your implementation. Since this assignment is fairly complicated, and assignments will be getting more complicated in the future, you should seriously consider using a unit test framework/harness.

There are several good unit testing frameworks/harnesses available for C++, and you should feel free to use one of them, but it may be easier to use a "home grown" system until you become more comfortable with C++.

The file UnitTest.hpp contains a very simple framework (that you will be able to expand on as you learn more C++) that allows you to make calls to assertEquals() functions as in JUnit, the file ExampleUnitTests.cpp contains an example of how it can be used, and the file ExampleMakefile contains a makefile that can be used to build the executable.

At this point, this framework won't let you test for exceptions or compare objects, but it should let you do most of what you need, and it should be easy to understand.

Though you will not be submitted your unit tests, hence will not be assessed on their coverage, you should probably use a test coverage tool to help ensure that your are covering your code adequately. See the course "Tools" and "Help" pages for more information.

6 A Development Strategy

Think carefully about how you should proceed, before you start writing and code. Obviously, you will need to make sure that your constructors are working properly before you can move on to any other methods/functions. Less obviously (since you may not have ever overloaded the assignment operator before), you will need to make sure that the assignment operator is working before you can move on to any other methods/functions. In addition, you will probably want to implement the relational == operator fairly early in the process.

As always, it is strongly recommended that you design, implement, debug, and test one method/function at a time.

7 Submission

You must submit a file named pa2.zip that contains just Vector.h and Vector.cpp using Autolab.

8 A Special Note About Collaboration on this Assignment

You may share code from your unit tests (only) with other students. However, if you include code in your unit tests that you did not write you must include a comment (for each test case) that credits the source. In either words, you may form a team to create test cases (to reduce the burden on any individual but still ensure that your code is adequately tested).

9 Grading

Points will be awarded as follows:

Copyright 2020