Denethor2000: You really need to start drinking decaf.
DeadArchDown: Please at least show some of that courtesy that you were talking about.
Unregistered: We're here to help you, but we don't have to. The way you stated your post implied otherwise, please choose your words more carefully in the future.
>I AM NOT EXPECTING SOMEONE TO DO IT FOR ME BUT
>DESREVE TO BE GUIDED SLOWLY TO SOLVE THE PROBLEM.
Sentences in all caps are very annoying, but to help you solve your problem I'll offer an algorithm and code. You can ignore the code if you wish, but I've found that one can learn more quickly from a good example than an explanation.
To check the frequency of one two and three letter words, read one word at a time and check the length of that word. If the length is one, two, or three then you can proceed to check the word for invalid characters. If the word contains invalid characters you do nothing and read another word, otherwise increment a simple counter. At the end of the program print the values of the three counters, one for each word size. The frequency from this point can easily be calculated.
Code:
#include <iostream>
#include <fstream>
#include <string>
bool goodStr ( std::string& s )
{
for ( int i = 0; i < s.length(); i++ )
if ( s[i] >= 'a' && 'z' >= s[i] || s[i] >= 'A' && 'Z' >= s[i] )
continue;
else
return false;
return true;
}
int main ( void )
{
std::string s;
int singles = 0, doubles = 0, triples = 0;
std::ifstream IN ( "test.txt" );
while ( IN.good() ) {
IN>>s;
switch ( s.length() )
{
case 1: if ( goodStr ( s ) ) ++singles; break;
case 2: if ( goodStr ( s ) ) ++doubles; break;
case 3: if ( goodStr ( s ) ) ++triples; break;
}
}
std::cout<<"Singles = "<< singles <<"\nDoubles = "
<< doubles <<"\nTriples = "<< triples <<"\n";
IN.close();
return 0;
}
-Prelude