Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 12.ObjectsAndClasses-Students
- Write a program that receives a count of students - n and orders them by grade in descending order. Each student should have a First name (string), a Last name (string) and a grade (a floating-point number).
- Input
- • On the first line, you are going to receive n - the count of students
- • On the next n lines, you will be receiving the info about the students in the following format:
- "{first name} {second name} {grade}"
- Output
- • Print each student in the following format: "{first name} {second name}: {grade}"
- Example
- Input Output
- 4
- Lakia Eason 3.90 Rocco Erben: 6.00
- Prince Messing 5.49 Prince Messing: 5.49
- Akiko Segers 4.85 Akiko Segers: 4.85
- Rocco Erben 6.00 Lakia Eason: 3.90
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _4.Average_Grades
- {
- class Student
- {
- public string FirstName { get; set; }
- public string SecondName { get; set; }
- public double Grade { get; set; }
- public Student(string firstName, string secondName, double grade)
- {
- this.FirstName = firstName;
- this.SecondName = secondName;
- this.Grade = grade;
- }
- public double getGrade()
- {
- return this.Grade;
- }
- public override string ToString()
- {
- return string.Format(this.FirstName, this.SecondName, this.Grade);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Student> students = new List<Student>();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] info = Console.ReadLine().Split(" ");
- string firstName = info[0];
- string secondName = info[1];
- double grade = double.Parse(info[2]);
- Student student = new Student(firstName, secondName, grade);
- students.Add(student);
- //Console.WriteLine($"{student.FirstName} {student.SecondName}: {student.Grade:f2}");
- }
- students.OrderByDescending(t => t.Grade).ThenBy(t => t.FirstName).ToList();
- List<Student> sortedStudents = students.OrderByDescending(t => t.Grade).ThenBy(t => t.FirstName).ThenBy(t => t.SecondName).ToList();
- foreach (Student t in sortedStudents)
- {
- Console.WriteLine($"{t.FirstName} {t.SecondName}: {t.Grade:f2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement