C####

using System; using System.Collections.Generic; namespace Bai_Tap { class Student { private String khoa; private int diem_RL; public int xep_loai; private string iD; private string name; private double diem_TB; public string ID { get { return iD; } set { iD = value; } } public string Name { get { return name; } set { name = value; } } public string Khoa { get { return khoa; } set { khoa = value; } } public double Diem_TB { get { return diem_TB; } set { diem_TB = value; } } public int Diem_RL { get { return diem_RL; } set { diem_RL = value; } } public Student(string iD, string name, string khoa, double diem_TB, int diem_RL) { ID = iD; Name = name; Khoa = khoa; this.Diem_TB = diem_TB; this.Diem_RL = diem_RL; if (diem_TB < 7) this.xep_loai = 0; if (diem_TB >= 7) if (diem_RL >= 70) this.xep_loai = 2; else this.xep_loai = 0; if (diem_TB >= 8) if (diem_RL >= 80) this.xep_loai = 3; else if (diem_RL < 80 && diem_RL >= 70) this.xep_loai = 2; else this.xep_loai = 0; if (diem_TB >= 9) if (diem_RL >= 90) this.xep_loai = 4; else if (diem_RL < 90 && diem_RL >= 80) this.xep_loai = 3; else if (diem_RL < 80 && diem_RL >= 70) this.xep_loai = 2; else this.xep_loai = 0; } public String toStringXepLoai() { switch (this.xep_loai) { case 0: { return "Yeu"; break; } case 2: { return "Kha"; break; } case 3: { return "Gioi"; break; } case 4: { return "Xuat Sac"; break; } default: { return ""; } } } public void Hien_Thi() { System.Console.WriteLine("------------------------------"); System.Console.WriteLine("MSSV: " + ID); System.Console.WriteLine("Ho va ten: " + Name); System.Console.WriteLine("Khoa: " + Khoa); System.Console.WriteLine("Diem hoc tap: " + Diem_TB); System.Console.WriteLine("Diem ren luyen: " + Diem_RL); System.Console.WriteLine("Xep loai: " + this.toStringXepLoai()); } } class QuanLiStudent { public static List<Student> std_list = new List<Student>(); public void KhoiTao() { std_list.Add(new Student("001", "Ten 1", "CNTT", 9.2, 90)); std_list.Add(new Student("002", "Ten 2", "CNTT", 8, 90)); std_list.Add(new Student("003", "Ten 3", "CNTT", 7, 90)); std_list.Add(new Student("004", "Ten 4", "CNTT", 9.2, 70)); std_list.Add(new Student("005", "Ten 5", "CNTT", 9.2, 55)); } public void Xuat_DS() { foreach (Student std in std_list) { std.Hien_Thi(); } } public Student FindStudentByID(String id) { foreach (Student std in std_list) { if (std.ID.Equals(id)) return std; } return null; } public void FindStudentByName(String name) { bool check = false; foreach (Student std in std_list) { if (std.Name.Equals(name)) { std.Hien_Thi(); check = true; } } if (!check) System.Console.WriteLine("Khong tim thay!!!"); } public void FindStudentByKhoa(String khoa) { bool check = false; foreach (Student std in std_list) { if (std.Name.Equals(khoa)) { std.Hien_Thi(); check = true; } } if (!check) System.Console.WriteLine("Khong tim thay!!!"); } public void FindStudentByDiemTB(double diemTB) { bool check = false; foreach (Student std in std_list) { if (std.Diem_TB >= diemTB) { std.Hien_Thi(); check = true; } } if (!check) System.Console.WriteLine("Khong tim thay sinh vien co diem trung binh lon hon!!!"); } public void AddStudent() { String id, name, khoa; double diemTb; int diemRl; System.Console.WriteLine("Nhap ID: "); id = System.Console.ReadLine(); System.Console.WriteLine("Nhap Ten: "); name = System.Console.ReadLine(); System.Console.WriteLine("Nhap Khoa: "); khoa = System.Console.ReadLine(); System.Console.WriteLine("Nhap diem trung binh: "); diemTb = Double.Parse(System.Console.ReadLine()); System.Console.WriteLine("Nhap diem ren luyen: "); diemRl = Int32.Parse(System.Console.ReadLine()); std_list.Add(new Student(id, name, khoa, diemTb, diemRl)); System.Console.WriteLine("Da them sinh vien"); } public void DeleteStudentById(String id) { std_list.Remove(this.FindStudentByID(id)); } } class Program { static void Main(string[] args) { QuanLiStudent ql = new QuanLiStudent(); bool exit = false; do { System.Console.Clear(); System.Console.WriteLine("QUAN LI SINH VIEN"); System.Console.WriteLine("Chon chuc nang: "); System.Console.WriteLine("1. Them Sinh Vien"); System.Console.WriteLine("2. Xuat danh sach Sinh Vien"); System.Console.WriteLine("3. Tm Sinh Vien bang ID"); System.Console.WriteLine("4. Tim Sinh Vien bang Ten"); System.Console.WriteLine("5. Tim Sinh Vien bang Khoa"); System.Console.WriteLine("6. Tim Sinh Vien bang Diem trung binh"); System.Console.WriteLine("7. Xoa Sinh vien bang ID"); System.Console.WriteLine("8. Thoat"); int choise; choise = UInt16.Parse(System.Console.ReadLine()); switch (choise) { case 1: { ql.AddStudent(); System.Console.ReadKey(); break; }; case 2: { ql.Xuat_DS(); System.Console.ReadKey(); break; }; case 3: { String id; System.Console.WriteLine("Nhap id: "); id = System.Console.ReadLine(); if (ql.FindStudentByID(id) != null) ql.FindStudentByID(id).Hien_Thi(); else System.Console.WriteLine("Khong tim thay sinh vien co ID da chon"); System.Console.ReadKey(); break; } case 4: { String name; System.Console.WriteLine("Nhap ten: "); name = System.Console.ReadLine(); ql.FindStudentByName(name); System.Console.ReadKey(); break; } case 5: { String khoa; System.Console.WriteLine("Nhap khoa: "); khoa = System.Console.ReadLine(); ql.FindStudentByName(khoa); System.Console.ReadKey(); break; } case 6: { double diemTB; System.Console.WriteLine("Nhap diem: "); diemTB = Double.Parse(System.Console.ReadLine()); ql.FindStudentByDiemTB(diemTB); System.Console.ReadKey(); break; } case 7: { String id; System.Console.WriteLine("Nhap id: "); id = System.Console.ReadLine(); ql.DeleteStudentById(id); System.Console.ReadKey(); break; } case 8: { exit = true; break; } default: { System.Console.WriteLine("Chon sai"); break; } } } while (!exit); } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.