第6次上机作业题目

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Count the number of the words in files Prerequisites, Goals, and Outcomes

Prerequisites: Students should have mastered the following prerequisite skills.

∙binary tree– Know how to construct and traverse a binary tree

∙File I/O– Opening, reading and writing a text data file

∙Dynamic Memory Management - Use of new and delete

Goals: This assignment is designed to reinforce the student's understanding of binary tree. Outcomes: Students successfully completing this assignment would master the following outcomes.

∙Define a class of objects and operations on those objects.

∙Build a massive, recursive data structure comprising those objects.

∙Search for an item in that data structure and, if it is not found, add it to the structure.

∙Create a file for your output and write to it.

∙Put together a non-trivial program in C++.

Description

Your program must accept an indeterminate number of arguments on the command line, the first of which specifies the output file and the remaining of which specify the input files. For example, the arguments may like this:

outputFile inputFile1 inputFile2 ...

With these arguments, the program would open and read each of the input files in turn, building up a binary tree of words (You should keep the tree be a complete binary tree when building up it) and counts as it progresses. Once all files have been read and closed, it must create the output file and write out the words in the tree(You should traverse the tree with 6 methods: in-order, pre-order and post-order, both recursive and non-recursive), one word per line, along with the number of occurrences of that word. Your program should ignore the case of the words, so that ―This‖ and ―this‖ are considered the same. However, words that are actually spelled differently —such as ―car‖ and ―cars‖ — are considered to be different words. For example:

If the input files are:

1.txt: My name is A.

2.txt: I am a student.

The tree you built up should look like the following:

And the outputs maybe like this:

Pre-order:

1 my

1 name

2 a

1 i

1 is

1 am

1 student

In-order

1 a

1 name

2 i

1 my

1 am

1 is

1 student

Post-order

1 a

1 i

2 name

1 am

1 student

1 is

1 my

-------------

7 Total number of different words

To allow for very long input files, the field width of the number of occurrences of each word should be at least six decimal digits. You should also total and print the number of distinct words.

Implementation in C++

相关文档
最新文档