Question
Write a program that reads a text from a given file and store the words of the text in a singly linked list. Each word
Write a program that reads a text from a given file and store the words of the text in a singly linked list. Each word is stored in a separate node.
The file text.txt contains a paragraph (see below):
The term bug to describe defects has been a part of engineering jargon since the 1870 and predates electronic computers and computer software. it may have originally been used in hardware engineering to describe mechanical malfunctions.
Declare a struct Word as given below:
structword {
string wrd;
intorder;
word* next;
word() : next(NULL) {}
word(string wrd0,intorder0) :
wrd(wrd0), order(order0),next(NULL) {}
};
Write a class text with the following data and function members:
- Two data members: head and tail of type struct word.
- A default constructor
-
- initialize head and tail. Make head next points to tail.
- Insert function,voidinsert(string s,intord=0)that inserts string s at the position ord in the list. Dont forget to update the order of rest of the following nodes after inserting.
- Overload ostream
(1): The
(2): term
(3): bug
(4): to
(5): describe
(6): defects
(7): has
(8): been
..etc
Write a suitable main() that read words from the given text file and prints.
Exercise 2:
Write the following member functions to the text class developed in ex1.
- boolfindWord(intord, word& w): finds the word thats present at order ord. If the word exist in the text then return true and save the word in reference variable.
- boolerase(intord): erases the word present at the order ord. Do not forget to update the oder of the words followed.
- booleraseAll(string w): erases all instances of the word w.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started