BullCowCartridge Semi-Auto List.txt Filtering & Sorting

My Bull Cow Game has three .txt lists, one for each difficulty level. Rather than sorting through the thousand+ words myself I just quickly put this together.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

bool IsIsogram(string Word, int NotIso)
{
    for (int j = 0; j < Word.length(); j++)
    {
        for (int h = j + 1; h < Word.length(); h++)
        {
            if (Word[j] == Word[h])
            {
                system("cls");
                cout << "Non-Isogram Words: " << NotIso << endl;
                return false;
            }
        }
    }
    return true;
}

int main ()
{
    fstream HugeList;
    HugeList.open("WordList.txt", ios::in);
    ofstream List1;
    ofstream List2;
    ofstream List3;
    List1.open ("EasyWordList.txt"); // You could direct these straight into the appropirate BullCowGame file & you could name them whatever you'd like
    List2.open ("NormalWordList.txt");
    List3.open ("HardWordList.txt");
    if (HugeList.is_open())
    {
        int NotIso = 1;
        string Word;
        while(getline(HugeList, Word))
        {
            if (IsIsogram(Word, NotIso)) // checks if words are isograms NOTE: Thinks A != a, B != b, etc... 
            {
                if (Word.length() == 3 || Word.length() == 4 || Word.length() == 5)
                {
                    List1 << Word << endl;
                }
                if (Word.length() == 6 || Word.length() == 7)
                {
                    List2 << Word << endl;
                }
                if (Word.length() >= 8)
                {
                    List3 << Word << endl;
                }
            }
            else
            {
                NotIso++;
            }
            
        }
   }
    List1.close();
    List2.close();
    List3.close();
    HugeList.close();
    return 0;
}

I created the WordList.txt file in the same location as this .cpp. Then I copied and pasted several online word lists into the WordList.txt, and ran the .cpp. It filters out all the non-isogram words (Except those with capitol first letters) and assigns the isograms to the other three lists. The length of the isogram determines which list it gets placed into. Additional/Alternate filters could easily be applied, and I plan on creating one to supplement the current isogram filter shortcoming. Hopefully someone here finds this helpful or interesting.

As I mentioned earlier, the Isogram checker isn’t 100% effective due to it’s inability to determine the sameness of a capitol letter and it’s lower-case counterpart. So, here’s my fix:

Function:

string CapitolClearing(string Word)
{
    char CapAlphaBet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Cross-Reference list for finding capitol letters
    char LowAlphaBet[] = "abcdefghijklmnopqrstuvwxyz"; // Reference list to replace capitol letters

    // Converts Word into a char array
    char Letters[50];
    strcpy(Letters, Word.c_str());
    cout << Word << endl;

    // Converts capitol letters to lowercase
    for (int i = 0; i < Word.length(); i++)
    {
        for (int j = 0; j < 26; j++)
        {
            if (Letters[i] == CapAlphaBet[j])
            {
                cout << "Swapping: " << Letters[i];
                Letters[i] = LowAlphaBet[j];
                cout << " For: " << LowAlphaBet[j] << endl;
            }
        }
    }

    // Converts Letters array back into string
    string NewWord(Letters);
    cout << "NewWord: " << NewWord << endl << endl;

    return NewWord;
}

Function Call:

Word = CapitolClearing(Word);

The function just needs to be placed above main somewhere, and the function call needs to be placed just above the isogram function call, which is the first if conditional statement within the while loop of main.

Privacy & Terms