You are here:

C++/Extracting words from a text file./C++

Advertisement


Question
Dear MR Prince,

Below are more details.

I have to use arrays,class,file handling, exception handling and string
processing.

A text file contain English sentences and the only punctuations used
are
" quote
"" speech
, comma
. and full stop

a prog is required to produce a list of 4-letter words used in the text
file and each word has to occur only once in the list. A user defined
exception is used to add in the list.

e.g once the word "read" is detected:

user defined exception occurs
the word is added to the list if it is not present
the program continues with the processing of the remaining words

once all the sentence is processed the user should be able to display
the list in alphabetical order.

B/Rgds
Ritesh

Answer
Dear ritish!
  
 Ya the problem is simple , but there may be lot of Meaning less words will be produced  in the final list.

. Create a list that can accommodate a string with 4chars
. Traverse the input file by single character ,
  if punctuation_marks occurs skip on to the next character
. Collect the character in an array  , if 4 characters are collected then  simply insert into the large list ( before inserting the word into the large array make sure that the word is not already in the array )
. Do this process until an end of file reaches.

. instead of using arrays usage of linked list in this case its more efficient .
. Use efficient algorithm to sort the final list in order.
. Then display the list .

. Note: You can instead use arrays !    
. There are lot of places in this program to handle exceptions.
1.Input File not open.
2.word already avail in list
3.EOF reached
4.EOF reached before filling the Input character array.
5.And your own exceptions...


NOte : As i said earlier your program will produce many Meaning less words eg:
 if the available word in the file is "sentence" your program will split the sentence in to two 4-letters just like "Sent" and "ence" , obviously "ence" have no meaning
so alter your algorithm in such a way it will read the complete word instead of splitting into two or three parts .


All the best !
Regards !
Prince M. Premnath.

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise

Years of research in C/C++ Will bring you all facts regarding , OOPS , SVGA , MOUSE , BIOS , IVT , Feel free to query me :-)

Experience

More than 5 years

Education/Credentials
MCA

©2012 About.com, a part of The New York Times Company. All rights reserved.