Solved

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

Posted on 1998-04-14
9
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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 84

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 200 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
returning a dereferenced pts in C++ 10 175
Unable to start eclipse ? 17 174
keep track of class structure 1 53
Creating a Windows C++ program in visual studio 2015 5 29
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

734 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