The purpose of this program is to read a text file and store words and the line
ID: 3714116 • Letter: T
Question
The purpose of this program is to read a text file and store words and the line numbers on which they occur, to be printed to another text file and screen. This project in a way brings you a tiny step closer to the search engine technology. You must use a Binary search tree as well as any other data structure needed. Proceed as follows:
1. Design a class called WordList, which is given below partially. You will need to add to it as per need of the program. In place of class you can also use WordList struct. Still all the same member functions and data members (as WordList class) would be needed.
Class WordList{
private:
/**
*Stores the word from text file
*/
string Word;
/**
*Stores the line numbers (as integers) on which the Word is found
*/
SinglyLinkedList LineNumList;
//Add any other data members as per your need.
public:
/**
*Reads data from the file or keyboard to fill the WordList object
*/
friend istream & operator >>(istream & in, WordList& WL);
/**
*Writes data to the file or to screen to print the WordList object
*/
friend ostream & operator <<(ostream & out, const WordList& WL);
/**
*Virtual destructor
*/
virtual ~ WordList ( );
//Add any other member functions, as you need. For example, you
//will need to overload the following operators, so that WordList
//can be placed in a binary search tree: operators >, <, and ==.
};
The suggested UML of WordList class may look like below.
Insert WordList objects into the Binary search tree such that when printing the tree, using an In-order iterator, the words are printed alphabetically
Explanation / Answer
#include<stdio.h>
int main(void)
{
int i,j;
//for loop
printf("This is a for loop );
j=-5;;// initial condition
//while loop
while(j<=0) //terminal condition
{
printf(%d",j);
j=j+1;// iteration
}
printf(" Both constructs generate same result.. ");
return 0;
}
//a program to show the nested for loops
#include<stdio.h>
int main()
{
//variables for counter....
int i,j;
//outer loop,execute this first....
//for every iteration ,execute the inner loop
for(i=15;i>0;)
{
//displayi==
printf("%d==",i);
//then,execute inner loopnwith loop index j,
//the initial value of j is i-1
for(j=1;j>0:)
{
//display i==
printf(%d==",i);
//then,execute innner loop with loop index j,
//the initial value of j is i-1
for(j=1;j>0:)
{
//display #
print("#");
//decrement j by 1 until j>10, i.e j=9
j=j-1;
}
//go to new line ,new row
print(" ");
//decrement by 1,repeat until i>0 that is i=1
i=i-1;
}
retun 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.