943,078 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 402
  • C++ RSS
Dec 17th, 2009
0

Count letter rate

Expand Post »
hi, i have a task i dont understand, im working with C++ Borland 6.
my task is to create array ,which will read text from .txt file (any text,with any number of words). What is important i need to count those letters by rating them, and then range (counted letters) in declining lines by rate.

Example: we have text
aaaa, bbbbbbbb, cccccccccccccc, dddddddddddddddddd...

my task is to rate them from higher to lower (sry if my english bad)

......
dddddddddddddddddd
cccccccccccccc
bbbbbbbb
aaaa


I dont know how formula looks so i beg ,to create me one, but create with C++ Borland 6, dont use black screen please. If its possible to compile and extract that program and upload here ^^ thank u.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grafas7 is offline Offline
6 posts
since Nov 2009
Dec 17th, 2009
0
Re: Count letter rate
Quote ...
dont use black screen please
I'm not sure what you mean by that.

No one is going to write the program for you, and definitely not with Borland anyway. Instead, we will help you with what you have coded.

In starting out, you should have an array of ints 26 elements long (one for each letter of the alphabet) and increment the appropriate counter when you process a letter.
Sponsor
Featured Poster
Reputation Points: 1165
Solved Threads: 578
Quantitative Phrenologist
jonsca is offline Offline
4,271 posts
since Sep 2009
Dec 17th, 2009
0
Re: Count letter rate
ok, only formula for it please. why not with Borland 6 ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
grafas7 is offline Offline
6 posts
since Nov 2009
Dec 17th, 2009
0
Re: Count letter rate
Since the size of the file is unknown you need to use vectors to store the
data. I also suggest you to read in the file into a string , from start untill
you reach the ',' comma character. Therefore you will need to use a
vectors of strings.
C++ Syntax (Toggle Plain Text)
  1. std::vectors<std::string> contents;

Then you read until the comma character is reached :
C++ Syntax (Toggle Plain Text)
  1. std::string tmp;
  2. getline(readFile,tmp,','); //read until the comma character is reached

Of course you will need to read the file until it ends so you need to while
loop it.
C++ Syntax (Toggle Plain Text)
  1. while( readFile.good() ){
  2. std::string temp;
  3. getline(readFile,temp,',');
  4. content.push_back( temp ); //add it to our list
  5.  
  6. }

So by now we have all of the content in the file stored inside our vectors
of string. Now all that is needed is to sort the vector. Maybe instead
of using the std::sort method, you should research on the art of sorting.
It will be a good learning experience. The after you have a sorting
code working, all you have to do is to make sure that you are
sorting the vector with respect to the length of its content.
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,859 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Display square of stars
Next Thread in C++ Forum Timeline: Inventory System with database "f.stream"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC