CS 202 Fall 2013  >  Assignment 6

CS 202 Fall 2013
Assignment 6

Assignment 6 is due at 2 p.m. Wednesday, November 13. It is worth 30 points.

Procedures

Complete each of the exercises below. Then turn in your work as follows.

  1. Run Check. Demonstrate the programs you have written for the exercises below to either the instructor (Glenn G. Chappell) or the T.A. (Zak Williams). Get official approval.
  2. Submission. Submit your code using Blackboard, under Assignment 6 for this class. You should only submit code that has already passed the Run Check. Be sure you attach your source/header files; do not paste them into the text box. Also, send only source & headers; no project files or executables.

We may not look at your homework submission immediately. If you have questions, e-mail me.

Exercises (30 pts total)

Do each of the following exercises. Coding standards are as on Assignment 3.

  1. Expand your work from Assignment 5 Exercise B as follows.
    • The base class should actually be an abstract class.
    • Write three new derived classes.
      • A class that converts each lower-case letter to “x” and each upper-case letter to “X”, leaving all other characters unchanged.
      • A class that converts each blank (“ ”) to an underscore (“_”), leaving all other characters unchanged.
      • A class that outputs each line backwards. This class should use a single Standard Library function call to reverse a string.
    • Your driver program should demonstrate the derived classes from your former work as well as the three new classes.
     
  2. From the Chapter 16 Programming Challenges (p. 1000), do exercise 1.
    • This problem mentions exercise 1 from chapter 13. Did you do this exercise? Yes, you did! It was Assignment 1 Exercise B.
     
  3. From the Chapter 16 Programming Challenges (p. 1000), do exercise 3.
    • Your driver program should demonstrate use of the templates with both numeric values (like int) and string values.
     
  4. From the Chapter 16 Programming Challenges (p. 1000), do exercise 4.
    • When you do your run check, explain whether your code works with strings, and why or why not.
     
  5. Write a program that does the following.
    • Input a filename from the user.
    • Read the file with the given name.
    • Print a (nicely formatted!) list of all the words in the file and how many times each word appears.

    The program must maintain running totals of word counts in a variable of type map<string, int>.

    Here, a word is what you get when you do something like “infile >> word;”, where infile has type ifstream, and word has type string. Two words are considered the same if they compare equal (“==”) as strings. So, for example, “dog”, “dog.”, and “Dog” are three different words, for the purposes of this exercise.

    When doing run checks, we may give you a new input file. Your program should work with any text file. A sample input file is available: a06e_input1.txt. If you run your program with this file as input, then it should give output with the following words and counts.

    WORD      COUNT
    ---------------
    How          4
    I            7
    can        553
    few          4
    form         8
    from         8
    many         7
    nonsense.    1
    sentences    7
    silly        1
    ways         2
    words        1
    words.       2
    words?       4


CS 202 Fall 2013: Assignment 6 / Updated: 7 Nov 2013 / Glenn G. Chappell