CS 311 Fall 2020  >  Project 2


CS 311 Fall 2020
Project 2

Project 2 is due at 5 pm  Tuesday, September 15  Thursday, September 17. It is worth 60 points.

Procedures

This project is to be done individually.

Turn in answers to the exercises below on the UA Blackboard Learn site, under Project 2 for this class.

Exercises (60 pts total)

Exercise A — Moderately Smart Array Class

Purpose

In this exercise, you will write an array class. It will not be quite as “smart” as it could be (std::vector is much smarter), but it will be much better than a built-in C++ array; for example, it knows its size, and has copy operations.

Key to this project is proper management of a resource in a class. Be sure you have no resource leaks, and that ownership and related issues are properly documented.

And as before, make your code high quality. In particular, follow the applicable coding standards.

Instructions

This project is to be done individually.

Implement a C++ class template that manages and allows access to a fixed-size array. The type of item in the array and the number of items in the array should be specified by the client code. Be sure to follow the coding standards. Standard 4A (“Requirements on template parameter types must be documented.”) now applies. You do not need to follow standards 4B, 4C, or 4D.

Example Code

Here is some code using MSArray. Some of it will not compile, as noted.

MSArray<int> ia(8);           // Array of 8 ints
MSArray<int> iax;             // Another array of 8 ints
MSArray<double> da(40, 3.2);  // Array of 40 doubles; each is set to 3.2
MSArray x(8);                 // DOES NOT COMPILE; no template parameter

// Set all items (counter loop)
for (int c = 0; c < ia.size(); ++c)
{
    ia[c] = c * c;
}

// Range-based for-loop calls MSArray member functions begin, end
for (auto x : ia)
{
    cout << "Item :" << x << endl;
}

const MSArray<int> ia2 = ia;  // Copy constructor
if (ia2 == ia)                // Condition should be true
    cout << "Equal!" << endl;

MSArray<double> da2;
da2 = da;                     // Copy assignment
da2 = ia;                     // DOES NOT COMPILE; different value types

if (da == ia)                 // DOES NOT COMPILE; different value types
    cout << "blah blah" << endl;

Test Program

A test program is available: msarray_test.cpp. If you compile and run the test program (unmodified!) with your code, then it will test whether your code works properly.

The test program requires doctest.h, the header for the doctest unit-testing framework, version 2. This file may be downloaded from the doctest GitHub site.

Do not turn in the test program or the doctest framework.

Note. As before, the test program does not check all of the requirements of the project. Some of these cannot be checked by a test program.

Thoughts