Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C++ program to perform to read non-punctuated text and give word frequency

Posted on 1998-04-14
9
Medium Priority
?
220 Views
Last Modified: 2010-07-27
How to implement a C++ program to perform a case-insensitve, frequency of occurance, analysis of words contained within a non-punctuated text. Only blank spaces between words, newline characters, and a single $ to mark end of text.
Example text: Yellow Blue Green BLUE Red GREEN yellow $
Example output: Word:   Frequency:
                BLUE       2
                GREEN      2      CONVERT ALL WORDS TO
                RED        1        UPPERCASE
                YELLOW     2       in alphabetical order
0
Comment
Question by:Kevn
9 Comments
 

Author Comment

by:Kevn
ID: 1184294
Edited text of question
0
 

Author Comment

by:Kevn
ID: 1184295
It would be awesome to have the code by Thursday night.
What is the average time to expect a notification?
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1184296
IS this a Homework assignment? If so, it would not be ethical for anyone here to do your work for you.

If it is homework, you could ask for pointers about how to write the code and then additional help in debugging it.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Kevn
ID: 1184297
Edited text of question
0
 

Author Comment

by:Kevn
ID: 1184298
I am in a C++ class but this is not an assignment. It is an exercise from the text on array's and pointers and it is giving me a hard time. The urgency is because I would like to fully comprehend the code before my test on Friday. I'll take all the help I can get!
0
 
LVL 85

Expert Comment

by:ozo
ID: 1184299
If you can post your code, and tell us where you're having difficulty,
we may be able to help explain it to you.

0
 
LVL 11

Accepted Solution

by:
alexo earned 600 total points
ID: 1184300
Use stream extraction (operator>>) to read words.  White space is considered as separators.  Stop when you reach '$'.  Convert strings to lowercase using tolower() loops, _strlwr() or any other supported function.
Use an STL map for frequency of occurance calculations.
0
 

Expert Comment

by:Ferd
ID: 1184301
I suggest you use a linked list to store words from the file.
As you read  in a new word store it in a temporary string variable.
Convert the string to uppercase, then add it to the link list.
Also when a new word is read traverse through the list to check if it already exists (check the list after the word is stored in the temporary string and converted to uppercase). If the word exists
do not add it to the linked list then increment the field in the linked list which stores the frequency of the word. If the word is not already in the linked list add it to it. Find out more about linked lists (or dynamic storage and structures) if you dont already know about it and you will now what I mean. I can send you the code if you really want but it may take longer.

0
 

Expert Comment

by:Ferd
ID: 1184302
A $ character is not required if the text is in a file (I am assuming the text is stored in a file). An end of file character (EOF) with ascii code(-1) is stored at the end of files.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question