Exemple #1
0
        private static void PopulateDictionary()
        {
            StreamReader sr = new StreamReader("students.txt");

            try
            {
                string currLine = sr.ReadLine();

                while (currLine != null)
                {
                    var lineTokens = currLine.Split(new char[] { '|', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();

                    var studentToAdd = new Student(lineTokens[0], lineTokens[1]);

                    if (!studentsByCourse.ContainsKey(lineTokens[2]))
                    {
                        studentsByCourse.Add(lineTokens[2], new SortedSet<Student>());
                    }

                    studentsByCourse[lineTokens[2]].Add(studentToAdd);

                    currLine = sr.ReadLine();
                }
            }

            catch (FileNotFoundException)
            {
                Console.WriteLine("File students.txt not found!");
            }
        }
        public static SortedDictionary<string, OrderedBag<Student>> ReadStudents(string path)
        {
            var result = new SortedDictionary<string, OrderedBag<Student>>();

            using (var reader = new StreamReader("students.txt"))
            {
                var currentLine = reader.ReadLine();

                while (currentLine != null)
                {
                    var tokens = currentLine.Split(new char[] { ' ', '|', }, StringSplitOptions.RemoveEmptyEntries);
                    var course = tokens[2].Trim();
                    Student student = new Student(tokens[0].Trim(), tokens[1].Trim(), course);
                    
                    if (result.ContainsKey(course))
                    {
                        result[course].Add(student);
                    }
                    else
                    {
                        result[course] = new OrderedBag<Student>();
                        result[course].Add(student);
                    }

                    currentLine = reader.ReadLine();
                }

                return result;
            }


           // return result;
        }
        public static void Main()
        {
            Student st1 = new Student("Pesho", "Peshov", "Peshov");
            st1.SSN = 555;
            st1.Specialty = Specialties.spec2;

            Student st2 = st1.Clone() as Student;

            Console.WriteLine("\tOriginal student data\n");
            Console.WriteLine(st1);

            Console.WriteLine("\tCloned student data\n");
            Console.WriteLine(st2);

            Console.WriteLine("st1 == st2 ? - {0}", st1 == st2);
            Console.WriteLine();

            Console.WriteLine("Enter new SSN number for student 2 (different from 555)");
            Console.Write("SSN = ");
            st2.SSN = long.Parse(Console.ReadLine());
            Console.WriteLine();

            Console.WriteLine("st1.CompareTo(st2) - {0}", st1.CompareTo(st2));

            Console.WriteLine();
        }
        public static SortedDictionary<string, SortedSet<Student>> ReadProducts(string fileName)
        {
            SortedDictionary<string, SortedSet<Student>> studentsByCourses = new SortedDictionary<string, SortedSet<Student>>();

            using (var reader = new StreamReader(fileName))
            {
                var line = reader.ReadLine();
                while (line != null && line.Length > 2)
                {
                    string[] tokens = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    Student student = new Student(tokens[0].Trim(), tokens[1].Trim());
                    string course = tokens[2].Trim();

                    if (studentsByCourses.ContainsKey(course))
                    {
                        studentsByCourses[course].Add(student);
                    }
                    else
                    {
                        studentsByCourses[course] = new SortedSet<Student>();
                    }
                    
                    line = reader.ReadLine();
                }
            }

            return studentsByCourses;
        }
Exemple #5
0
        static void Main(string[] args)
        {
            string command = Console.ReadLine();
            while(command != "End")
            {
                Student student = new Student(command);
                command = Console.ReadLine();
            }

            Console.WriteLine(Student.instanceCounter);
        }
Exemple #6
0
        private static Student[] ParseStudentEntities(IList<string> studentsEntities)
        {
            Student[] students = new Student[studentsEntities.Count];
            for (int i = 0; i < studentsEntities.Count; i++)
            {
                string[] studentsEntitieParts = studentsEntities[i].Split(new char[] { '|'}, StringSplitOptions.RemoveEmptyEntries);
                students[i] = new Student
                {
                    FirstName = studentsEntitieParts[0].Trim(),
                    LastName = studentsEntitieParts[1].Trim(),
                    CourseName = studentsEntitieParts[2].Trim()
                };
            }

            return students;
        }
        static void Main(string[] args)
        {
            //1.
            var Antoan = new Student("Antoan", "Petrov", "Elenkov", 14690, "Sin City", "+12345678",
                "*****@*****.**", 5, Specialitiy.CivilEngineering, University.UACG, Faculty.Mathematic);
            var Antoan2 = new Student("Antoan", "Petrov", "Elenkov", 14690, "Sin City", "+12345678",
                "*****@*****.**", 5, Specialitiy.CivilEngineering, University.UACG, Faculty.Mathematic);
            Console.WriteLine(Antoan.ToString());

            Console.WriteLine("\nChecks if getHashCode() is implemented properly:");
            Console.WriteLine(Antoan.GetHashCode());
            Console.WriteLine(Antoan2.GetHashCode());

            //2.IClonable - Clone Object
            Console.WriteLine("\nThis is the deep copy:");
            var AntoanCopy = Antoan.Clone();
            Console.WriteLine(AntoanCopy);

            //3.Implement the IComparable<Student> interface to compare students by names (as first criteria,
            //in lexicographic order) and by social security number (as second criteria, in increasing order).
            Console.WriteLine("\nCompare student Antoan with his copy:");
            Console.WriteLine(Antoan.CompareTo(Antoan2));
        }
Exemple #8
0
        private static ICollection<Student> ReadFile(string filePath)
        {
            char[] separators = new char[] { ' ', '|' };
            var students = new List<Student>();

            using (var streamReader = new StreamReader(filePath))
            {
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    var studentInfo = line.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    if (studentInfo.Length == 3)
                    {
                        var firstName = studentInfo[0];
                        var lastName = studentInfo[1];
                        var courseName = studentInfo[2];
                        var student = new Student(firstName, lastName, courseName);
                        students.Add(student);
                    }
                }
            }

            return students;
        }