void runProg(){ int remaining[NSQ]; STDMatrix builder; for(int i = 0; i < NSQ; i++) remaining[i] = 0; cout << "Generating Order-" << N << " squares. . . \n\n"; generateOrder4(remaining, builder, 1); cout << "All squares built."; cout << endl << endl; cout << "Permuting squares as upper triangular. . .\n\n"; permuteUT(); cout << "Permutation complete."; cout << endl << endl; cout << "Finding unique squares after tests for equality. . .\n\n"; findUnique_Comparison(); cout << "Unique squares found."; cout << endl << endl; cout << "Classifying squares as Dudeney Types. . .\n\n"; classify4(); cout << "Classification complete."; cout << endl << endl; cout << "Finding unique squares after tests for permutations. . .\n\n"; findUnique_Permute(); cout << "\nUnique squares found."; cout << endl << endl; cout << "Sorting squares from least to greatest. . .\n\n"; sortLinearCompare(); cout << "Sorting complete."; cout << endl << endl; cout << "Classifying squares as Dudeney Types. . .\n\n"; classify4(); cout << "Classification complete."; cout << endl << endl; cout << "There are currently " << magics.size() << " squares created." << endl; classList(); }
int Lexer::classify(const char *s, int n, bool q) { switch (n) { case 2: return classify2(s, q); case 3: return classify3(s, q); case 4: return classify4(s, q); case 5: return classify5(s, q); case 6: return classify6(s, q); case 7: return classify7(s, q); case 8: return classify8(s, q); case 9: return classify9(s, q); case 10: return classify10(s, q); case 11: return classify11(s, q); case 12: return classify12(s, q); case 13: return classify13(s, q); case 16: return classify16(s, q); default: return T_IDENTIFIER; } // switch }
int main(){ /* */ /* BEGIN INITIALIZE */ /* */ bool loop = true; cout << "MAGIC SQUARE CONSTRUCTION PROGRAM \nBUILD VERSION " << LATEST_VERSION << "\nLAST REVISED " << REVISION_DATE << "\nCOPYRIGHT " << AUTHOR << "\n\n\n"; /* END INITIALIZE */ while(loop){ cout << "Enter command (or type 'help' for command list): "; string str; getline(cin, str); for(unsigned int z = 0; z < str.length(); z++) str[z] = tolower(str[z]); cout << endl; /* */ /* BEGIN CHECK USER INPUT */ /* */ if(str == "help") showCommands(); else if(str == "exit" || str == "quit") loop = false; else if(str == "generate squares"){ int remaining[NSQ]; STDMatrix builder; for(int i = 0; i < NSQ; i++) remaining[i] = 0; cout << "Generating Order-" << N << " squares. . . \n\n"; generateOrder4(remaining, builder, 1); cout << "All squares built."; } else if(str.find("output square ") != -1){ if(magics.size() == 0) throwException(1); else{ unsigned int a = atoi(str.substr(14).c_str()) - 1; if(a <= magics.size() - 1 && a >= 0) magics[a].print(); else throwException(2); } } else if(str.find("output squares ") != -1){ if(magics.size() == 0) throwException(1); else{ int pos = str.find("to") - 1; unsigned int a = atoi(str.substr(15, pos-2).c_str()) - 1; unsigned int b = atoi(str.substr(pos+3).c_str()) - 1; while(a <= b){ if(a <= magics.size() - 1 && a >= 0){ magics[a].print(); if(a != b) cout << "\n\n\n"; a++; } else{ throwException(2); break; } } } } else if(str.find("output type ") != -1){ if(magics.size() == 0) throwException(1); else{ unsigned int a = atoi(str.substr(12).c_str()); for(unsigned int i = 0; i < magics.size(); i++){ if(magics[i].getType() == a){ magics[i].print(); cout << "\n\n\n"; } } } } else if(str == "permute upper triangular"){ if(magics.size() == 0) throwException(1); else{ cout << "Permuting squares as upper triangular. . .\n\n"; permuteUT(); cout << "Permutation complete."; } } else if(str == "check square equality"){ if(magics.size() == 0) throwException(1); else{ cout << "Finding unique squares after tests for equality. . .\n\n"; findUnique_Comparison(); cout << "Unique squares found."; } } else if(str == "classify squares"){ if(magics.size() == 0) throwException(1); else{ cout << "Classifying squares as Dudeney Types. . .\n\n"; classify4(); cout << "Classification complete." << endl << "Remember to reclassify squares after any operation!"; } } else if(str == "sort squares"){ if(magics.size() == 0) throwException(1); else{ cout << "Sorting squares from least to greatest. . .\n\n"; sortLinearCompare(); cout << "Sorting complete."; } } else if(str == "find unique squares"){ if(magics.size() == 0) throwException(1); else{ cout << "Finding unique squares after tests for permutations. . .\n\n"; findUnique_Permute(); cout << "\nUnique squares found."; } } else if(str == "analysis"){ if(magics.size() == 0){ cout << "There are currently 0 squares created." << endl << "Generate squares for further details."; } else{ cout << "There are currently " << magics.size() << " squares created." << endl; if(magics[0].getType() == -1) cout << "Classify squares for further details."; else classList(); } } else if(str == "run program") runProg(); else cout << "Unknown Command '" << str << "'"; /* END CHECK USER INPUT */ cout << endl << endl; } return 0; }