CS 311 Fall 2020  >  Project 6


CS 311 Fall 2020
Project 6

Project 6 is due at 5 pm Thursday, November 5. It is worth 60 points.

Procedures

This is, optionally, a group assignment. You may work in a group of 2 or 3, if you wish. Each group only needs to turn in a single copy of the assignment. Under normal circumstances, each group member will receive the same grade on the assignment.

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

If you work in a group:

Exercises (60 pts total)

General

In each of the following exercises, you are to write a function template or class template. All code must be in file dp6.h. Since everything you write will be a template, there will be no source file.

Each exercise will make use of the Linked List in file llnode2.h (in the Git repository). Do not duplicate the code in this file; instead, do “#include "llnode2.h"”. And do not modify file llnode2.h.

Your code must reference Linked List nodes via unique_ptr. All creation of nodes must be done via make_unique. You may not use new or delete. You may use any C++ Standard Library functionality you wish.

Be sure to follow the coding standards. All standards now apply!

Test Program

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

Note that your code will not compile with the test program unless all required functions and classes exist. Therefore, you must write dummy versions of all functions—at least—or your work will not be graded.

The test program requires doctest.h, the header for the doctest unit-testing framework, version 2.

Do not turn in the test program, file llnode2.h, or the doctest framework.

Exercise A — Reversing a Linked List

Purpose

In this exercise, you will write an efficient reversing function for a Linked List.

You will make use of smart-pointers.

Instructions

Write a function template reverseList, prototyped as follows.

[C++]

template<typename ValType>
void reverseList(unique_ptr<LLNode2<ValType>> & head);

This function is given a unique_ptr to a Linked List—an empty unique_ptr if the list is empty. It alters the list so that the values appear in reverse order. A pointer to the new list is returned via the reference parameter.

Function reverseList must meet the following requirements.

Exercise B — Associative Dataset Class Template

Purpose

In this exercise, you will write a class template that uses a Linked List to hold an associative dataset. This is not a terribly good way to implement such a dataset; we will cover better ways later in the semester.

As in the previous exercise, you will also make use of smart-pointers.

Background

An associative dataset is one in which items are looked up by key. Often there is a value associated with each key; in this case the dataset consists of a number of key-value pairs.

Instructions

Implement a C++ class template that manages an associative dataset consisting of key-value pairs. The types of the keys (the key type) and associated values (the data type) should be specified by the client.

Duplicate keys should not be allowed. Determining whether two keys are the same should be done using the equality (==) operator.

It is not expected that LLMap will be terribly efficient. Indeed, the requirements of Exercise B make high efficiency impossible. And much of the rest of the semester will be devoted to how we might do better. But you should write reasonable code, which is not unduly inefficient within the requirements of this exercise.