예제 #1
0
        static void Main(string[] args)
        {
            List <Person> list = new List <Person>();

            Console.WriteLine("So luong nguoi muon nhap");
            int N = Int32.Parse(Console.ReadLine());

            for (int i = 0; i < N; i++)
            {
                Console.WriteLine("Bam 1 de them giang vien");
                Console.WriteLine("Bam 2 de them sinh vien");
                int n = Convert.ToInt32(Console.ReadLine());
                switch (n)
                {
                case 1:
                    Teacher gv = new Teacher();
                    gv.Input();
                    list.Add(gv);
                    break;

                case 2:
                    Student std = new Student();
                    std.Input();
                    list.Add(std);
                    break;

                default:
                    Console.WriteLine("Nhap sai");
                    break;
                }
            }
            //Xuat danh sach SV
            var lsStudent = from s in list where s is Student select(Student) s;

            foreach (Student c in lsStudent)
            {
                c.Output();
            }
            //Xuat danh sach GV
            var lsTeacher = from s in list where s is Teacher select(Teacher) s;

            foreach (Teacher c in lsTeacher)
            {
                c.Output();
            }
            //Xuat sinh vien co diem cao nhat thuoc khoa CNTT
            Student stu = (list.Where(s => s is Student && ((Student)s).Khoa == "CNTT")
                           .Select(s => (Student)s)).OrderByDescending(p => p.DiemTb)
                          .FirstOrDefault();

            stu.Output();
            //Tim Giang vien va sinh vien co find key
            string findKey = Console.ReadLine();

            FindPeoplebyFindkey(findKey, list);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.Write("NHAP SO NGUOI: ");

            int n = Convert.ToInt32(Console.ReadLine());

            List <Person>  listPerson  = new List <Person>();
            List <Student> listStudent = new List <Student>();
            List <Teacher> listTeacher = new List <Teacher>();

            byte option = 9;

            while (option != 0)
            {
                Console.WriteLine();
                Console.WriteLine("1. NHAP THONG TIN CHO SINH VIEN");
                Console.WriteLine("2. NHAP THONG TIN CHO GIAO VIEN");
                Console.WriteLine("3. XUAT THONG TIN CAC HOC SINH");
                Console.WriteLine("4. XUAT THONG TIN CAC GIAO VIEN");
                Console.WriteLine("5. TIM SINH VIEN CO DIEM CAO NHAT THUOC KHOA CNTT");
                Console.WriteLine("6. TIM KIEM THONG TIN THEO TEN");
                Console.WriteLine("0. LUU VA THOAT");
                Console.Write("> ");
                option = Convert.ToByte(Console.ReadLine());
                switch (option)
                {
                case 1:
                {
                    if (listPerson.Count() == n)
                    {
                        Console.Write("\nSO LUONG NGUOI DA TOI DA! VUI LONG NHAP LUA CHON KHAC..\n");
                        break;
                    }
                    Student sv = new Student();
                    sv.Input();
                    listStudent.Add(sv);
                    listPerson.Add(sv);
                    break;
                }

                case 2:
                {
                    if (listPerson.Count() == n)
                    {
                        Console.Write("\nSO LUONG NGUOI DA TOI DA! VUI LONG NHAP LUA CHON KHAC..\n");
                        break;
                    }
                    Teacher tc = new Teacher();
                    tc.Input();
                    listTeacher.Add(tc);
                    listPerson.Add(tc);
                    break;
                }

                case 3:
                {
                    foreach (Student sv in listStudent)
                    {
                        sv.Output();
                    }
                    break;
                }

                case 4:
                {
                    foreach (Teacher tc in listTeacher)
                    {
                        tc.Output();
                    }
                    break;
                }

                case 5:
                {
                    List <Student> listSVKhoaCNTT = listStudent.Where(sv => sv.Khoa.ToLower() == "cntt").ToList();
                    float          maxScore       = listSVKhoaCNTT.Max(p => p.DiemTrungBinh);
                    Console.WriteLine("\n== DANH SACH SINH VIEN CO DTB CAO NHAT VA THUOC KHOA CNTT ==");
                    foreach (Student sv in listSVKhoaCNTT)
                    {
                        if (sv.DiemTrungBinh == maxScore)
                        {
                            sv.Output();
                        }
                    }
                    break;
                }

                case 6:
                {
                    Console.Write("\nHAY NHAP TEN CAN TIM KIEM: ");
                    string inputName = Console.ReadLine();
                    Person find      = listPerson.FirstOrDefault(p => p.HoTen == inputName.ToLower());
                    Console.WriteLine("\n== DANH SACH TIM KIEM THEO TEN VUA NHAP ==");
                    find.Output();
                    break;
                }

                default: break;
                }
            }
            Console.ReadLine();
        }