Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- static void CalcMin(Decimal[] grades)
- {
- grades.Min().ToString();
- Console.WriteLine("the minimum grade is: " + grades.Min());
- return;
- }
- static void CalcMax(Decimal[] grades)
- {
- grades.Max().ToString();
- Console.WriteLine("the Maximum is: " + grades.Max());
- return;
- }
- static decimal SumGrades(Decimal[] grades)
- {
- decimal Sum = 0;
- foreach (Decimal singlegrade in grades)
- {
- Sum = Sum + singlegrade;
- }
- Console.WriteLine("The sum of all the grades is: " + Sum);
- return Sum;
- }
- static Decimal Calcaverage(Decimal Sum, int num)
- {
- Decimal average = (Sum / num);
- Console.WriteLine("the average of the grades is: " + average);
- return average;
- }
- static decimal CalcFailed(Decimal[] grades, int num)
- {
- decimal fail = 0;
- for (int i = 0; i < num; i++)
- {
- if (grades[i] < 50)
- {
- Console.WriteLine();
- fail = fail + 1;
- }
- }
- Console.WriteLine("the number of students who failed is: " + fail);
- return fail;
- }
- static decimal CalcPassed(Decimal[] grades, int num)
- {
- decimal pass = 0;
- for (int i = 0; i < num; i++)
- {
- if (grades[i] >= 50)
- {
- Console.WriteLine();
- pass = pass + 1;
- }
- }
- Console.WriteLine("the number of students who passed is: " + pass);
- return pass;
- }
- static decimal Failedpercent(decimal fail, int num)
- {
- decimal percentfail = fail / num;
- Console.WriteLine("the percentage of students who failed is: " + percentfail);
- return percentfail;
- }
- static decimal Passpercent(decimal pass, int num)
- {
- Decimal percentpass = pass / num;
- Console.WriteLine("the percentage of the perople who passed is: " + percentpass);
- return percentpass;
- }
- static Tuple<string[], string[], string[], string[], int> Enterinfo()
- {
- Console.WriteLine("How many students do you have? ");
- int num = int.Parse(Console.ReadLine());
- string[] snum = new string[num];
- string[] lastnames = new string[num];
- string[] firstnames = new string[num];
- string[] grades = new string[num];
- for (int i = 0; i < num; i++)
- {
- Console.WriteLine("What is student #" + (i + 1) + "'s Student ID number? ");
- snum[i] = Console.ReadLine();
- Console.WriteLine("What is student #" + (i + 1) + "'s first name? ");
- firstnames[i] = Console.ReadLine();
- Console.WriteLine("What is student #" + (i + 1) + "'s last name? ");
- lastnames[i] = Console.ReadLine();
- Console.WriteLine("What is student #" + (i + 1) + "'s grade? ");
- grades[i] = Console.ReadLine();
- }
- Console.WriteLine(".............");
- for (int i = 0; i < num; i++)
- {
- Console.WriteLine("student #" + (i + 1));
- Console.WriteLine(firstnames[i] + " ");
- Console.WriteLine(lastnames[i] + " ");
- Console.WriteLine(snum[i] + " ");
- Console.WriteLine(grades[i] + " ");
- }
- Console.WriteLine();
- var Input = Tuple.Create<string[], string[], string[], string[], int>(snum, lastnames, firstnames, grades, num);
- return Input;
- }
- static string[] Statistics(string[] snum, Decimal[] grades, int num)
- {
- CalcMin(grades);
- CalcMax(grades);
- Calcaverage(SumGrades(grades), num);
- Failedpercent(CalcFailed(grades, num), num);
- Passpercent(CalcPassed(grades, num), num);
- return null;
- }
- static Tuple<string[], string[], string[], Decimal[], int> Changeinfo(string[] snum, string[] firstnames, string[] lastnames, Decimal[] grades, int num)
- {
- Console.WriteLine("Please enter which Student number you want to find?");
- string sd = Console.ReadLine();
- for (int i = 0; i < num; i++)
- {
- if (sd == snum[i])
- {
- Console.WriteLine("Student ID: " + snum[i] + "Last Name: " + firstnames[i] + "First name: " + lastnames[i] + "Current Grade: " + grades[i].ToString() + " ");
- Console.WriteLine("What is student #" + snum[i] + "'s first name? ");
- firstnames[i] = Console.ReadLine();
- Console.WriteLine("What is student #" + snum[i] + "'s last name? ");
- lastnames[i] = Console.ReadLine();
- Console.WriteLine("What is student #" + snum[i] + "'s grade? ");
- grades[i] = Decimal.Parse(Console.ReadLine());
- Console.Clear();
- break;
- }
- }
- Console.ReadLine();
- var Change = Tuple.Create<string[], string[], string[], Decimal[], int>(snum, lastnames, firstnames, grades, num);
- return Change;
- }
- private static void Main(string[] args)
- {
- char answer;
- Console.WriteLine("List of possible tasks");
- Console.WriteLine("Enter new information. Press 1");
- Console.WriteLine("Print statistics. Press 2");
- Console.WriteLine("Change entered information. Press 3");
- string[] snum = new string[1];
- string[] lastnames = new string[1];
- string[] firstnames = new string[1];
- Decimal[] grades = new Decimal[1];
- int num = 0;
- do
- {
- Console.Write("Please select a task");
- string x = Console.ReadLine();
- switch (x)
- {
- case "1":
- Tuple<string[], string[], string[], string[], int> returned = Enterinfo();
- snum = returned.Item1;
- firstnames = returned.Item2;
- lastnames = returned.Item3;
- grades = Array.ConvertAll(returned.Item4, Decimal.Parse);
- num = returned.Item5;
- break;
- case "2":
- Statistics(snum, grades, num);
- break;
- case "3":
- Tuple<string[], string[], string[], Decimal[], int> changed = Changeinfo(snum, firstnames, lastnames, grades, num);
- snum = changed.Item1;
- firstnames = changed.Item2;
- lastnames = changed.Item3;
- grades = changed.Item4;
- num = changed.Item5;
- break;
- default:
- Console.WriteLine("Invalid response.");
- break;
- }
- Console.Write("Do you want to issue an addistion action");
- answer = Char.Parse(Console.ReadLine());
- } while (answer == ('y' | 'Y'));
- Console.WriteLine("Thank you have a good day!");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement