Strings, Structs & Files (CSC100) solved

Strings, Structs & Files (CSC100) solved

Strings, Structs & Files (CSC100)
Name your C++ source code file:data.cppOverview of Problem: Read a text file to create an array containing one structured element foreach unique word found in the file, as well as the number of times that word appears in the fileregardless of case. Use this array to calculate and display the statistics described below.A text file contains English text, such as essay.txt available as example input to your program forthis assignment. Your program must read the contents of such a text file, store the unique wordsand count the occurrences of each unique word. When the file has been completely read and thearray of unique word structs has been set, print the words in sorted (alphabetical) order and thenumber of occurrences of each word to an output text file. After this output file has been createdand the list of words written to the file, the following statistics must also be written to the outputfile:·Total number of words read·Total number of unique words read·Average length of a word (as a floating point value)·Average occurrence of a word (as a floating point value)·Most commonly occurring word(s)You can see anexample input file and its corresponding output file produced by your codehere.NOTE: Throughout this assignment (and this course!), when the data type,string, ismentioned, you are expected to use a c-string, which is anarray of char. Do not use thename,string, as a data type directly. To make a variable a string, declare it as an arrayof char.Processing Requirements:·You will need to prompt the user for the name of the input text file. From this name youare to create the name of the output text file. The output text file should have thesamename, but use the extension:.out. So if the input file is named:test.txt, then the outputfile should be namedtest.out. Do not prompt for the output file, create it using the inputfile name. The names of the files are strings, i.e.,arrays of char.·Close the input file when you have completed reading and close the output file when youhave completed writing

In addition to the title at the beginning of the program and the prompts to the user for thename of the input file, print to the screen identification of the different steps happeningduring the processing. As there is no other output to the screen, this is helpful inidentifying the progress of the program.·Use an array of structs to hold the words and word counts. Define a struct to hold a string(array of char) and a count (integer). Your main function will then declare an array ofthese structs. Assume that a word has a maximum length of 20 characters ,so the string(array of char) size must be 21 to allow for the null character.·All words stored in the array should be stored in all lowercase. So, if a word appearscapitalized in one place and in lowercase in another place, these two occurrences count astwo occurrences of the same word, not two different words. See handling of the words"This and "this" in theexample output.·Declare the array of structs in the main and pass it as a parameter to the other functions.Declaring this array as a global variable is not acceptable. Novariables should be global,except for named constants.·Break your code into meaningful functions that are short and perform only one, well-defined, easily-understood function.·You must use the linear search algorithm to determine if a word is in the array.Remember that the array is an array of structures and that the key is a string (array ofchar) so the string comparison function,strcmp, must be used. The search task should bea separate function that accepts the array of structs, the number of items currently in thearray, and the string value (a word) for which to search. The search function shouldreturn the position (index, subscript, an integer) of where in the array the value (word) isfound or a -1 if not found. The search function must have only onereturn statement.·Use the selection sort algorithm (given in the array module) to sort the array of structs .To use the given algorithm, you must change it from handling arrays of integers tohandling an array of struct. The items being compared will be strings (arrays of char),which will require the use of thestrcmpfunction.·Use good programming style. You will, as usual, be graded on: documentation of theprogram and functions (each function should have its own comment prolog), names ofvariables, indentation of statements, correct use of loops, correct use of structs andfunctions and everything else that you learned about this semester!·Functions are limited to a length of about 25 statements (not including declarations). Usegood modularization criteria to divide longer functions into sub-functions.·The example programs in this module demonstrate both reading from and writing to afile. Awordis defined as one or more characters terminated by one or more spaces, theend of a line, or the end of a file. Your program should also remove any punctuation
Powered by