Advertisement
Guest User

Last stretch

a guest
Apr 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.71 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp1
  9.     {
  10.         class Program
  11.         {
  12.  
  13.             static void CalcMin(Decimal[] grades)
  14.             {
  15.                 grades.Min().ToString();
  16.                 Console.WriteLine("the minimum grade is: " + grades.Min());
  17.                 return;
  18.             }
  19.  
  20.             static void CalcMax(Decimal[] grades)
  21.             {
  22.                 grades.Max().ToString();
  23.                 Console.WriteLine("the Maximum is: " + grades.Max());
  24.                 return;
  25.             }
  26.  
  27.             static decimal SumGrades(Decimal[] grades)
  28.             {
  29.  
  30.                 decimal Sum = 0;
  31.                 foreach (Decimal singlegrade in grades)
  32.                 {
  33.                     Sum = Sum + singlegrade;
  34.                 }
  35.                 Console.WriteLine("The sum of all the grades is: " + Sum);
  36.                 return Sum;
  37.             }
  38.  
  39.             static Decimal Calcaverage(Decimal Sum, int num)
  40.             {
  41.                 Decimal average = (Sum / num);
  42.                 Console.WriteLine("the average of the grades is: " + average);
  43.                 return average;
  44.             }
  45.  
  46.             static decimal CalcFailed(Decimal[] grades, int num)
  47.             {
  48.  
  49.                 decimal fail = 0;
  50.                 for (int i = 0; i < num; i++)
  51.                 {
  52.                     if (grades[i] < 50)
  53.                     {
  54.                         Console.WriteLine();
  55.                         fail = fail + 1;
  56.                     }
  57.                 }
  58.                 Console.WriteLine("the number of students who failed is: " + fail);
  59.                 return fail;
  60.             }
  61.  
  62.             static decimal CalcPassed(Decimal[] grades, int num)
  63.             {
  64.                 decimal pass = 0;
  65.  
  66.                 for (int i = 0; i < num; i++)
  67.                 {
  68.                     if (grades[i] >= 50)
  69.                     {
  70.                         Console.WriteLine();
  71.                         pass = pass + 1;
  72.                     }
  73.                 }
  74.  
  75.                 Console.WriteLine("the number of students who passed is: " + pass);
  76.                 return pass;
  77.             }
  78.  
  79.             static decimal Failedpercent(decimal fail, int num)
  80.             {
  81.             decimal percentfail = fail / num;
  82.                 Console.WriteLine("the percentage of students who failed is: " + percentfail);
  83.                 return percentfail;
  84.             }
  85.  
  86.             static decimal Passpercent(decimal pass, int num)
  87.             {
  88.                 Decimal percentpass = pass / num;
  89.                 Console.WriteLine("the percentage of the perople who passed is: " + percentpass);
  90.                 return percentpass;
  91.             }
  92.  
  93.             static Tuple<string[], string[], string[], string[], int> Enterinfo()
  94.  
  95.             {
  96.                 Console.WriteLine("How many students do you have? ");
  97.  
  98.                 int num = int.Parse(Console.ReadLine());
  99.                 string[] snum = new string[num];
  100.  
  101.                 string[] lastnames = new string[num];
  102.  
  103.                 string[] firstnames = new string[num];
  104.  
  105.                 string[] grades = new string[num];
  106.  
  107.  
  108.                 for (int i = 0; i < num; i++)
  109.  
  110.                 {
  111.  
  112.                     Console.WriteLine("What is student #" + (i + 1) + "'s Student ID number? ");
  113.  
  114.                     snum[i] = Console.ReadLine();
  115.  
  116.                     Console.WriteLine("What is student #" + (i + 1) + "'s first name? ");
  117.  
  118.                     firstnames[i] = Console.ReadLine();
  119.  
  120.                     Console.WriteLine("What is student #" + (i + 1) + "'s last name? ");
  121.  
  122.                     lastnames[i] = Console.ReadLine();
  123.  
  124.                     Console.WriteLine("What is student #" + (i + 1) + "'s grade? ");
  125.  
  126.                     grades[i] = Console.ReadLine();
  127.  
  128.  
  129.                 }
  130.                 Console.WriteLine(".............");
  131.                 for (int i = 0; i < num; i++)
  132.                 {
  133.                     Console.WriteLine("student #" + (i + 1));
  134.                     Console.WriteLine(firstnames[i] + " ");
  135.                     Console.WriteLine(lastnames[i] + " ");
  136.                     Console.WriteLine(snum[i] + " ");
  137.                     Console.WriteLine(grades[i] + " ");
  138.                 }
  139.                 Console.WriteLine();
  140.                 var Input = Tuple.Create<string[], string[], string[], string[], int>(snum, lastnames, firstnames, grades, num);
  141.                 return Input;
  142.  
  143.             }
  144.  
  145.  
  146.  
  147.  
  148.             static string[] Statistics(string[] snum, Decimal[] grades, int num)
  149.             {
  150.  
  151.                 CalcMin(grades);
  152.                 CalcMax(grades);
  153.                 Calcaverage(SumGrades(grades), num);
  154.                 Failedpercent(CalcFailed(grades, num), num);
  155.                 Passpercent(CalcPassed(grades, num), num);
  156.                 return null;
  157.             }
  158.             static Tuple<string[], string[], string[], Decimal[], int> Changeinfo(string[] snum, string[] firstnames, string[] lastnames, Decimal[] grades, int num)
  159.             {
  160.            
  161.             Console.WriteLine("Please enter which Student number you want to find?");
  162.             string sd = Console.ReadLine();
  163.             for (int i = 0; i < num; i++)
  164.  
  165.             {
  166.                 if (sd == snum[i])
  167.  
  168.                 {
  169.  
  170.                     Console.WriteLine("Student ID: " + snum[i] + "Last Name: " + firstnames[i] + "First name: " + lastnames[i] + "Current Grade: " + grades[i].ToString() + " ");
  171.  
  172.                     Console.WriteLine("What is student #" + snum[i] + "'s first name? ");
  173.  
  174.                     firstnames[i] = Console.ReadLine();
  175.  
  176.                     Console.WriteLine("What is student #" + snum[i] + "'s last name? ");
  177.  
  178.                     lastnames[i] = Console.ReadLine();
  179.  
  180.                     Console.WriteLine("What is student #" + snum[i] + "'s grade? ");
  181.  
  182.                     grades[i] = Decimal.Parse(Console.ReadLine());
  183.  
  184.                     Console.Clear();
  185.                    
  186.                     break;
  187.  
  188.                 }
  189.                
  190.             }
  191.             Console.ReadLine();
  192.             var Change = Tuple.Create<string[], string[], string[], Decimal[], int>(snum, lastnames, firstnames, grades, num);
  193.             return Change;
  194.             }
  195.  
  196.             private static void Main(string[] args)
  197.             {
  198.                 char answer;
  199.  
  200.                 Console.WriteLine("List of possible tasks");
  201.  
  202.                 Console.WriteLine("Enter new information. Press 1");
  203.  
  204.                 Console.WriteLine("Print statistics. Press 2");
  205.  
  206.                 Console.WriteLine("Change entered information. Press 3");
  207.                 string[] snum = new string[1];
  208.  
  209.                 string[] lastnames = new string[1];
  210.  
  211.                 string[] firstnames = new string[1];
  212.  
  213.                 Decimal[] grades = new Decimal[1];
  214.  
  215.                 int num = 0;
  216.            
  217.                 do
  218.                 {
  219.                     Console.Write("Please select a task");
  220.                     string x = Console.ReadLine();
  221.  
  222.                     switch (x)
  223.  
  224.                     {
  225.  
  226.                         case "1":
  227.                             Tuple<string[], string[], string[], string[], int> returned = Enterinfo();
  228.                         snum = returned.Item1;
  229.                         firstnames = returned.Item2;
  230.                         lastnames = returned.Item3;
  231.                         grades = Array.ConvertAll(returned.Item4, Decimal.Parse);
  232.                         num = returned.Item5;
  233.  
  234.                         break;
  235.  
  236.                         case "2":
  237.  
  238.                             Statistics(snum, grades, num);
  239.  
  240.                             break;
  241.  
  242.                         case "3":
  243.                         Tuple<string[], string[], string[], Decimal[], int> changed = Changeinfo(snum, firstnames, lastnames, grades, num);
  244.                         snum = changed.Item1;
  245.                         firstnames = changed.Item2;
  246.                         lastnames = changed.Item3;
  247.                         grades = changed.Item4;
  248.                         num = changed.Item5;
  249.                        
  250.                             break;
  251.  
  252.                         default:
  253.  
  254.                             Console.WriteLine("Invalid response.");
  255.  
  256.                             break;
  257.  
  258.                     }
  259.  
  260.                     Console.Write("Do you want to issue an addistion action");
  261.  
  262.                     answer = Char.Parse(Console.ReadLine());
  263.  
  264.                 } while (answer == ('y' | 'Y'));
  265.  
  266.                 Console.WriteLine("Thank you have a good day!");
  267.  
  268.                 Console.ReadLine();
  269.             }
  270.         }
  271.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement