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;
- namespace Student
- {
- class Student
- {
- public string nume;
- public double medie;
- public int nrRestante;
- public Student (string nume, double medie, int nrRestante = 0 )
- {
- this.nume = nume;
- this.medie = medie;
- this.nrRestante = nrRestante;
- }
- public double getMedie()
- {
- return this.medie;
- }
- public int getNrRestante()
- {
- return this.nrRestante;
- }
- public void displayStudent()
- {
- Console.WriteLine(this.nume + " " + this.medie + " " + this.nrRestante);
- }
- }
- class GrupStudenti
- {
- public int nr;
- public System.Collections.Generic.List<Student> grupList = new System.Collections.Generic.List<Student>();
- public GrupStudenti(int nr)
- {
- this.nr = nr;
- }
- public void readGrup()
- {
- for (int i = 1; i <= this.nr; ++i)
- {
- string nume;
- double medie;
- int restante;
- Console.Write("Numele studentului " + i + ": ");
- nume = Console.ReadLine();
- Console.Write("Media studentului " + i + ": ");
- medie = Convert.ToDouble(Console.ReadLine());
- Console.Write("Studentul " + i + " are restante? Daca da, cate?: ");
- restante = Convert.ToInt32(Console.ReadLine());
- //Student student = new Student(nume, medie, restante);
- grupList.Add(new Student(nume, medie, restante));
- }
- }
- public void displayList()
- {
- foreach (Student i in grupList)
- {
- i.displayStudent();
- }
- }
- private static int compByMedie (Student s1, Student s2)
- {
- if (s1.medie == s2.medie) return 0;
- else if (s1.medie > s2.medie) return -1;
- else return 1;
- }
- public void sortByMedie()
- {
- grupList.Sort(compByMedie);
- }
- private static int compByNume (Student s1, Student s2)
- {
- if (s1.nume == s2.nume) return 0;
- else if (String.Compare(s1.nume, s2.nume) > 0) return 1;
- else return -1;
- }
- public void sortByNume()
- {
- grupList.Sort(compByNume);
- }
- public Student getMedieMax()
- {
- double Max = -1;
- Student ans = new Student("Student", -1, 0);
- foreach (Student i in grupList)
- {
- if (i.medie > Max)
- {
- Max = i.medie;
- ans = i;
- }
- }
- return ans;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- GrupStudenti var1 = new GrupStudenti(3);
- var1.readGrup();
- Console.WriteLine("Lista studentilor: ");
- var1.displayList();
- Console.WriteLine("\nLista studentilor ordonata dupa medie: ");
- var1.sortByMedie();
- var1.displayList();
- Console.WriteLine("\nLista stdentilor ordonata alfabetic: ");
- var1.sortByNume();
- var1.displayList();
- Student var2 = var1.getMedieMax();
- Console.Write("\nCea mai mare medie o are: ");
- var2.displayStudent();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement