using System; using System.Collections.Generic; public class HOCSINH { public string Hoten { get; set; } public int Tuoi { get; set; } public int DiemT { get; set; } public int DiemL { get; set; } public int DiemH { get; set; } public double DiemTB { get; set; } public string XepLoai { get; set; } // Phương thức khởi tạo public HOCSINH(string hoten, int tuoi, int diemt, int dieml, int diemh) { Hoten = hoten; Tuoi = tuoi; DiemT = diemt; DiemL = dieml; DiemH = diemh; TinhDiemTB(); XepLoaiHocSinh(); } // Tính điểm trung bình public void TinhDiemTB() { DiemTB = (DiemT + DiemL + DiemH) / 3.0; } // Xếp loại học sinh public void XepLoaiHocSinh() { if (DiemTB < 5) XepLoai = "Yếu"; else if (DiemTB >= 5 && DiemTB < 7) XepLoai = "Trung bình"; else if (DiemTB >= 7 && DiemTB < 8.5) XepLoai = "Khá"; else XepLoai = "Giỏi"; } } class Program { static List danhSachHocSinh = new List(); // Nhập danh sách học sinh static void NhapDSO() { Console.Write("Nhập số học sinh: "); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { Console.WriteLine($"Nhập thông tin cho học sinh {i + 1}:"); Console.Write("Họ tên: "); string hoten = Console.ReadLine(); Console.Write("Tuổi: "); int tuoi = int.Parse(Console.ReadLine()); Console.Write("Điểm Toán: "); int diemt = int.Parse(Console.ReadLine()); Console.Write("Điểm Lý: "); int dieml = int.Parse(Console.ReadLine()); Console.Write("Điểm Hóa: "); int diemh = int.Parse(Console.ReadLine()); // Thêm học sinh vào danh sách HOCSINH hs = new HOCSINH(hoten, tuoi, diemt, dieml, diemh); danhSachHocSinh.Add(hs); } } // Xuất danh sách học sinh static void XuatDS() { Console.WriteLine("\nDanh sách học sinh:"); Console.WriteLine("{0,-25} {1,-5} {2,-10} {3,-5} {4,-5} {5,-10} {6,-10}", "Họ tên", "Tuổi", "Toán", "Lý", "Hóa", "TB", "Xếp loại"); foreach (var hs in danhSachHocSinh) { Console.WriteLine("{0,-25} {1,-5} {2,-10} {3,-5} {4,-5} {5,-10:F2} {6,-10}", hs.Hoten, hs.Tuoi, hs.DiemT, hs.DiemL, hs.DiemH, hs.DiemTB, hs.XepLoai); } } static void Main(string[] args) { NhapDSO(); XuatDS(); } }