Advertisement
RMarK0

Untitled

Dec 26th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace ConsoleApp3
  9. {
  10.     class Student
  11.     {
  12.         // уровень 2 задание 1
  13.         public double Sred;
  14.         public int[] Marks;
  15.         public string Name;
  16.         public Student(double Sred, int[] Marks, string Name)
  17.         {
  18.             this.Sred = Sred;
  19.             this.Marks = Marks;
  20.             this.Name = Name;
  21.         }
  22.         public static double CalculateAverage(int[] Marks, double Sred)
  23.         {
  24.             foreach (int mark in Marks)
  25.             {
  26.                 Sred += mark;
  27.             }
  28.             Sred /= Marks.Length;
  29.             return Sred;
  30.         }
  31.     }
  32.     class Program
  33.     {
  34.         static void Main(string[] args)
  35.         {
  36.             string path = @"G:\surnames.txt";
  37.             StreamReader str1 = new StreamReader(path, Encoding.GetEncoding(1251));
  38.  
  39.  
  40.             Student[] students = new Student[5];
  41.             Student st1 = new Student(0, new int[] { 2,3,4,5 },str1.ReadLine());
  42.             st1.Sred = Student.CalculateAverage(st1.Marks, st1.Sred);
  43.             students[0] = st1;
  44.             Student st2 = new Student(0, new int[] { 3,5,5,5 }, str1.ReadLine());
  45.             st2.Sred = Student.CalculateAverage(st2.Marks, st2.Sred);
  46.             students[1] = st2;
  47.             Student st3 = new Student(0, new int[] {  4,5,4,4}, str1.ReadLine());
  48.             st3.Sred = Student.CalculateAverage(st3.Marks, st3.Sred);
  49.             students[2] = st3;
  50.             Student st4 = new Student(0, new int[] {  3,2,4,5}, str1.ReadLine());
  51.             st4.Sred = Student.CalculateAverage(st4.Marks, st4.Sred);
  52.             students[3] = st4;
  53.             Student st5 = new Student(0, new int[] {  2,2,5,4}, str1.ReadLine());
  54.             st5.Sred = Student.CalculateAverage(st5.Marks, st5.Sred);
  55.             students[4] = st5;
  56.  
  57.             Console.WriteLine("\n  Фамилия     \t Средний балл \n ");
  58.  
  59.             foreach (Student student in students)
  60.             {
  61.                 Console.Write("{0,10} \t {1,4}   \t   ", student.Name, student.Sred);
  62.                 foreach (uint mark in student.Marks)
  63.                     Console.Write($" {mark}");
  64.                 Console.WriteLine();
  65.             }
  66.             Console.WriteLine("\n  Фамилия    \t Средний балл \n");
  67.             foreach (Student student in students)
  68.             {
  69.                 if (student.Sred >= 4)
  70.                     Console.WriteLine("{0,10} \t {1,4}", student.Name, student.Sred);
  71.             }
  72.             Console.Read();
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement