1 #include "stdafx.h" 2 3 #include <iostream> 4 #include <cstdlib> 5 #include <cstring> 6 #include <algorithm> 7 using namespace std; 8 9 #define EQUAL 0 10 #define WORDLEN 200 11 #define CHAR_COUNT 26 12 13 struct word { 14 char name[WORDLEN]; 15 int fre[CHAR_COUNT]; 16 }; 17 18 class dict { 19 static const int DICTVOL = 100; 20 word list[DICTVOL]; 21 int wordcount; 22 public: 23 dict(); 24 void addword(const char str[]); 25 void search(const char req[]); 26 void dictsort(); 27 friend void calfre(word & tar); 28 friend bool frecmp(word & w1, word & w2); 29 }; 30 31 32 void calfre(word & tar) //log the frequency of each char 33 { 34 for (int i = 0; i < CHAR_COUNT; i += 1) 35 tar.fre[i] = 0; 36 for (int i = 0; tar.name[i] != '