Just by looking very quickly, it seems that you are using the position of the letters in the alphabet to do something.
You can replace all of your switch statements with a single expression that looks like this:
int letter = (int)(ActualLetter - 'a'); if(numOfWordsInFile[letter]<maxWordsPerFile){ fout.open(fileName.data(),ios::app); fout<<word<<" "<<endl; numOfWordsInFile[letter]++; if(totalWordsInDict<maxWordsInDict){ totalWordsInDict++; } return(Dictionary::success); }else{ return(Dictionary::failure); }
ActualLetter is something like "a", for example.
In a related article in the future, if you really have big switch statements, consider encapsulating code in a function:
switch (letter) { case 'a': LetterA(); break; case 'b': LetterB(); break; ... }
Or, even better, you can use polymorphism to send to C ++ the method you want based on a specific derived class:
class BaseLetter { ... public: virtual void DoStuff() = 0; }; class LetterA : public BaseLetter { public: void DoStuff(); }; class LetterB : public BaseLetter { public: void DoStuff(); }; void Foo(BaseLetter *letter) { // Use dynamic dispatch to figure out what to do letter->DoStuff(); }
Just remember that dynamic dispatching has a (negligible) performance rating, and above this is a very bad place for actual use. Solution I, RedX and others published are much better suited for your specific example.
Mike bailey
source share