

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A handout for an assignment in the university of north carolina at greensboro's csc 330: advanced data structures course. The assignment, due on september 23, 2009, focuses on using associative containers, specifically maps, to work with character frequencies and contexts. Students are required to write two programs, count1.cpp and count2.cpp, which read character-by-character and update counts accordingly. For count1.cpp, students keep track of how many times each character occurs. For count2.cpp, students maintain a separate set of counts for each context, resulting in a map of maps. The assignment is worth 50 points and involves understanding map declarations and usage in c++.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


University of North Carolina at Greensboro Handout 5 CSC 330: Advanced Data Structures September 16, 2009 Prof. Stephen R. Tate
Objective: The objective of this assignment is for students to work with and show they under- stand how to use associative containers (course objective 5 from the syllabus). This program is shorter and less involved than others in this class, so this assignment will be graded out of 50 points — half the weight of other assignments.
High-Level Description: In the first assignment you wrote a program to figure out word fre- quencies: how often a word appears in a text file. In this assignment you are to consider character frequencies, but also consider the notion of “context” — in this case the “context” is the preceding character, so rather than counting the number of times the character “u” oc- curs (for example), you will count the number of times “u” follows “q”, how many times “u” follows “r”, and so on.
Details: You are to write two programs for this assignment, count1.cpp and count2.cpp. Both programs read the input (from standard input) character-by-character, and update counts after each character is read. Use cin.get() for character input. For count1.cpp you are simply to keep track of how many times each character occurs. This is a basic map<char,int> object that increments the count as each character is seen. At the end of the program, print out each character and the number of times it occurs. For count2.cpp you are to keep a separate set of counts for each context — in other words, for each character “context” (meaning the previous character) you will have a complete set of counts. This is a map of maps — and part of this assignment is to figure out exactly what that means as a C++ map declaration, and to use it in your program. At the end of the program, print out each pair of characters and the count of the number of times that pair occurred. See the sample input and output on the back of this handout and follow the basic form shown there for your program’s output.
To Turn In: Use the 330submit program (see Handout 3) in order to turn in your code, using assignment name assign2. You should submit all of your code (for both programs) so that it can be compiled and tested. On the due date, you should turn in a printout of your code.
2 Handout 5: Assignment 2 — Using Maps
Sample Input/Output:
Whammer Jammer
a: 2 e: 2 h: 1 m: 4 r: 2
(J,a): 1 (W,h): 1 (a,m): 2 (e,r): 2 (h,a): 1 (m,e): 2 (m,m): 2 (r, ): 1 (r, ): 1