CSCI 261 - Programming Concepts (C++)

Spring 2017 - Assignment 06 - Word Counting

Quick Links: Blackboard | Canvas | CS @ Mines | Cloud9 | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |
This assignment is due by Tuesday, February 28, 2017 11:59pm.


Instructions


For this assignment, we will ask the user to enter a series of strings. These strings could be a single word or be an entire sentence. We will then count the occurence of each word they entered and print out a histogram of word counts, sorted in alphabetical order.

The first step will be to continually ask the user to enter text until they enter the string "Done" to signal they are finished. Every time the user types a sentence, we will need to break the sentence into each of its individual words. We'll then need to do two things with these words:
  1. Keep a list of all the individual words the user has entered
  2. Keep a count of how many times the user entered that particular word
Hmm, this sounds like a perfect job for a couple of vectors!

When the user signals they are finished entering text (by typing "Done"), we will then sort all of the words the user entered into alphabetical order.

Once the words have been alphabetized, we'll print the words in alphabetical order along with a series of x's denoting each time the word was entered. See the following sample output:

Enter a sentence or "Done" to finish: The quick brown fox jumped over the lazy dog 
Enter a sentence or "Done" to finish: I would like to have the dog
Enter a sentence or "Done" to finish: The dog is my friend
Enter a sentence or "Done" to finish: A friend is a terrible thing to waste
Enter a sentence or "Done" to finish: dog dog dog dog dog
Enter a sentence or "Done" to finish: Done
        A : x
        I : x
      The : xx
        a : x
    brown : x
      dog : xxxxxxxx
      fox : x
   friend : xx
     have : x
       is : xx
   jumped : x
     lazy : x
     like : x
       my : x
     over : x
    quick : x
 terrible : x
      the : xx
    thing : x
       to : xx
    waste : x
    would : x

A couple of points to note about the output:
  • When the words are sorted, the associated counts need to be ordered as well. This means we cannot use the built-in sort() method, we'll need to write our own
  • All of our words are right aligned allocating enough space for the longest word the user entered
  • Capital letters come before lower case letters alphabetically (why?)
  • When sorting, you'll need to do some swapping. Look to zyBooks 4.6 for review


Hints


  • We're going to need two vectors, each storing a different type of data
  • Dr. Paone's solution was 61 lines long. I used three sets of nested loops to accomplish the three main steps (input, sorting, printing).
  • Speaking of steps, pseudocode pseudocode pseudocode. Break the problem down into smaller steps. Implement one step at a time.
  • Loops and vectors work well together! Loops and vectors work well together!


Functional Requirements


  • The words must be right aligned allowing enough space for the longest word entered.
  • A single x should correspond to a single occurrence of a word.
  • You will not be able to use the STL sort method


Grading Rubric


Your submission will be graded according to the following rubric.

Points Requirement Description
6 Labs completed
13 Assignment meets functional requirements outlined above
4 (1) Comments used (2) Coding style followed (3) Appropriate variable names, constants, and data types used (4) Instructions followed (5) Assignment compiles


Submission


Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.

In summary, for homework due on Tuesday, February 28 follow these specific steps:
  • create a directory called week06.
  • within week05, create four subdirectories: Lab06A, Lab06B, Lab06C, and A06.
  • within your new week06/Lab06A directory, copy in your main.cpp file from your Lab06A solution.
  • within your new week06/Lab06B directory, copy in your main.cpp file from your Lab06B solution.
  • within your new week06/Lab06C directory, copy in your main.cpp file from your Lab06C solution.
  • within your new week06/A06 directory, copy in your main.cpp file from your A06 solution.
  • compress the week06 directory (see Step 3 here for details).
  • submit the week06.zip file to Blackboard (see Steps 5-10 here for details).
  • after you submit, download the file and double check it contains all that you think it contains!

This assignment is due by Tuesday, February 28, 2017 11:59pm.
Last Updated: 01/01/70 00:00


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0