Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.68 KB | None | 0 0
  1. //***Written by Sam Hill HIL12447299***
  2.  
  3.  
  4. using System;
  5. using System.IO;
  6. using System.Text.RegularExpressions;
  7. //System.IO and System.Text.RegularExpressions is needed to use Regex.Split and File.ReadAllText
  8.  
  9. class studentGradeDist
  10. {
  11.     public static void Main()
  12.     {
  13.     //Try statement will run all my main code first
  14.     try
  15.     {
  16.         for (int gradeLine = 0; gradeLine <= 11; gradeLine +=2)
  17.         //For loop will loop my code until gradeLine is = 11
  18.         {
  19.             Console.WriteLine("0    10   20   30   40   50   60   70   80   90  100");             
  20.             Console.WriteLine("|    |    |    |    |    |    |    |    |    |    |");
  21.             Console.WriteLine("***************************************************");
  22.             //Simple Console.WriteLine table formatting
  23.            
  24.            
  25.             string gradeText = File.ReadAllText("grades_multiple.txt");
  26.             string[] gradeTextLine = Regex.Split(gradeText, "\r\n");
  27.             //Read the text file into a string array
  28.             //Split the string on each line
  29.            
  30.             Console.WriteLine(gradeTextLine[gradeLine]);
  31.             //Display the course name with Console.WriteLine
  32.            
  33.            
  34.             double count = 0;
  35.             //Creating a variable to hold the value of the amount of chars in the foreach loop
  36.             //Only one is needed because it will reset after each loop
  37.            
  38.             foreach (char a in gradeTextLine[gradeLine + 1])
  39.             {
  40.             if (a == 'A')
  41.             {
  42.             count++;
  43.             Console.Write("*");
  44.             }
  45.             }
  46.             Console.Write(" A\n");
  47.             //Foreach loop and if statement used to count every character that is equal to the if statement
  48.             //Console.Write is then used to display the corresponding number of asterisks
  49.            
  50.            
  51.             foreach (char b in gradeTextLine[gradeLine + 1])
  52.             {
  53.             if (b == 'B')
  54.             {
  55.             count++;
  56.             Console.Write("*");
  57.             }
  58.             }
  59.             Console.Write(" B\n");
  60.             //Foreach loop and if statement used to count every character that is equal to the if statement
  61.             //Console.Write is then used to display the corresponding number of asterisks
  62.            
  63.             foreach (char c in gradeTextLine[gradeLine + 1])
  64.             {
  65.             if (c == 'C')
  66.             {
  67.             count++;
  68.             Console.Write("*");
  69.             }
  70.             }
  71.             Console.Write(" C\n");
  72.             //Foreach loop and if statement used to count every character that is equal to the if statement
  73.             //Console.Write is then used to display the corresponding number of asterisks
  74.            
  75.             foreach (char d in gradeTextLine[gradeLine + 1])
  76.             {
  77.             if (d == 'D')
  78.             {
  79.             count++;
  80.             Console.Write("*");
  81.             }
  82.             }
  83.             Console.Write(" D\n");
  84.             //Foreach loop and if statement used to count every character that is equal to the if statement
  85.             //Console.Write is then used to display the corresponding number of asterisks
  86.            
  87.             foreach (char e in gradeTextLine[gradeLine + 1])
  88.             {
  89.             if (e == 'E')
  90.             {
  91.             count++;
  92.             Console.Write("*");
  93.             }
  94.             }
  95.             Console.Write(" E\n");
  96.             //Foreach loop and if statement used to count every character that is equal to the if statement
  97.             //Console.Write is then used to display the corresponding number of asterisks
  98.            
  99.             foreach (char f in gradeTextLine[gradeLine + 1])
  100.             {
  101.             if (f == 'F')
  102.             {
  103.             countw++;
  104.             Console.Write("*");
  105.             }
  106.             }
  107.             Console.Write(" F\n");
  108.             //Foreach loop and if statement used to count every character that is equal to the if statement
  109.             //Console.Write is then used to display the corresponding number of asterisks
  110.         }
  111.     }
  112.     catch (Exception e)
  113.     //Catch statement will catch any exceptions within the try statement
  114.     {
  115.         Console.WriteLine("Exception caught: \n\n {0}", e.Message);
  116.     }
  117.     finally
  118.     //finally statement will show no matter if the catch statement catches anything or not
  119.     {
  120.         Console.WriteLine("\n\n--- Done with exception handling ---");
  121.         Console.ReadLine();
  122.         //Console.ReadLine is used to prevent the program from exiting
  123.     }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement