Пример #1
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            Elev elev1 = obj as Elev;

            if (this.gradesArithmeticAverage == elev1.gradesArithmeticAverage)
            {
                int ret = elev1.firstName.CompareTo(this.firstName);
                if (ret == 0)
                {
                    return(elev1.lastName.CompareTo(this.lastName));
                }
                else
                {
                    return(ret);
                }
            }

            else if (this.gradesArithmeticAverage > elev1.gradesArithmeticAverage)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Load();

            for (int i = 0; i < elevi.Count - 1; i++)
            {
                for (int j = i + 1; j < elevi.Count; j++)
                {
                    if ((elevi[i].media < elevi[j].media) || ((elevi[i].media < elevi[j].media) && (StringCompare(elevi[i].name, elevi[j].name) < 0)))
                    {
                        Elev aux = elevi[i];
                        elevi[i] = elevi[j];
                        elevi[j] = aux;
                    }
                }
            }

            elevi.Sort((x, y) =>
            {
                var result = y.media.CompareTo(x.media);
                if (result == 0)
                {
                    result = y.name.CompareTo(x.name);
                }
                return(result);
            });

            Save();
        }
Пример #3
0
        private static List <Elev> CalculMedie(List <Elev> studenti)
        {
            double mediaStud = 0;

            foreach (var student in studenti)
            {
                mediaStud = student.GetAverage(student.Grades);
                Elev elev = new Elev(student.numeFam, student.prenume, mediaStud);
                media.Add(elev);
            }

            return(media);
        }
Пример #4
0
        public static List <Elev> GenerareIntrare(string filepath)
        {
            List <Elev>  students = new List <Elev>();
            StreamReader sr       = sr = new StreamReader(filepath);
            Elev         elev     = new Elev();
            string       line     = sr.ReadLine();

            while (line != null)
            {
                string[] datas  = line.Split(',');
                string[] grades = datas[3].Split(' ');
                elev = new Elev(datas[0], datas[1], datas[2], grades);
                students.Add(elev);
                line = sr.ReadLine();
            }
            return(students);
        }
Пример #5
0
        //met 1 de sortare bubble
        public void BubbleSort(List <Elev> elevi)
        {
            Elev tmp = new Elev();

            for (int j = 0; j <= elevi.Count - 2; j++)
            {
                for (int i = 0; i <= elevi.Count - 2; i++)
                {
                    if (elevi.ElementAt(i).CompareTo(elevi.ElementAt(i + 1)) < 0)
                    {
                        tmp.Copy(elevi.ElementAt(i + 1));
                        elevi.ElementAt(i + 1).Copy(elevi.ElementAt(i));
                        elevi.ElementAt(i).Copy(tmp);
                    }
                }
            }
        }
Пример #6
0
        public List <Elev> Read()
        {
            Console.WriteLine("Reading from [" + this.fileName + "]");

            List <Elev> elevi = new List <Elev>();

            string[] lines = File.ReadAllLines(this.fileName);
            foreach (string line in lines)
            {
                string[] tokens = line.Split(' ');
                double   gradesArithmeticAverage = 0;
                int      gradesCount             = int.Parse(tokens[2]);

                for (int i = 0; i < gradesCount; i++)
                {
                    gradesArithmeticAverage += double.Parse(tokens[3 + i]);
                }
                gradesArithmeticAverage = gradesArithmeticAverage / gradesCount;
                Elev v = new Elev(tokens[0], tokens[1], gradesArithmeticAverage);
                elevi.Add(v);
            }

            return(elevi);
        }
Пример #7
0
 public void Copy(Elev a)
 {
     this.firstName = a.firstName;
     this.lastName  = a.lastName;
     this.gradesArithmeticAverage = a.gradesArithmeticAverage;
 }