Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to read in a text file called lines.txt that holds an entire dictionary of words with multiple words on each line. I

image text in transcribedI am trying to read in a text file called "lines.txt" that holds an entire dictionary of words with multiple words on each line. I am supposed to find the longest word in the file and the line number it is on. So far I know that I am supposed to have a line counter when initializing the first get line() to 1 but I am confused on how to parse through it.

1. Again start a new program. This time, you need to finclude as well as . 2. Next, write code to prompt the user to enter a string, and use getline() to obtain the string from the user. 3. Now, create an 18tringstream object on the string. This is easily done using the stringstrean constructor. For instance, if your string is held in the variable str, and you want to create a stringstream object named sin, you can create the object using istringstream sin(atr); Here, I've named the object in ('string input"), but you can name it whatever you want. 4. Remember how we used the cof() method to detect when we hit the end of a file? The same method is used for istringstreams to detect when you reach the end of the input string. So you can now write a loop that uses the >>operator on your new istringstream object to get the individual strings from the string passed in by the user. 5. For bonus points (well, not really this part isn't graded), try using the >> operator, the good() method, and the clear() method take in an arbitrary string and parse it into doubles (when possible) and strings for anything not matching a double. (It would be nice to further distinguish between integers and doubles, but that takes a bit more work.) Your program should output what kind of value you read, and the value itself. For Instance, if the input is "The fourth digit of 3.14159265 is 1", your output might look like string! The stringt fourth stringi digit atring: of number: 3.14159265 string is number: 1 Task 4: Put it all together For the final task, you are provided with a text file, "lines.txt", and asked to discover two facts from the file. The file contains a large number of English words (from a Scrabble dictionary); one of these is larger than all of the others. Your job is to find that word and tell us what it is and b) tell us what line number the word is on. The file is laid out as follows: ) The first line has three integers. The first integer is the number of lines after the first line. The second and third integers are the minimum and maximum number of words on each line, respectively. Each subsequent line contains words separated by spaces. Assume that the first line of text (not the first line of the file) is tine number 1 for line numbering purposes. To find the information we're asking for, you'll want to do something like the following: 1. Read in the first line of the file to get the number of lines of text. 2. Read in the lines of text one by one using get line(). 3. Read in each word from the line using an Satringstream object. 4. Keep track of the longest word you've found, and what line you found it on

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

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions