StoimenK

C#_Objects_and_Classes_1.4.Students

Feb 25th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _1._4.Students
  6. {
  7.     class Student
  8.     {
  9.         public string FirstName { get; set; }
  10.         public string SecondName { get; set; }
  11.         public double Grade { get; set; }
  12.         public Student(string firstName, string secondName, double grade)
  13.         {
  14.             this.FirstName = firstName;
  15.             this.SecondName = secondName;
  16.             this.Grade = grade;
  17.         }
  18.         public double getGrade()
  19.         {
  20.             return this.Grade;
  21.         }
  22.  
  23.         public override string ToString()
  24.         {
  25.             return string.Format(this.FirstName, this.SecondName, this.Grade);
  26.         }
  27.     }
  28.  
  29.  
  30.     class Program
  31.     {
  32.         static void Main()
  33.         {
  34.             List<Student> students = new List<Student>();
  35.             int n = int.Parse(Console.ReadLine());
  36.  
  37.             for (int i = 0; i < n; i++)
  38.             {
  39.                 string[] info = Console.ReadLine().Split(' ');
  40.                 string firstName = info[0];
  41.                 string secondName = info[1];
  42.                 double grade = double.Parse(info[2]);
  43.  
  44.                 Student student = new Student(firstName, secondName, grade);
  45.                 students.Add(student);
  46.  
  47.             }
  48.             students.OrderByDescending(t => t.Grade).ThenBy(t => t.FirstName).ToList();
  49.             List<Student> sortedStudents = students.OrderByDescending(t => t.Grade).ThenBy(t => t.FirstName).ThenBy(t => t.SecondName).ToList();
  50.  
  51.             foreach (Student t in sortedStudents)
  52.             {
  53.                 Console.WriteLine($"{t.FirstName} {t.SecondName}: {t.Grade:f2}");
  54.             }
  55.  
  56.         }
  57.     }
  58. }
Add Comment
Please, Sign In to add comment