コード例 #1
0
ファイル: Common_Code.cs プロジェクト: Zapafaz/CIS210-Project
        /// <summary>
        /// Searches and creates a log that tracks how many iterations the search takes
        /// </summary>
        /// <param name="searchType">The type of search to be performed</param>
        /// <param name="searchQuery">The query to search for</param>
        /// <param name="addToName">An additional item to add to the log file name</param>
        public static void CreateSearchLog(string searchType, string searchQuery, string addToName)
        {
            // Searches and writes log based on search type and informs user of what it created
            try
            {
                string fileName = GetLogFilePath(searchType, addToName);

                var counter = 0;

                // Writes to log file for every index searched
                using (var logger = new StreamWriter(fileName))
                {
                    // Searches every location of the array, in sequence
                    if (searchType == serializedSearch)
                    {
                        for (int page = 0; page < virtualMemory.GetLength(0); page++)
                        {
                            for (int row = 0; row < virtualMemory.GetLength(1); row++)
                            {
                                for (int col = 0; col < virtualMemory.GetLength(2); col++)
                                {
                                    // if searchQuery is blank, write a 1 for every virtualNull (-99) found, and write the character for everything else
                                    if (searchQuery == blank)
                                    {
                                        if (virtualMemory[page, row, col] == virtualNull)
                                        {
                                            logger.WriteLine("1");
                                        }

                                        else
                                        {
                                            logger.WriteLine("{0}", (char)virtualMemory[page, row, col]);
                                        }
                                    }

                                    // if searchQuery is anything besides blank, write when it finds an instance of searchQuery
                                    // Then add a pointer for the location where it found searchQuery
                                    // also writes a 0 for other characters and a 1 for virtualNull
                                    else if (searchQuery != blank)
                                    {
                                        char[] searchChars = searchQuery.ToCharArray();
                                        var    intQuery    = (int)searchChars[0];

                                        if (virtualMemory[page, row, col] == virtualNull)
                                        {
                                            logger.WriteLine("1");
                                        }

                                        else if (virtualMemory[page, row, col] == intQuery)
                                        {
                                            logger.WriteLine("{0}", searchQuery);
                                            memLoc[counter] = new Ptr(page, row, col);
                                            counter++;
                                        }

                                        else
                                        {
                                            logger.WriteLine("0");
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Searches only the "upper left" location of every page (i.e. [page, 0, 0]), in sequence
                    else if (searchType == indexSearch)
                    {
                        for (int page = 0; page < virtualMemory.GetLength(0); page++)
                        {
                            // Writes a 1 for every blank page, by checking the "upper left" location of each page (i.e. [page, 0, 0])
                            if (virtualMemory[page, 0, 0] == virtualNull)
                            {
                                logger.WriteLine("1");
                            }

                            // Writes the character at "upper left" of non-blank pages (e.g. [10, 0, 0] will have some TCOTLB character printed)
                            else if (searchQuery == blank)
                            {
                                logger.WriteLine("{0}", (char)virtualMemory[page, 0, 0]);
                            }
                        }
                    }
                }

                // If the query was 'T', sends total number of searchQuery's (i.e. 'T's) found to T to Q conversion method in week 5
                if (searchQuery == "T")
                {
                    Week_5_Class.ConvertTtoQ(counter);
                }
            }

            // Writes an error if something goes wrong creating the log (e.g. wrong permissions)
            catch (Exception e)
            {
                Console.WriteLine("{0}{1}", genericError, e);
            }
        }
コード例 #2
0
ファイル: Intro_Outro.cs プロジェクト: Zapafaz/CIS210-Project
        /// <summary>
        /// Prompts the user to select which section (week) to run
        /// </summary>
        /// <remarks>Week input do-while loop had a bug almost the whole semester where it wasn't actually doing anything because I used && (AND) instead of || (OR). Whoops.</remarks>
        private static void WeekSelect()
        {
            // Tests input for valid integers (1 through 16), asks again if input is invalid
            var weekInput = 0;

            do
            {
                Common_Code.CenterWrite("Enter class week (1 to 16)");
                var input = Console.ReadLine();
                int.TryParse(input, out weekInput);
            } while ((weekInput <= 0) || (weekInput > 16));

            var labWeek = string.Format("Week {0} was a lab week. Please choose a different week.", weekInput);

            var futureWeek = string.Format("We aren't at week {0} yet. Please choose a different week.", weekInput);

            // Sends user to Week_#_Class.Method based on input, restarts WeekSelect method if incorrect input
            // Defaults to restarting WeekSelect method
            switch (weekInput)
            {
            case 1:
                Week_1_Class.TextToASCIIdec();
                break;

            case 2:
                Week_2_Class.PoemReadWrite();
                break;

            case 3:
                // Sends user to choose which search method to use
                // Figure we might implement more searches later on down the line
                // Can just point back to this case for those weeks
                Common_Code.ChooseSearch();
                break;

            case 4:
                Console.WriteLine(labWeek);
                WeekSelect();
                break;

            case 5:
                Week_5_Class.FindUppercaseT();
                break;

            case 6:
                Week_6_Class.VirtualStacks();
                break;

            case 7:
                goto case 4;

            case 8:
                Week_8_Class.VirtualQueue();
                break;

            case 9:
                goto case 4;

            case 10:
                // Create new instance of Week_10_Class and start the BubbleSortAndLog method from that class
                var week_10 = new Week_10_Class();
                week_10.BubbleSortAndLog();
                break;

            case 11:
                Week_11_Class.FrequencySortAndLog();
                break;

            case 12:
                goto case 16;

            case 13:
                goto case 16;

            case 14:
                goto case 16;

            case 15:
                goto case 16;

            case 16:
                Week_12_Class.SortComparisons();
                break;

            default:
                Console.WriteLine("Entered {0} week, ended in default case - please select a valid week", weekInput);
                WeekSelect();
                break;
            }
        }