Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- class Student
- {
- public string Name;
- public double[] Marks = new double[5];
- public double avgMark;
- public Student(string name, double[] marks)
- {
- Name = name;
- Marks = marks;
- double temp = 0;
- for (int i = 0; i < Marks.Length; i++)
- {
- temp += Marks[i];
- }
- avgMark = (temp / Marks.Length);
- }
- public static void Sort(ref Student[] array)
- {
- for (int i = 0; i < array.Length; i++)
- {
- for (int ii = 0; ii < array.Length-1; ii++)
- {
- if (array[ii + 1].avgMark > array[ii].avgMark)
- {
- Student temp = array[ii + 1];
- array[ii + 1] = array[ii];
- array[ii] = temp;
- }
- }
- }
- }
- }
- class Program
- {
- static void DeleteBad(Student student) // удаление тех кто не сдал 3 и более экзаменов
- {
- Console.WriteLine("Студент {0} не сдал 3 и более экзаменов", student.Name);
- }
- static void WriteTwoArrays(Student[] array) // успевающие и не сдавшие 1 экз
- {
- foreach (Student student in array)
- {
- int temp = 0;
- foreach (var mark in student.Marks)
- {
- if (mark <= 2)
- temp++;
- }
- if (temp >= 3)
- DeleteBad(student);
- else
- {
- Console.Write("{0} - ", student.Name);
- foreach (var mark in student.Marks)
- {
- if (mark <= 2)
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("{0} ",mark);
- Console.ResetColor();
- }
- Console.WriteLine("\t {0}", student.avgMark);
- }
- }
- }
- static void Main(string[] args)
- {
- const int n = 4;
- Student[] StudentArray = new Student[n];
- StudentArray[0] = new Student("Vanya", new double[5] {4,3,4,2,4});
- StudentArray[1] = new Student("Petya", new double[5] {2,3,3,2,2});
- StudentArray[2] = new Student("Vova", new double[5] {5,5,4,4,5});
- StudentArray[3] = new Student("Vasya", new double[5] {4,3,4,4,4});
- foreach (var student in StudentArray)
- {
- Console.Write("{0} - ", student.Name);
- foreach (var mark in student.Marks)
- {
- Console.Write("{0} ", mark);
- }
- Console.WriteLine("\t {0}", student.avgMark);
- }
- Student.Sort(ref StudentArray);
- Console.WriteLine();
- WriteTwoArrays(StudentArray);
- Console.Read();
- }
- }
- }
Add Comment
Please, Sign In to add comment