using System; using System.Collections.Generic; class PERSON { public string Hoten { get; set; } public string Gioitinh { get; set; } public int Namsinh { get; set; } public PERSON() { Hoten = ""; Gioitinh = ""; Namsinh = 0; } public PERSON(string hoten, string gioitinh, int namsinh) { Hoten = hoten; Gioitinh = gioitinh; Namsinh = namsinh; } public virtual void Nhap() { Console.Write("Nhap ho ten: "); Hoten = Console.ReadLine(); Console.Write("Nhap gioi tinh: "); Gioitinh = Console.ReadLine(); Console.Write("Nhap nam sinh: "); Namsinh = int.Parse(Console.ReadLine()); } public virtual void Xuat() { Console.Write("{0,-20}{1,-10}{2,-10}", Hoten, Gioitinh, Namsinh); } } class CONGNHAN : PERSON { public string Tencongty { get; set; } public double Hesoluong { get; set; } public CONGNHAN() : base() { Tencongty = ""; Hesoluong = 0; } public CONGNHAN(string hoten, string gioitinh, int namsinh, string tencongty, double hesoluong) : base(hoten, gioitinh, namsinh) { Tencongty = tencongty; Hesoluong = hesoluong; } public override void Nhap() { base.Nhap(); Console.Write("Nhap ten cong ty: "); Tencongty = Console.ReadLine(); Console.Write("Nhap he so luong: "); Hesoluong = double.Parse(Console.ReadLine()); } public double Thunhap() { return Hesoluong * 850000; } public override void Xuat() { base.Xuat(); Console.WriteLine("{0,-20}{1,-15}{2,-15:N0}", Tencongty, Hesoluong, Thunhap()); } } class Program { static void Main() { Console.Write("Nhap so luong cong nhan: "); int n = int.Parse(Console.ReadLine()); List ds = new List(); for (int i = 0; i < n; i++) { Console.WriteLine($"\nNhap thong tin cong nhan thu {i + 1}:"); CONGNHAN cn = new CONGNHAN(); cn.Nhap(); ds.Add(cn); } Console.WriteLine("\n=== Danh sach cong nhan ==="); Console.WriteLine("{0,-20}{1,-10}{2,-10}{3,-20}{4,-15}{5,-15}", "Ho ten", "Gioi tinh", "Nam sinh", "Ten cong ty", "He so luong", "Thu nhap"); foreach (CONGNHAN cn in ds) { cn.Xuat(); } // Tim cong nhan co he so luong cao nhat double maxHeso = 0; foreach (CONGNHAN cn in ds) { if (cn.Hesoluong > maxHeso) maxHeso = cn.Hesoluong; } Console.WriteLine("\n=== Cong nhan co he so luong cao nhat ==="); Console.WriteLine("{0,-20}{1,-10}{2,-10}{3,-20}{4,-15}{5,-15}", "Ho ten", "Gioi tinh", "Nam sinh", "Ten cong ty", "He so luong", "Thu nhap"); foreach (CONGNHAN cn in ds) { if (cn.Hesoluong == maxHeso) cn.Xuat(); } Console.ReadLine(); } }