Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***Written by Sam Hill HIL12447299***
- using System;
- using System.IO;
- using System.Text.RegularExpressions;
- //System.IO and System.Text.RegularExpressions is needed to use Regex.Split and File.ReadAllText
- class studentGradeDist
- {
- public static void Main()
- {
- //Try statement will run all my main code first
- try
- {
- for (int gradeLine = 0; gradeLine <= 11; gradeLine +=2)
- //For loop will loop my code until gradeLine is = 11
- {
- Console.WriteLine("0 10 20 30 40 50 60 70 80 90 100");
- Console.WriteLine("| | | | | | | | | | |");
- Console.WriteLine("***************************************************");
- //Simple Console.WriteLine table formatting
- string gradeText = File.ReadAllText("grades_multiple.txt");
- string[] gradeTextLine = Regex.Split(gradeText, "\r\n");
- //Read the text file into a string array
- //Split the string on each line
- Console.WriteLine(gradeTextLine[gradeLine]);
- //Display the course name with Console.WriteLine
- double count = 0;
- //Creating a variable to hold the value of the amount of chars in the foreach loop
- //Only one is needed because it will reset after each loop
- foreach (char a in gradeTextLine[gradeLine + 1])
- {
- if (a == 'A')
- {
- count++;
- Console.Write("*");
- }
- }
- Console.Write(" A\n");
- //Foreach loop and if statement used to count every character that is equal to the if statement
- //Console.Write is then used to display the corresponding number of asterisks
- foreach (char b in gradeTextLine[gradeLine + 1])
- {
- if (b == 'B')
- {
- count++;
- Console.Write("*");
- }
- }
- Console.Write(" B\n");
- //Foreach loop and if statement used to count every character that is equal to the if statement
- //Console.Write is then used to display the corresponding number of asterisks
- foreach (char c in gradeTextLine[gradeLine + 1])
- {
- if (c == 'C')
- {
- count++;
- Console.Write("*");
- }
- }
- Console.Write(" C\n");
- //Foreach loop and if statement used to count every character that is equal to the if statement
- //Console.Write is then used to display the corresponding number of asterisks
- foreach (char d in gradeTextLine[gradeLine + 1])
- {
- if (d == 'D')
- {
- count++;
- Console.Write("*");
- }
- }
- Console.Write(" D\n");
- //Foreach loop and if statement used to count every character that is equal to the if statement
- //Console.Write is then used to display the corresponding number of asterisks
- foreach (char e in gradeTextLine[gradeLine + 1])
- {
- if (e == 'E')
- {
- count++;
- Console.Write("*");
- }
- }
- Console.Write(" E\n");
- //Foreach loop and if statement used to count every character that is equal to the if statement
- //Console.Write is then used to display the corresponding number of asterisks
- foreach (char f in gradeTextLine[gradeLine + 1])
- {
- if (f == 'F')
- {
- countw++;
- Console.Write("*");
- }
- }
- Console.Write(" F\n");
- //Foreach loop and if statement used to count every character that is equal to the if statement
- //Console.Write is then used to display the corresponding number of asterisks
- }
- }
- catch (Exception e)
- //Catch statement will catch any exceptions within the try statement
- {
- Console.WriteLine("Exception caught: \n\n {0}", e.Message);
- }
- finally
- //finally statement will show no matter if the catch statement catches anything or not
- {
- Console.WriteLine("\n\n--- Done with exception handling ---");
- Console.ReadLine();
- //Console.ReadLine is used to prevent the program from exiting
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement