Question

Implement the histogram function to complete the desired program. You must use dynamically allocated arrays for...

Implement the histogram function to complete the desired program.

You must use dynamically allocated arrays for this purpose.

For your initial implementation, use ordered insertion to keep the words in order and ordered sequential search when looking for words. Note that the array utility functions from the lecture notes are available to you as art of the provided code.

Although we are counting words in this program, the general pattern of counting occurrences of things is a common analysis step in laboratory work, statistical studies, and business tasks. The results of such a program are often fed into other programs for further processing and/or display. Such results are often displayed as histograms. The CSV output format is a common “data exchange” format recognized by many programs. Almost all spreadsheets, for example, will read CSV files.

When you have the program running, execute it using a short paragraph of text as an input, saving the output in a file ending with a “.csv” extension. Run a spreadsheet program (e.g., Microsoft Excel). You should be able to load your .csv file directly into the spreadsheet.

Try displaying your results as a histogram. In Excel, for example, select the two columns of data, choose “Sort” from the Data tab and sort your data on the numeric column. Then, with the two sorted columns of data still selected, go to the Insert tab and select a 2D Bar chart. Save your spreadsheet in Excel (.xsl) format. You will turn this in later.

As documents get larger, the total number of words increases far, far faster than does the number of distinct words. Our personal vocabularies are only so large, after all. In fact, most writers unconsciously limit themselves to writing with a small fraction of their personal “reading” vocabularies. So most words in a large document are bound to be repeats. That means that, for this application, the speed of the functions for searching for words is probably more important than the speed of the functions for inserting new words into the array. We do many more searches than insertions.

Try running your program on one of the large text files provided in the assignment directory. Time it to see how long it takes. Now replace all uses of ordered sequential search by calls to the binary search function. Run it on the same output, timing it again. You should see a substantial improvement.

Problem Description:

Develop a program to prepare a list of all words occurring in a plain-text document, counting how many times each word occurs. In determining whether two words are different, punctuation (non-alphabetic characters) other than hyphens and differences in upper/lower case should be ignored. Portions of text that cannot be interpreted as words (e.g.: “ !@#%* ”) should be ignored.

The program will be launched with either one or three parameters on the command line. The first parameter is always the maximum number of distinct words (i.e., discounting repetitions of the same word) expected in the input.

If that is the only parameter supplied, e.g.,

./countwords.exe 1000

then the program reads from the standard input (cin) and writes its output to the standard output (cout).

Optionally, the program can be run with two additional parameters, the file names to be used for input and output respectively, e.g.,

./countwords.exe 1000 aDocument.txt aDocument.csv

The function you will write, which does the actual input, counting, and output, should read a word at a time (the usual >> string operator will do just fine). Each word should be processed to remove punctuation and replace upper-case characters, then checked against an array of already encountered words. If it is in there, increment an associated counter. If not, it must be added.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Implement the histogram function to complete the desired program. You must use dynamically allocated arrays for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • C++ Lab 1. Read in the contents of a text file up to a maximum of...

    C++ Lab 1. Read in the contents of a text file up to a maximum of 1024 words – you create your own input. When reading the file contents, you can discard words that are single characters to avoid symbols, special characters, etc. 2. Sort the words read in ascending order in an array (you are not allowed to use Vectors) using the Selection Sort algorithm implemented in its own function. 3. Search any item input by user in your...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • In this exercise you will be designing a program in c++ that does the following: Prompts...

    In this exercise you will be designing a program in c++ that does the following: Prompts the user for a file name and then shows the user with the number of word in the file. The program should then allow the user to repeatedly specify a number and the program should show that word in the file. For example, if the file contained the text: Hello. This is the text that is contained in this file. A sample run of...

  • Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that...

    Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • You will be reading in 3 files in the program. One will contain a list of...

    You will be reading in 3 files in the program. One will contain a list of 1000 words in unsorted order. The second file will contain 1000 words in sorted order. The final file will contain 20 words to be searched for. The main program has been written for you. You will be implementing three functions: bool readWords(string array[], int size, string fileName); int linearSearch(string wordToFind, const string words[], int size); int binarySearch(string wordToFind, const string words[], int size); The...

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT