1. Again start a new program. This time, you need to #include . 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 istringstream object on the string. This is easily done using the istringstream 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(str); Here, I've named the object sin (string input"), but you can name it whatever you want. 4. Remember how we used the eof) 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 as this part isn't graded), try using the >operator, the good method, and the clear) method to 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 string: fourth string: digit string: 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 al of the others. Your job is to a) 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 line number 1 for lie 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 getline). 3. Read in each word from the line using an istringstream object 4. Keep track of the longest word you've found, and what line you found it on.

Question

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 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 #include <s stream» as well as <iostream>.
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 istringstream object on the string. This is easily done using the istringstream 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(str);
Here, I've named the object sin (string input"), but you can name it whatever you want.
4. Remember how we used the eof) 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 as this part isn't graded), try using the >operator, the good
method, and the clear) method to 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
string: fourth
string: digit
string: 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 al of the
others. Your job is to a) 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 line number 1 for lie 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 getline).
3. Read in each word from the line using an istringstream object
4. Keep track of the longest word you've found, and what line you found it on.
Expand
Transcribed Image Text

1. Again start a new program. This time, you need to #include <s stream» as well as <iostream>. 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 istringstream object on the string. This is easily done using the istringstream 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(str); Here, I've named the object sin (string input"), but you can name it whatever you want. 4. Remember how we used the eof) 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 as this part isn't graded), try using the >operator, the good method, and the clear) method to 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 string: fourth string: digit string: 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 al of the others. Your job is to a) 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 line number 1 for lie 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 getline). 3. Read in each word from the line using an istringstream object 4. Keep track of the longest word you've found, and what line you found it on.

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: write a program to convert between KPH and MPH in either direction. in Eclipse.If you are driving ac...

A: Hey,,,We  have to use scanner class  to get input .So we will import scanner package to access the s...

Q: You are not required to execute the queries. However, your syntax must by accurate.You must give at ...

A: SELECT Movie_Tiltle, Movie_Year, Price_Description, Rental_Fee FROM Movies WHERE Categories = ‘famil...

Q: Used Java 4.23 (Financial application: payroll) Write a program that reads the following information...

A: The program would have the following 4 sections:The declaration and initialization of the variables ...

Q: Write a program called LoopMinMax that reads in 4 values from the user and prints the lowest and hig...

A: You didn’t mention which language should be used for the given program. Here, I have used JAVA langu...

Q: Is the following distributive law valid or invalid? Prove your answer. x XOR (y + z) = (x XOR y) + ...

A: Answer:Here, the truth table is used to get the answer for each side of the question.First take LHS,

Q: Construct a dfa that accepts the language generated by the grammar S → abA, A → baB, B → aA|bb.

A: Deterministic finite automata (DFA):

Q: I am stuck trying to create a program in PYTHON that calculates the coins needed to make change for ...

A: We know penny=1 cent, nickel=5 cents, dime=10 cents and quarter=25 cents.Now for example if we have ...

Q: Write a class, AgeMessages , which does the following:a. Ask the user to enter age using a Scannerb....

A: The given below is the code to enter the age through user and print the message according to age. To...

Q: How do you convert 172.16.20.55 to binary format?

A: 172.16.20.55 represents IP address in decimal format. In order to convert it into binary format we n...

Q: Write a PL/SQL block to accept a date from the user and print the day and the date as shown below. U...

A: Solution:Given data,The PL/SQL code read the user input of date and display the day and the date in ...

Q: create a new file in c++. In this lab, you will add some more functionality to the program. Use loop...

A: Program Instructions:Declare variables and write a welcome message.Always convert the user's choice ...

Q: Give an implementation of the macroinstruction searchleft (a, qi, qj), which indicates that the mach...

A: Turing machine uses “searchleft” for an implementation of the macroinstructions. If the machine read...

Q: What language is accepted by the Turing machine whose transition graph is in the figure below?

A: Turing machine:Turing machine is a model of a hypothetical computing machine which can use a predefi...

Q: Write a program called StudentTable that prints the below table. Use only print() orprintf(). DO NOT...

A: The program in Java would be using print and printf statements with formatting for left alignment of...

Q: 1. What is the output of the following code? public class Loopy {public static void main(String[] ar...

A: 1. Algorithm for the given code is as follows:The variable ""x is initialized as "1" within the "mai...

Q: Write a program called StudentTable that prints the below table. Use only print() orprintf(). DO NOT...

A: Using the given hint "printf" the below program was done in C language where "println()" is used in ...

Q: Write two scnr.nextInt statements to get the input values into birthMonth and birthYear.Then write a...

A: Given below is the program to get input values for month and year and write the output value as a mo...

Q: Create a new file in c++.  In this lab, you will add some functionality to the table ofmenu. Your bo...

A: Program Instructions:Declare variables and write a welcome message.Always convert the user's choice ...

Q: Create a new file (in Dev C++) . In Lab 2, you created a menu for a simple calculator program. In La...

A: Program Instructions:Declare variables and call the printHelloMsg() function to display a welcome me...

Q: Programming in C.

A: Algorithm: Declare required header files.Create “ContactInfo” structure.Declare required variables f...

Q: how can I write a statement in C++ that would print last name, followed by a comma, followed by firs...

A: Given below is the C++ program to print a statement with last name, followed by comma, followed by f...

Q: Consider the following grammar in BNF (start symbol is ) Which of the following sentences are in the...

A: Backus-Naur Form (BNF):BNF is a formal mathematical method to define the syntax of the programming l...

Q: Find and list the websites of the parent and child standardization organizations that create standar...

A: Standards in Data communication and computer networking defines the rules which are needed for inter...

Q: What is a solid state disk?

A: Solid state disk drive or solid state drive (SSD) is a non-volatile that stores (or persists) data i...

Q: If you are reading a flat file, with minimal information regarding business rules and constraints. H...

A: Solution:Even though the file contains minimal information about business rules and constraints, the...

Q: Construct an npda corresponding to the grammar S→aABB|aAA,A→aBB|b,B→bBB|A.

A: Firstly, we will convert the given grammar into GNFS → aABB|aAAA → aBB|bB → bBB|aBB|a

Q: Problem: Create a base class called Vehicle that has the manufacturer’s name (typeString), number of...

A: 4 classes are implemented using the blueprint given:Vehicle class which is the base class is: public...

Q: Find a regular grammar that generates the language on Σ = {a, b} consisting of all strings with no m...

A: Regular grammar for the language Σ = {a, b} is as follows:

Q: Normalization               Repair the ER Diagrams into at least 1nf, 2nf and 3nf Give explanations...

A: Hi due to lack of adequate information we are unable to provide any solution. Please provide us more...

Q: Read in 5 letters from the keyboard, reverse the order of the second and next to last letters, and p...

A: Pseudocode is an informal approach of programming description that does not need any exact programmi...

Q: SQL(Oracle): How do I create an index for the number of days it takes to ship an order? i.e. shipdat...

A: Since we need to create an index based on a calculated field we need to create a calculated index. T...

Q: The nor of two languages is nor (L1, L2) = {w : w ∉ L1 and w ∉ L2}. Show that the family of regular ...

A: Click to see the answer

Q: What type of data breach occurred involving the Facebook/Cambridge Analytica?

A: Data breaching involves intentional or unintentional leakage of confidential information to un autho...

Q: c++ Write a program to swap the contents of two arrays. Each array has five elements. The fist array...

A: Program Instructions:Declare and initialize array and variables.Print the elements of arrays before ...

Q: Write a program that contains 2 methods, main and printLine (10 points)1) The printLine method will ...

A: Declare required variables ‘first’, ‘second’ and ‘times’ which is used to store first character, sec...

Q: Is each of the following an absolute pathname, a relative pathname or a simple file name?a. Milk_cob...

A: Absolute path specifies the location of a directory or file from the root directory including a slas...

Q: (The Fan class) Design a class named Fan to represent a fan. The class contains:■ Three constants na...

A: Java program to create Fan class is as follows:

Q: 2. Write a program called ListOddNumbers that prints the below (there is a single space between each...

A: Solution: 2. The below program is written in Java language to display the odd number between 1 and 5...

Q: 1.6 Compute the scalar cardinality and the fuzzy cardinality for each of thefollowing fuzzy set.

A: The scalar cardinality of a fuzzy set is calculated using the formula:

Q: Use the worksheets to show, one path augmentation at a time, how to use the Ford-Fulkerson Algorithm...

A: For solving your problem first of all we define Ford-Fulkerson Algorithm.Ford-Fulkerson Algorithm fo...

Q: Write a complete C++ program that randomly generates 20 integers between the rangeof 1 to 50 and sto...

A: The random number is generated by using rand() function from stdlib.h and in order to generate a new...

Q: 21,22,23

A: An image contains white, black or different shades of grey from black (maximum gray) to white (minim...

Q: The speed of computers has increased greatly over the history of computing. The traveling salesman p...

A: TSP is an NH Hard problem, if solved by brute force method it takes (n-1)! time where n is the size ...

Q: Cell Phones Records In this part, you are required to write a program, using linked lists, that man...

A: In the given question, some parts of the question are missing to use linked lists.Here, I have creat...

Q: Create a new file in c++ and save it as lab11_XYZ.cpp (replace XYZ with your initials). Create ANOTH...

A: Program Instructions:In the header file, create a temporary variable temp of the data type of each v...

Q: Find regular grammars for the following languages on {a, b}: L = {w : na (w) and nb (w) are both eve...

A: Regular grammar for the language L = {W: na (w) and nb (w) are both even} is as follows:

Q: Develop the ‘Shape’ application such that: Implement an array of objects of various types (all SIX ...

A: Program plan:Define a class called “ShapeTest”.Define a “main()” method.Create an array of six shape...

Q: Write a program to convert between KPH and MPH in either direction.If you are driving across the bor...

A: The algorithm for the program would be as below:Declare one int variable for accepting user menu cho...

Q: what strategies that would attract buyers to a company's e-commerce web site

A: Strategies to attract buyers to the company e-commerce website:Offer limited time specials to new cu...

Q: #include#include#includeusing namespace std;// outputHtmlTitle// parameters// This function...void o...

A: We need to print the html, head and title tag in the outputHtmlTitle() method.The outputHtmlTitle() ...