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.

Recommended Answers

All 3 Replies

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.