Solved

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

Posted on 1998-04-14
9
217 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Independent Software Vendors: 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

636 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