コード例 #1
0
 public static void PoemReadWrite()
 {
     Common_Code.ShowHeader();
     // Calls the rest of the Week_2_Class methods
     PoemReader();
     PoemWriter();
 }
コード例 #2
0
        /// <summary>
        /// Show header, initialize virtualMemory, bubble sort poems by incremented segments and log number of exchanges used by each sort
        /// </summary>
        public void BubbleSortAndLog()
        {
            // Shows a header in the console similar to the comment at the top of this file
            Common_Code.ShowHeader();

            // Initializes all virtualMemory locations to -99
            Common_Code.VirtualMemoryInit();

            // Reads all three of the poems (TCOTLB.txt, RC.txt, GEAH.txt) in textDir (C:\devel\TFiles\)
            Week_2_Class.PoemReader();

            // Search virtualMemory for the text of the poems and put it in an array
            int[] allPoems = GetPoemsInVirtualMemory();

            int totalPoemsLength = allPoems.Length;

            // Variable to track the number of exchanges used in a sort
            int exchanges;

            // Sort a segment of allPoems of size 10
            exchanges = BubbleSortSegment(allPoems, 10);

            // Write the log from the size 10 sort
            WriteEfficiencyLog(10, exchanges, Common_Code.bubbleSort);

            // Sort and log segments of the array starting at 100 and incrementing by 100 every time (100, 200, 300, etc) up to 2000
            for (int i = 100; i <= 2000; i += 100)
            {
                exchanges = BubbleSortSegment(allPoems, i);
                WriteEfficiencyLog(i, exchanges, Common_Code.bubbleSort);
            }

            bool keepSorting = Common_Code.YesNo("Keep sorting segments from size 2000 to 5927 (may take a few minutes)");

            if (keepSorting)
            {
                // Sort and log segments of the array starting at 2000 and incrementing by 100 every time (2000, 2100, 2200, etc) up to 5900
                for (int i = 2000; i <= totalPoemsLength; i += 100)
                {
                    exchanges = BubbleSortSegment(allPoems, i);
                    WriteEfficiencyLog(i, exchanges, Common_Code.bubbleSort);
                }

                // Sort the entire array
                exchanges = BubbleSort(allPoems);

                // Write the log for the full sort
                WriteEfficiencyLog(totalPoemsLength, exchanges, Common_Code.bubbleSort);
            }

            // Write all locations in the sortable source array to log file for debugging
            Common_Code.IntArrayLog(allPoems, "AllPoems");

            // Write all locations in virtual memory to log file for debugging
            Common_Code.VirtualMemoryLog(10, true);
        }
コード例 #3
0
ファイル: Intro_Outro.cs プロジェクト: Zapafaz/CIS210-Project
        static void Main(string[] args)
        {
            Common_Code.ShowHeader();
            WeekSelect();

            // Calls CenterWrite method and sends it the given string to display centered in console
            Common_Code.CenterWrite("Press Enter to open the log folder and exit the program...");
            Console.ReadLine();
            Common_Code.OpenLogFolder();
        }
コード例 #4
0
        public static void TextToASCIIdec()
        {
            Common_Code.ShowHeader();

            var textDir = Common_Code.textDir;

            // Calls TFileSelect method to find what text file they want to use (in this case for conversion)
            var fileToConv = TFileSelect();

            // Appends "ConV" to filename based on chosen file, assigns result to newFile
            var newFile = "ConV" + fileToConv;

            // Confirmation of chosen file, option to restart method to choose new file; if they choose no (YesNo method returns false), restarts method
            Console.WriteLine("The contents of {0} will be read to ASCII decimal values\nValues will output to new file {1}", fileToConv, newFile);
            if (!Common_Code.YesNo("Is this ok?"))
            {
                TextToASCIIdec();
            }

            // Uses StreamReader.Read method to read one character at a time from the text file
            // Then uses StreamReader.WriteLine method to write ASCII decimal value for each character
            // Writes to a file with newFile variable as name, in the textDir folder
            using (var readChar = new StreamReader(textDir + fileToConv))
            {
                var currentChar = readChar.Read();
                using (var write = new StreamWriter(textDir + newFile))
                {
                    while (currentChar != -1)
                    {
                        write.WriteLine("{0}", currentChar);
                        currentChar = readChar.Read();
                    }
                }
            }

            // Tells user what it did, asks if they'd like to convert another file
            // If YesNo method returns true, restarts TextToASCIIdec method
            Console.WriteLine("Converted {0} to {1}", fileToConv, newFile);
            if (Common_Code.YesNo("Would you like to convert another file?"))
            {
                TextToASCIIdec();
            }
        }
