Please Write C++ PROGRAM : That will write a program that initially prompts the user for...

50.1K

Verified Solution

Question

Programming

Please Write C++ PROGRAM :

That will write a program that initially prompts the user for afile name. If the file is not found, an error message is output,and the program terminates. Otherwise, the program prints eachtoken in the file, and the number of times it appeared, in a wellformatted manner. To accomplish all this, do the following:

- Open the file - the user must be prompted anda file name input. DO NOT hardcode a filename.

- Read the words in the file, placing them inan array of struct with capacity I 00, where each struct has astring (the word) and an int (number of occurrences)

- Sort the array, eliminating duplicates

- Report the results

- You must write appropriate functions for each task. Atminimum, you must write a function for each of thefollowing:

• Open the file:

o    Pass in an ifstream (must be a referenceargument [what type of parameter is it?]). The function prompts theuser and, if the file is found, it returns true and theifstream will be a handle for that text file. Otherwise thefunction returns false , and the argument isassumed to be undefined.

• Populate the array of struct with the words in thefile:

o    Pass in two reference arguments, theifstrcam, and the l 00 element array of word/count structs. Whenthe function completes, the array will hold the words in thefile.

• Output results:

o    Pass in the variables that bold the filename and the word/count array. Use this data to

produce the desired ouput, which should be appropriatelyfonnatted.

• Sort an array of structs (the name/int pairs),eliminating duplicates:

o    Pass in the array of struct, and the numberof elements in the array. The function sorts the array, inascending order of words, eliminating duplicates and tabulatingcounts as it goes. It definitely uses other functions for specificpurposes, e.g. identifying duplicate tokens and swappingstructs.

• Increment the counter member of a struct that holds aword and its multiplicity:

o    Pass in a single struct; it will bean import/export parameter. Simply increment its countermember.

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

Notes:

» A word, or token, is whatever is read using the>> operator. A word followed by a period is distinct from thesame word without the period. Words are also case sensitive, i.e.heLLo is not equal to Hello.

» When a word is placed into the array of struct, its counter isinitially 1.

» When the array reaches capacity:

If there aren't 100 unique words already in the array, run thesort function to eliminate duplicates.

If the file has 100 unique words, then after the tooth uniqueword is added to the array, only repeats will be tabulated. Newtokens will be discarded.

» While several functions are required, other functions shouldbe written as well.

No function..should handle multiple tasks on its own.Non-modular designs will be penalized.

» In sorting, if the word being placed is aduplicate, the already placed word must have its counterincremented, and the duplicate must be removed from the array.

- The program must be well written, properly indented,and commented

Answer & Explanation Solved by verified expert
4.3 Ratings (941 Votes)
PROGRAM CODE WordCountcpp Created on 22Feb2017 Author kasturiinclude include    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students