Question: C++ Objctivs: 1) Undrstand and us rcursion; 2) Undrstand and implmnt binary trs Ovrviw: Writ a program that rads an input txt fil and counts

C++

Objctivs: 1) Undrstand and us rcursion; 2) Undrstand and implmnt binary trs

Ovrviw: Writ a program that rads an input txt fil and counts th occurrnc of individual words in th fil. You will us a binary tr to kp track of words and thir counts.

Dscription: Th program should opn and rad an input fil (namd input.txt) in turn, and build a binary sarch tr of th words and thir counts. Th words will b stord in alphabtical ordr in th tr. Th program should ignor th cas of th words, so that Branch and branch ar considrd th sam. Howvr, words that ar actually splld diffrntly such as tr and trs ar considrd to b diffrnt, and should b stord in sparat nods. All words will b stord in th tr in thir lowrcas form. Hlp is providd on how to accomplish this.

Two forms of quris ar to b supportd by th tr class:

1. A qury for an individual word should rturn th numbr of occurrncs of that word in th input fil, as rtrivd from sarching th tr, or should display a mssag stating that th word was not found in th tr.

2. A qury for words that mt or xcd a thrshold numbr of occurrncs, should rsult in th output of th words (and thir counts) that mt that critria, using inordr tr travrsal.

Th nods for th word tr should b a struct with th following mmbrs

a. A string containing th word itslf.

b. On pointr ach for th lft and right subtrs.

c. An int containing th count of th numbr of occurrncs of th word.

Rquirmnts:

Your program must b split into 3 fils. Thr will b a class (with sparat intrfac and implmntation fils), and a drivr fil. Th rquirmnts for ths ar spcifid blow:

a) Th WordTr class This class rprsnts a word binary sarch tr

- Fils must b namd WordTr.h and WordTr.cpp

- Class must b namd WordTr

- You should implmnt th following mmbr functions in th class

- A constructor Crats an mpty tr

- A dstructor Rcursiv function that xplicitly rlass all nods allocatd during program xcution. You may not rly on program trmination to rlas mmory.

- insrt Rcursiv function that adds a word to th tr, if it is not found, or incrmnts its count if it is alrady in th tr.

- findNod accpts a string argumnt (a word) and sarchs for th word in th tr. This function should b public, but should call a privat function, so as to not xpos th trs root, its implmntation, tc. If found, outputs th word and its count. Othrwis displays a mssag stating that th word was not found.

- printInOrdr Rcursiv function that accpts a singl intgr argumnt (a thrshold valu), and travrss th tr in ordr, outputting th words (and thir counts) that mt or xcd th thrshold count. Th function should also output th numbr of nods mting th critria (s sampl output).

b) A drivr, or clint, fil that

- Must b namd main.cpp

- Instantiats th word tr objct

- Opns and rads th txt fil namd input.txt and builds th word tr from th fil by invoking th insrt function dscribd abov. Th input fil should contain a singl lin of alphabtic charactrs (no numbrs or punctuation). It should b split using a singl spac charactr via th providd function or on you writ. Car should b takn to nsur that multipl squntial spacs and trailing spacs ar not prsnt in th fil/lin to b rad. xampl fil: This is th whol fil and is stord and rad as a singl lin into a string

- Invoks quris for individual words, or for words whos counts mt or xcd a thrshold numbr of occurrncs, as shown in th sampl output blow.

2. Sampl output:

a) This output shows th program xcution of primary functionality using a fil containing xcrpts from an arlir vrsion of this assignmnt. That txt is supplid to aid you in validation/tsting

C++ Objctivs: 1) Undrstand and us rcursion; 2) Undrstand and implmnt binary

input.txt file used in assignment specification Project description The program should open and read input file named input.txt in turn building up a binary search tree of words and counts as it progresses The words will be stored in alphabetical order in the tree The program should ignore the case of the words so that Branch and branch are considered the same However words that are actually spelled differently such as tree and trees are considered to be different and should be stored in separate nodes All words will be stored in the tree in their lowercase form Two forms of queries are to be supported by the tree class A query for an individual word should return the number of occurrences of that word in the input file as retrieved from searching the tree or should display a message stating that the word was not found in the tree A query for words that meet or exceed a threshold number of occurrences should result in the output of the words and their counts that meet that criteria using inorder tree traversal The nodes for the word tree should be a struct with the following members One pointer each to the left and right subtrees An int containing the count of the number of occurrences of the word A string containing the word itself Requirements Your program must be split into files There will be a class with separate interface and implementation files and a driver file The requirements for these are specified below The WordTree class This class represents a Word Binary Tree Files must be named WordTree.h and WordTree.cpp Class must be named WordTree You should implement the following member functions in the class A constructor Creates an empty tree A destructor Recursive function that explicitly releases all nodes allocated during program execution You may not rely on program termination to release memory insert Recursive function that adds a word to the tree if it is not found or increments its count if it is already in the tree findNode accepts a string argument a word and searches for the word in the tree If found outputs the word and its count Otherwise displays a message stating that the word was not found printInOrder Recursive function that accepts a single integer argument a threshold value and traverses the tree in order outputting the words and their counts that meet or exceed the threshold count The function should also output the number of nodes meeting the criteria A driver or client file that Must be named proj6.cpp Declares the word tree object Opens and reads the text file named input.txt and builds the word tree from the file by invoking the insert function described above Invokes queries for individual words or for words whose counts meet or exceed a threshold number of occurrences 

-------------------- code to transform string to lowercase //transforms a string to lowercase - must include  // text is a string std::transform(text.begin(), text.end(), text.begin(), ::tolower); -------------------- function to split a string with a delimiter and load individual tokens into a string vector // From book "C++ Cookbook" by Jeff Cogswell, Jonathan Turkanis, Christopher Diggins, D. Ryan Stephens // Splits a string s, using character c as a delimeter, and places individual words into a vector of strings void split(const std::string& s, char c, std::vector<:string>& v) { std::string::size_type i = 0; std::string::size_type j = s.find(c); while (j != std::string::npos) { v.push_back(s.substr(i, j-i)); i = ++j; j = s.find(c, j); if (j == std::string::npos) v.push_back(s.substr(i, s.length())); } } 

ord tree built an oad Finding all words with 4 or more occurrences: a(20 and 16) are class (6 count(4> counts for7 found 4 Function 5 in K13) meet 4 must 4> named 5) nodes (4> not(4) number(5 occurrences should9 that 13 the C45) threshold Searching for 0ccurrences of the wod uery The word query occurs 2 time in the text earching for occurrences of the word 'stack

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!