static void Main(string[] args) { //Program class instantiations Menu m1 = Menu.Instance; KbIn kb1 = new KbIn(); //local variables string[] setup, digits; string prompt, input, Occupation, Classification; string keyIn, temp; int origWidth, origHeight, score; string path = "IQProgramErrorLog.txt"; bool error, debug; string announce = "An IQ score of "; string announce2 = " is rated "; string announce3 = "A recommended occupation for this level of IQ is "; //Initialize local variables setup = new string[] { "D1", "D2", "D3" }; digits = new string[] { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "NUMPAD0", "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD4", "NUMPAD5", "NUMPAD6", "NUMPAD7", "NUMPAD8", "NUMPAD9", "Backspace", "Enter" }; prompt = "(Numeric value 20 - 200 required) Enter an IQ score > "; input = ""; error = false; debug = debugging; //Display menu, process user choices - Main loop while (true) { Console.Clear(); m1.displayMenu(); keyIn = kb1.readKey(setup); switch (keyIn) { case "D1": origWidth = Console.WindowWidth; origHeight = Console.WindowHeight; error = false; input = ""; //IntegerDivide(0, 0); Fibonacci(8); if (!error) { GetInput(prompt, ref input, ref error); } Console.SetWindowSize(4, 4); //Smallify console during tests //Test GetInput input parameter results if (!(debug && error)) { IsInputNotEmpty(input, ref error); } if (!(debug && error)) { IsInputANumber(input, ref error); } //Input tests passed //Convert input to score score = 0; //if (!error) {GetScore(input, ref score);}; //Test GetScore parameter results if (!(debug && error)) { IsScoreANumber(score, ref error); } if (!(debug && error)) { IsScoreGreaterThanMinimumIQ(score, MinimumIQ, ref error); } if (!(debug && error)) { IsScoreLessThanMaximumIQ(score, MaximumIQ, ref error); } //Score tests passed Console.SetWindowSize(origWidth, origHeight); //Restore console after tests Classification = ""; //if (!error) { GetClassifier(score, ref Classification); } //Test GetClassification parameter results if (!(debug && error)) { IsClassificationValid(Classification, ref error); } if (!(debug && error)) { IsClassificationRight(score, Classification, ref error); } Occupation = ""; //if (!error) { GetOccupation(score, ref Occupation); } //Test GetOccupation parameter results if (!(debug && error)) { IsOccupationValid(Occupation, ref error); } if (!(debug && error)) { IsOccupationRight(score, Occupation, ref error); } Console.WriteLine(); Console.WriteLine(); if (!error) { temp = announce + input + announce2 + Classification + "."; Console.WriteLine(); Console.WriteLine(temp); Console.WriteLine(); temp = announce3 + Occupation + "."; Console.WriteLine(temp); Console.WriteLine(); Console.WriteLine(); Console.Write("IQ processed. Press enter to return to the main menu> "); } else { Console.Write("IQ processing failed. Press enter to return to the main menu> "); } do { temp = kb1.readKey(digits); } while (temp != "Enter"); break; case "D2": Console.Clear(); Console.WriteLine(); if (File.Exists(path)) { using (StreamReader sr = File.OpenText(path)) { string s = ""; while ((s = sr.ReadLine()) != null) { Console.WriteLine(s); } } Console.WriteLine(); Console.WriteLine(); Console.Write("Data displayed. Press enter to continue"); do { temp = kb1.readKey(digits); } while (temp != "Enter"); } else { Console.WriteLine(); Console.WriteLine(); Console.Write("No data file found. Press enter to continue"); do { temp = kb1.readKey(digits); } while (temp != "Enter"); } break; case "D3": return; default: break; } } }
// IQ Processing subroutines static void GetInput(string prompt, ref string token, ref bool error) { KbIn kb1 = new KbIn(); string[] alphas, digits, period, alphas_w_space, digits_0_1, digits_1_2, digits_1_9, digits_0_3, all; string blanks = " "; int orgCursorRow, orgCursorColumn; bool test; string temp; digits = new string[] { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "NUMPAD0", "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD4", "NUMPAD5", "NUMPAD6", "NUMPAD7", "NUMPAD8", "NUMPAD9", "Backspace", "Enter" }; alphas = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "Backspace", "Enter" }; period = new string[] { "OemPeriod", "Backspace", "Enter" }; alphas_w_space = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "Backspace", "Enter", "Spacebar" }; digits_0_1 = new string[] { "D0", "D1", "NUMPAD0", "NUMPAD1", "Backspace", "Enter" }; digits_1_2 = new string[] { "D1", "D2", "NUMPAD1", "NUMPAD2", "Backspace", "Enter" }; digits_1_9 = new string[] { "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD4", "NUMPAD5", "NUMPAD6", "NUMPAD7", "NUMPAD8", "NUMPAD9", "Backspace", "Enter" }; digits_0_3 = new string[] { "D0", "D1", "D2", "D3", "NUMPAD0", "NUMPAD1", "NUMPAD2", "NUMPAD3", "Backspace", "Enter" }; alphas_w_space = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "Backspace", "Enter", "Spacebar" }; digits = new string[] { "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "NUMPAD0", "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD4", "NUMPAD5", "NUMPAD6", "NUMPAD7", "NUMPAD8", "NUMPAD9", "Backspace", "Enter" }; List<String> allkeys = new List<String>(alphas_w_space.Concat<string>(digits)); all = allkeys.ToArray(); Console.Clear(); Console.WriteLine(); Console.WriteLine("IQ Classification program. James Brooks, CST236, Instructor Bhushan Gupta, OIT"); Console.WriteLine(); Console.Write(prompt); orgCursorRow = Console.CursorTop; orgCursorColumn = Console.CursorLeft; test = false; int testnum = 0; while (test == false) { temp = kb1.readKey(digits); if (temp[0] == 'D') { temp = temp.Substring(1, temp.Length - 1); } if (temp == "Backspace") { token = kb1.backspacehandler(token, orgCursorColumn, orgCursorRow, blanks); } else if (temp == "Enter") { try { testnum = Convert.ToInt32(token); } catch (FormatException e) { error = true; } if ((testnum >= MinimumIQ) && (testnum <= MaximumIQ)) { test = true; } } else { if (token.Length < scoreMaxLength) { Console.SetCursorPosition(orgCursorColumn, orgCursorRow); token = token + temp; Console.Write(token); } } } }