Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. Two data members: head and tail of type struct word.
  2. A default constructor
    1. initialize head and tail. Make head next points to tail.
  3. 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.
  1. 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.

  1. 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.
  2. boolerase(intord): erases the word present at the order ord. Do not forget to update the oder of the words followed.
  3. booleraseAll(string w): erases all instances of the word w.





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

Design Operation And Evaluation Of Mobile Communications

Authors: Gavriel Salvendy ,June Wei

1st Edition

3030770249, 978-3030770242

More Books

Students also viewed these Programming questions

Question

Outline two major problems for psychogenic identity theory.

Answered: 1 week ago