Sunday, July 12, 2009

My c++ program has some error..so pl correct them... it is a program to count unique words and what these are?

#include%26lt;iostream%26gt; // Allows program to perform input and output


using std::cout; // program uses cout


using std::cin; // program uses cin





#include%26lt;fstream%26gt;


using std::ifstream;








int main() // function main begains program execution





{





ifstream in;


char w[2000][15];


int alphabet[26];


char ch;


int ind = 0. subind = 0;





// initialise the array with zeros





for(int i=0;i%26lt;26;i++)


alphabet[i] = 0;





//Open the input file


in.open("Text.txt");





//Check the file opened successfully.


if(!in.is_open())


cout%26lt;%26lt;"Unable to open input file."%26lt;%26lt;endl;





// Read the input file character by character


while(in.get(ch))





// if the character is an alphabet, then append the word


if( (ch%26lt;91%26amp;%26amp;ch%26gt;64)||(ch%26lt;123%26amp;%26amp;ch%26gt;96) )





{


w[ind][subind]=ch;


subind++;


}


// end if





// If a space found, move onto a new word





if(ch==' ')


{


w[ind][subind] = '\0';


subind=0;


ind++;


w[ind][subind]='\0';


} // end fi





} // end while





// Find the cout of occurence of words which starts with a letter





for(int i=0;i%26lt;ind;i++)


alphabet[toupper(w[i][0] = 65]++;





int max=0 // to find the max





// Display results





for(int i=0;i%26lt;26;i++)


if(alphabet[i]!=0)


{


// Display the cout of words that starts with a letter





cout%26lt;%26lt;"\n" %26lt;%26lt; static_cast %26lt;char%26gt; (i+65) %26lt;%26lt;"'s-"


%26lt;%26lt;alphabet[i]%26lt;%26lt;"--";





// Find for the max occurences of a letter


if (alphabet[i]%26gt;alphabet[max])


max=1;


// Display the words that starts with a specific letter





for (int j=0;j%26lt;ind;j+=)


if(toupper(w[j][0]==(i+65))


cout%26lt;%26lt;w[j]%26lt;%26lt;", ";


} // end if





// A conclusion comment of the program


cout%26lt;%26lt;"\n\nLetter with that began the most words was "


%26lt;%26lt;static_cast%26lt;char%26gt; (max+65);





// close the input file


in.close();


return 0; // indicate program executed successfully


} // end of function, main

My c++ program has some error..so pl correct them... it is a program to count unique words and what these are?
What is the output? I may be able to analyse depending upon the actual output.





I cant run it here as i do not have any C++ compiler out here


No comments:

Post a Comment