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;
- using System.IO;
- namespace ConsoleApp3
- {
- class Student
- {
- // уровень 2 задание 1
- public double Sred;
- public int[] Marks;
- public string Name;
- public Student(double Sred, int[] Marks, string Name)
- {
- this.Sred = Sred;
- this.Marks = Marks;
- this.Name = Name;
- }
- public static double CalculateAverage(int[] Marks, double Sred)
- {
- foreach (int mark in Marks)
- {
- Sred += mark;
- }
- Sred /= Marks.Length;
- return Sred;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- string path = @"G:\surnames.txt";
- StreamReader str1 = new StreamReader(path, Encoding.GetEncoding(1251));
- Student[] students = new Student[5];
- Student st1 = new Student(0, new int[] { 2,3,4,5 },str1.ReadLine());
- st1.Sred = Student.CalculateAverage(st1.Marks, st1.Sred);
- students[0] = st1;
- Student st2 = new Student(0, new int[] { 3,5,5,5 }, str1.ReadLine());
- st2.Sred = Student.CalculateAverage(st2.Marks, st2.Sred);
- students[1] = st2;
- Student st3 = new Student(0, new int[] { 4,5,4,4}, str1.ReadLine());
- st3.Sred = Student.CalculateAverage(st3.Marks, st3.Sred);
- students[2] = st3;
- Student st4 = new Student(0, new int[] { 3,2,4,5}, str1.ReadLine());
- st4.Sred = Student.CalculateAverage(st4.Marks, st4.Sred);
- students[3] = st4;
- Student st5 = new Student(0, new int[] { 2,2,5,4}, str1.ReadLine());
- st5.Sred = Student.CalculateAverage(st5.Marks, st5.Sred);
- students[4] = st5;
- Console.WriteLine("\n Фамилия \t Средний балл \n ");
- foreach (Student student in students)
- {
- Console.Write("{0,10} \t {1,4} \t ", student.Name, student.Sred);
- foreach (uint mark in student.Marks)
- Console.Write($" {mark}");
- Console.WriteLine();
- }
- Console.WriteLine("\n Фамилия \t Средний балл \n");
- foreach (Student student in students)
- {
- if (student.Sred >= 4)
- Console.WriteLine("{0,10} \t {1,4}", student.Name, student.Sred);
- }
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement