Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that Prompts the user for an input file name and opens the input file for reading. Count the number of words

Write a C++ program that

  • Prompts the user for an input file name and opens the input file for reading.
  • Count the number of words in the file. If the file has more than 1000 words then display a message indicating the number of words in the file, close the file, and end the program. In other words, do not proceed unless the file contains 1000 or fewer words.
  • Create an array of C++ string objects with a size of 1000. Initialize each element of the array to a null string ("").
  • Read each word in the input file. If the word is already stored in the array then do not store it again, but if the word is not already stored in the array then add it to the array. In other words, the array should contain a list of the unique, distinct words in the input file, and each word should appear only one time in the array.
  • Display the count of the total number of words stored in the array, and then display each word in the array.

Your program must implement and use the following functions with the function signatures as shown:

  • void openFile(ifstream &); - This function accepts an input file stream variable passed by reference. The function prompts the user for a file name, and then opens the file for input. If the file does not exist then the function re-prompts the user. The function must not return until a valid file name has been entered, and the input file is open. This function must be used to open the input file in your program.
  • int find(string *, string); - This function accepts your string array (string *) as the first parameter, and a string as the second parameter. The function searches the array for the string, and returns the position (subscript number) of the array element that matches the string. If the string is not found the function should return a -1. This function must be used for your array searches.
  • int append(string *, string); - This function accepts your string array (string *) as the first parameter, and a string as the second parameter. The function "appends" the string to the array, i.e. set the value of the first free element of the array to the value of the string given in the second parameter. This function must be used to add a new string to your word list array.

Your program may use additional functions if desired (such as an array print function), but no additional functions are required.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago

Question

Organize and support your main points

Answered: 1 week ago

Question

Move smoothly from point to point

Answered: 1 week ago

Question

Outlining Your Speech?

Answered: 1 week ago