using System; using System.Collections.Generic; namespace Bai2 { // Lớp PERSON class PERSON { protected string hoten; protected string gioitinh; protected int namsinh; // Constructor public PERSON() { } public PERSON(string hoten, string gioitinh, int namsinh) { this.hoten = hoten; this.gioitinh = gioitinh; this.namsinh = namsinh; } // Nhập dữ liệu 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()); } // Xuất dữ liệu public virtual void Xuat() { Console.WriteLine($"Ho ten: {hoten}, Gioi tinh: {gioitinh}, Nam sinh: {namsinh}"); } } // Lớp CONGNHAN kế thừa PERSON class CONGNHAN : PERSON { private string tenCongTy; private double heSoLuong; private double thuNhap; // Constructor public CONGNHAN() { } public CONGNHAN(string hoten, string gioitinh, int namsinh, string tenCongTy, double heSoLuong) : base(hoten, gioitinh, namsinh) { this.tenCongTy = tenCongTy; this.heSoLuong = heSoLuong; this.thuNhap = heSoLuong * 850000; } // Nhập dữ liệu 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()); thuNhap = heSoLuong * 850000; } // Xuất dữ liệu public override void Xuat() { base.Xuat(); Console.WriteLine($"Cong ty: {tenCongTy}, He so luong: {heSoLuong}, Thu nhap: {thuNhap:N0}"); } // Trả về hệ số lương public double GetHeSoLuong() { return heSoLuong; } } // Lớp chính Program class Program { static void Main(string[] args) { List ds = new List(); Console.Write("Nhap so luong cong nhan: "); int n = int.Parse(Console.ReadLine()); 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 ==="); foreach (var cn in ds) { cn.Xuat(); } // Tìm công nhân có hệ số lương cao nhất double maxHeSo = double.MinValue; foreach (var cn in ds) { if (cn.GetHeSoLuong() > maxHeSo) maxHeSo = cn.GetHeSoLuong(); } Console.WriteLine("\n=== Cong nhan co he so luong cao nhat ==="); foreach (var cn in ds) { if (cn.GetHeSoLuong() == maxHeSo) cn.Xuat(); } Console.ReadLine(); } } }