//Written by Mo Kashi //This program gets all words from an input file as a //dictionarry and specifies how many of them are Palindromic //and how many of them are in dictionarry if they are spelled backwards //The program can also specify how many 1-letter,2-letter,3-letter and //n-letter-word are in that dictionary.The dictionary is an input file //"input.txt".The result is sent to an output file"output.txt" in C drive. #include #include #include #include vector text;//vector to store all words in dictionarry ifstream fin; ofstream fout; int Freez; int number_of_stills; int number_of_palindromics; string reverse(string);//This method gets a string and returns //the reverse of it. void Banner(){//This method prompts user to print out //the banner fout<text){ //This method gets a word and specifies if it is palindromic //is so, it increments the number of the palindromic numbers string reversed=reverse(s); if(s==reversed){ number_of_palindromics++; }//if }//palindromic bool stillcheck(string s,int position, vectortext){ //This methos specifies how many words are still words in //the dictionarry if they are inversed.It makes use of the //binary search to specify if the inverse of the word is still //in the dictionarry .It also includes pladromic int lowindex=position; int highindex=text.size()-1; string reversed=reverse(s); int midindex; while(highindex>=lowindex){ midindex=(lowindex+highindex)/2; if(text[midindex]==reversed){ number_of_stills++; return true; }//if else if(text[midindex]>reversed) highindex=midindex-1; else lowindex=midindex+1; }//while return false; }//still check string reverse(string s){ //This method gets a string and return its reverse if(s.size()==1) return s; else return s.substr(s.size()-1,s.size()) +reverse(s.substr(0,s.size()-1)); }//revese int countletters( vectortext,int n,int size){ //This method accept "n" as an integer and specifies how //many n-letter words are there in the dictionary. int counter=0;//number of n-letter words for(int j=0;j>word;//reads one word from dictionarry while(fin){ text.push_back(word); fin>>word; }//while for(int i=1;i<11;i++){ fout<<"Number of "<>Freez; }