コード例 #5
0
        /// <summary>
        /// Perform sorts (bucket, frequency, bubble) on a page of randomized integers in virtual memory and log their efficiency.
        /// </summary>
        public static void SortComparisons()
        {
            Common_Code.ShowHeader();

            Common_Code.VirtualMemoryInit();

            int pageToTwoDBucketSort = 200;
            int pageToFrequencySort  = 205;
            int pageToBubbleSort     = 210;

            // Use the default 0 and 1,500,000 as min and max to populate the pages with random numbers.
            // Not counting this towards the logCounter value since it's not part of the sorts being performed.
            PopulatePage(pageToTwoDBucketSort, minValue, maxValue);
            PopulatePage(pageToFrequencySort, minValue, maxValue);
            PopulatePage(pageToBubbleSort, minValue, maxValue);

            // Increment this value by 1 every time a variable (other than the logCount variable itself) changes.
            // Includes variable changes in iterators (e.g. for (int i = 0; i < 100; i++) should increase logCount by 1 for each iteration, for a total of 100).
            // Does not include variable declaration/initialization.
            int logCount = 0;

            // FindMinAndMax() Reassigns minValue and maxValue to whatever the lowest and highest numbers that were generated are (respectively).
            // Tracks how many iterations it takes (17 * 80 = 1360) to find the min and max values so it can be added to logCount.
            // Also, not every sort uses minValue and maxValue - only Frequency Sort and Bucket Sort, so I'm only increasing logCount by this for those sorts.
            int findMinAndMax = FindMinAndMax(pageToTwoDBucketSort);

            #region Sorts
            #region 2-Dimensional Bucket Sort
            // Set logCount to findMinAndMax since BucketSort uses them
            logCount += findMinAndMax;

            // Get the number of times to log based on operations performed during the bucket sort (i.e. total variable assignments it took to sort).
            logCount += TwoDBucketSortPage(pageToTwoDBucketSort);

            Week_10_Class.WriteEfficiencyLog(pageSize, logCount, Common_Code.arrayBucketSort);

            Console.WriteLine("After bucket sort on page {0}, is it sorted?: {1}", pageToTwoDBucketSort, IsPageSorted(pageToTwoDBucketSort));
            Common_Code.DisplayFooter();
            #endregion

            #region Frequency Sort
            // Reset logCount to findMinAndMax for frequency sort.
            logCount = findMinAndMax;

            logCount += FrequencySortPage(pageToFrequencySort);

            Week_10_Class.WriteEfficiencyLog(pageSize, logCount, Common_Code.frequencySort);

            Console.WriteLine("After frequency sort on page {0}, is it sorted?: {1}", pageToFrequencySort, IsPageSorted(pageToFrequencySort));
            Common_Code.DisplayFooter();
            #endregion

            #region Bubble Sort
            // Reset logCount to 0 for bubble sort.
            logCount = 0;

            // Get number of times to log based on bubble sort operations.
            logCount += LazyBubbleSortPage(pageToBubbleSort);

            Week_10_Class.WriteEfficiencyLog(pageSize, logCount, Common_Code.bubbleSort);

            Console.WriteLine("After bubble sort on page {0}, is it sorted?: {1}", pageToBubbleSort, IsPageSorted(pageToBubbleSort));
            Common_Code.DisplayFooter();
            #endregion
            #endregion

            // Writes locations in virtual memory to a log, excluding -99 (virtualNull), so the sorts can be manually checked for correctness.
            Common_Code.VirtualMemoryLog(12, false);
        }
コード例 #6
0
        /// <summary>
        /// Use frequency sort to sort the poems and log the efficiency of the algorithm.
        /// </summary>
        public static void FrequencySortAndLog()
        {
            // Shows a header in the console similar to the comment at the top of this file
            Common_Code.ShowHeader();

            // Initializes all virtualMemory locations to -99
            Common_Code.VirtualMemoryInit();

            // Reads all three of the poems (TCOTLB.txt, RC.txt, GEAH.txt) in textDir (C:\devel\TFiles\)
            Week_2_Class.PoemReader();

            // Search virtualMemory for the text of the poems and put it in an array
            int[] allPoems = Week_10_Class.GetPoemsInVirtualMemory();

            // Set log count to total poem array length, since part of this algorithm is loading the poems into the array.
            int logOneCount = allPoems.Length;

            // Round the length of allPoems down to nearest 100
            // Integer division always rounds down so by dividing by 100 then multiplying by 100 we get the value we want
            // Examples:
            // 5927 / 100 = 59.27; C# rounds int to 59; 59 * 100 = 5900
            // 5977 / 100 = 59.77; C# rounds int to 59; 59 * 100 = 5900
            int poemLengthDownToHundred = allPoems.Length / 100 * 100;

            // Frequency sort segment of size i
            // Increase log count by the number of operations performed by a segment sort of size 10
            // 255 represents the size of the frequency counters array (i.e. ASCII values 0-255); Parameter exists in case I want to frequency sort things other than ASCII
            logOneCount += FrequencySortSegment(allPoems, 10, 255);

            // Write a log file with a 1 for the value of logOneCount
            Week_10_Class.WriteEfficiencyLog(10, logOneCount, Common_Code.frequencySort);

            // Repeat above processes for segments of size 100, 200, 300...5900, then size allPoems.Length
            for (int i = 100;
                 i <= allPoems.Length;
                 i = i < poemLengthDownToHundred ? (i + 100) : allPoems.Length)
            {
                // Set log count to total poem array length, since part of this algorithm is loading the poems into the array.
                logOneCount = allPoems.Length;

                // Frequency sort a segment of allPoems, segment size: i (100, 200, 300, etc)
                // Increase log count by the number of operations performed by that sort
                logOneCount += FrequencySortSegment(allPoems, i, 255);

                // Write a log file with a 1 for the value of logOneCount
                Week_10_Class.WriteEfficiencyLog(i, logOneCount, Common_Code.frequencySort);

                // Break out of loop if i == allPoems.Length, otherwise infinite loop
                if (i == allPoems.Length)
                {
                    break;
                }

                // Expanded version of above ? : ternary operation (in for() loop iterator)
                //if (i < poemLengthDownToHundred)
                //{
                //    i += 100;
                //}
                //else
                //{
                //    i = allPoems.Length;
                //}
            }

            // Open the log folder path given in Common_Code.logDir in explorer
            Common_Code.OpenLogFolder();
        }