130 likes | 244 Views
This C++ programming assignment requires you to create a program that reads one or more text files, builds a binary tree of words, and produces an alphabetical list displaying each word along with its occurrence count and the total number of distinct words. The program must handle case-insensitivity and differentiate between words spelled differently. Implement classes for the binary tree and nodes, following guidelines from provided textbook chapters. Final submissions must be zipped and include README and output files.
E N D
Programming Assignment #4Binary Trees CS-2303System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan and Ritchie and from C: How to Program, 5th and 6th editions, by Deitel and Deitel) Programming Assignment #4
Assignment • Write a C++ program to • Read one or more text files • Build up a binary tree of words in those text files • Print out alphabetical list of words and number of occurrences of each word • Also total number of words • In Visual Studio 2008 Programming Assignment #4
Reading • Deitel & Deitel, Chapter 19 • Especially §19.7–19.9 • Review Binary Trees • Previous courses • K&R §6.5 • D&D §12.7 Programming Assignment #4
This Assignment • Command line program ./PA4 outputFile inputFile1 inputFile2 ... • Open and read each input file in turn • Scan for words • Store each word in binary tree • Increment count of words previously seen • Open and write to output • List of words • Count for each word • Total number of distinct words Programming Assignment #4
Example Output 166 a 25 and 11 as 3 command 15 each 2 file 4 files 109 in 4 input 98 it 99 of 3 open 6 program 18 read 152 the 41 this 3 under 30 would------------- 17 Total number of different words Programming Assignment #4
Notes • Upper and lower case words are the same • “This” and “this” • Related words that are spelled differently are different • “Car” vs. “cars” Programming Assignment #4
Guidance • Think through this problem in Java • Use as inspiration and guideline for C++ implementation • One or more class interface files (.h) • A corresponding class implementation file (.cpp) for each class interface • One or more .cpp files for main() and other non-class functions Don’t use templates from StandardTemplate Library! You must build your own classes! Programming Assignment #4
Suggestion • class treenode • Members:– • Pointers to left and right subtrees • int count • string word • Constructor, destructor • Add to or access left and right subtrees Programming Assignment #4
Suggestion (continued) • class binaryTree • Members:– • root • Constructor, destructor • Methods to traverse tree, insert into tree, etc. Programming Assignment #4
Test Files • Provided in project assignment Programming Assignment #4
Submission • Build in Visual Studio • If working on Mac or other system, port to VS at least one day prior to due date • Make clean before submitting • Zip files together so grader can unzip and build • Project name:–PA4 • Submit zip file, README, output from test cases Programming Assignment #4
Additional Notes • See notes at the end of Programming Assignment document • Command line arguments (same as in C) • Input and Output streams • Not in Deitel and Deitel! • Formatted output Programming Assignment #4
Questions? Programming Assignment #4