CS 311 Fall 2024  >  Assignment 8


CS 311 Fall 2024
Assignment 8

Assignment 8 is due at 5 pm Thursday, December 5. It is worth 60 points.

Procedures

This is, optionally, a group assignment. You may work in a group of two, 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 Canvas site, under Assignment 8 for this class.

If you work in a group:

Exercises (60 pts total)

Exercise A — Program: Counting Words

Purpose

In this exercise, you will write a program that uses a C++ STL Table implementation. Your program will also read information from a file. Robustness and proper error checking are an important part of the assignment.

Background

For the purposes of this exercise, a word is a contiguous sequence of one or more non-space characters.

For example, consider the following.

xyz/ xyz123 xyz
xyz123 xyz abc

Four distinct words appear in the above text. They are, in lexicographic order, abc, xyz, xyz/, and xyz123. The words xyz and xyz123 each appear twice. The other words each appear once.

Instructions

Write a complete C++ program (including function main!) that inputs a filename from the user, and reads the named file. The program should then print the number of distinct words that appear in the file, followed by a list giving, for each word appearing, the word itself and the number of times it appears in the file, as shown below. Be sure to follow the coding standards. All standards now apply!

Testing

Since you are writing a complete program this time, there will be no test program. However, I have created a test input file: wordcount_test.txt. (This file is also in the Git repository.) If you run your program with this file as input, then it should output the following.

Number of distinct words: 45

2024: 1
2024-11-21: 1
311: 1
8,: 1
A: 1
And: 1
Assignment: 1
CS: 1
Can: 2
Chappell: 1
Exercise: 1
Fall: 1
For: 1
G.: 1
Glenn: 1
Next: 1
Test: 1
What: 1
a: 3
again.: 1
change: 2
correctly: 2
count: 2
ending: 1
file: 2
for: 1
if: 1
input: 1
is: 2
it: 1
line-ending: 1
line.: 1
line?: 1
long: 2
marker?: 1
newline?: 1
no: 1
the: 1
there: 1
we: 2
when: 1
with: 1
word: 100000
wordcount_test.txt: 1
you: 2

Do not turn in wordcount_test.txt.

Note that I may test your program using a different input file.

Hints

Exercise B — Writing a Test Suite

Purpose

In this exercise, you will write a test suite for a simple C++ class. You will use the doctest testing framework.

Background

Consider a class Reverser. And objects of this class is a function object that takes two bidirectional iterators defining a range. It reverses the order of the values in the range.

An object of type Reverser might be used as follows.

[C++]

Reverser rr;
deque<int> dd { 1.2, 5.2 };
rr(begin(dd), end(dd));  // Now dd contains 5.2, 1.2

A complete, correct definition of class Reverser can be found in file reverser.hpp, in the Git repository.

Instructions

Modify the posted file reverser_test.cpp so that it, along with doctest.h, forms a thorough test program for class Reverser, contained in header file reverser.hpp.

Do not turn in files doctest.h or reverser.hpp.

Hints