Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For 60 points, modify the main program as follows. Check the command line arguments. A file is specified as -f textfile. If a file has

For 60 points, modify the main program as follows.

Check the command line arguments. A file is specified as "-f textfile". If a file has not been specified, exit the program with a meaningful error message.

Open the input file specified by argv[2] and enter into an endless loop that reads and processes the text lines. Save each text line in a cache (e.g., vector) for retrieval later on. Then change all so-called punctuation characters, i.e., (, ), {, }, and ., to a blank space. Specifically, wrap std::ispunct(), which can handle the detection (see "man ispunct"), inside a function to be called replace_punctuation() that you pass along to std::transform() which sweeps thru the text line characters. Have function replace_punctuation() return either the character tested (give as its input argument) or a blank space. Finally, use a string stream to parse the resulting text line into words which you insert into a hash table along with the current line number. Close the input file when EOF is reached.

Add a second endless loop that prompts the user for words to search for. Print all line numbers and the corresponding text for each successfull search. Print nothing for an unsuccessfull search. Use the vector of line numbers returned by hash_table::find() to do this. Look up the text in the above mentioned data cache for each line number. See output examples below.

Make no assumptions about the number of lines in the input file. Make no assumptions about the number of characters or words on each line. The test files may be pure ascii text, html code, or even a C++ program. Your code should work regardless of the type of ascii data stored in the file.image text in transcribed

Hashtable: command line checking user./hashtable usage: ./hashtable -vf f textfile Hashtable: data processing user> cat-n sometext.txt 1 Wow 2 Hash tables are so cool. 3 CS140 is great 4 I learn so much. 5 This is awesome user> ./hashtable -f sometext.txt find> Wow 1 Wow find> so 2: Hash tables are so cool 4: I learn so much find> great 3: CS140 is great. find> CTRL-D user ./hashtable-vf sometext.txt find> Wow 1 Wow find> CTRL-D Run stats Number of slots used 14 Max number of slots: 23 Number of collision s: 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions