954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Count letter rate

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.

grafas7
Newbie Poster
6 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 
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.

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

ok, only formula for it please. why not with Borland 6 ?

grafas7
Newbie Poster
6 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

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.

std::vectors<std::string> contents;


Then you read until the comma character is reached :

std::string tmp;
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.

while( readFile.good() ){
  std::string temp;
  getline(readFile,temp,',');
  content.push_back( temp ); //add it to our list
   
}


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.

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You