As part of another project that I'll be calling PHRASEG, which is essentially a hangman type game, I need to establish character rankings, based on a reasonably large text file. Each game will start @ 100 and by choosing vowels as an example, the score will be reduced significantly versus less frequent characters like J or Z.Proficiency in C++ is the ultimate goal, but on that path, coding and compiler flags to produce the tightest executable are priorities. Without having delved into it deeper, but I thinkIndex = (Ch & 31) - 1;is better thanIndex = toupper (Ch) - 'A';NOTE: VT100 emulation is only for estethics or at least to make output a little more readable.CharWeight.cpp/*    version 5.4.0 20160609 g++ -Os -Wall -std=c++11    On Ubuntu 16.04 using GNOME terminal 3.18.3 (132 x 43)*/#include  <iostream>#include  <iomanip>#include  <fstream>#include  <string>using namespace std;/*    Display character ranking relative to the one with the most occurences.    In the case of the default file, there are 90,113 occurrences of the     letter 'S' and 31,872 of 'C'. This yields a ranking of 35 as there is     roughly 1/3 as many C's as S's.*/void Summary (unsigned Chars[], unsigned Maximum){  cout << \033[10;49H;    // Start at Row 10, Column 48  // Display character ranking in a 3 x 9 grid with the last column only  // having 8 rows.  for (int row = 0; row < 9; row++) {        for (int col = 0; col < 3; col++) {      int Index = col * 9 + row;      char Ch = 'A' + Index;      // This will exclude the 27th interation and formula works to calculate      // essentially factional values with integers.      if (Index < 26) {        unsigned Weight = Chars[Index] * 100 / Maximum;        // Samples of less that 500k characters may yield results of less        // than 1, so those results need to be bumped        if (!Weight)          Weight++;        // Display result in the format [?]  000            cout << \033[34m[\033[1;33m << Ch << \033[34m]\033[1;36m;        cout << setw (5) << Weight << \033[6C;        }              }    // Go to new line a repeat process    cout << \n\033[48C;     // Indent on newline 49 spaces    }}/*    Invoked by CharWeight [Textfile]*/int main (int ArgC, char **ArgS) {  string FName;  ifstream Text;  // Emulating VT100, clear screen and move cursor to initial position.  cout << \033[2J\033[2;47HAlphabetic character weight calculator;  // Use filename passed by OS or America English Dictionary  if (ArgC == 2)    FName = ArgS [1];  else    FName = /usr/share/dict/american-english;  // Display file that will be used by algorythim.  cout << \033[6;18HUsing: \033[1;35m << FName;    Text.open (FName);  if (Text.is_open()) {    unsigned Count[26] = {0};    unsigned Max, ChrCount, FileSize, Index;    unsigned char Ch;    Max = ChrCount = FileSize = 0;    // Initialize variables on stack    Ch = Text.get();                  // Read first character    while (Text.good()) {      // Only consider alphabetic characters in the range A-Z.      if (isalpha(Ch)) {        Index = toupper(Ch) - 'A';        Count [Index]++;              // Bump occurences of this letter        // Needed to calculate characters rank compared to the maximum        // occurences of any letter.        if (Count[Index] > Max)          Max++;        // Used to calculate what percentage of characters in file are        // whitespace or punctuation.        ChrCount++;        }      Ch = Text.get();      FileSize++;      }    // Show total number of qualifying characters, total filesize and    // ratio of qualifying charaters.     cout << \033[0m --> \033[1;2;36m << ChrCount << \033[2;37m of ;    cout << FileSize <<  = \033[33m << ChrCount * 100 / FileSize;    cout << \033[1;37m%;    // Display 3 x 9 grid of rank results for each character    Summary (Count, Max);     // Display summary of weight values    }  else    // Usually because file doesn't exist    cout <<  \033[0;31;43m FAILED ;  // Move cursor to last line of terminal window.  cout << \033[42;1H\033[0m << endl;}
Ranking of alphabetical characters A-Z
c++