int n; //so HS //StreamWriter fw = File.CreateText("TKhocsinh.txt"); #region Doc Du lieu tu tep hocsinh.txt va day vao danh sach moc noi don ds; Hien thi public void doctep() { StreamReader fr = File.OpenText("hocsinh.txt"); ds = null; n = 0; Nodehs tg; string s; string[] con; //cac truong DL s = fr.ReadLine(); //doc dong dau=> duoc ban ghi dau tien if (s != null) { int d = 0;//d so truong DL, d=so dau #+1 for (int i = 0; i < s.Length; i++) { if (s[i] == '#') { d++; } } con = new string[d + 1]; while (s != null)//lan luot doc het tep { if (s.Length > 0) { con = s.Split('#'); tg = new Nodehs(); tg.hs = new HocSinh(); tg.hs.mahs = int.Parse(con[0]); tg.hs.hoten = con[1]; tg.hs.gioitinh = con[2]; tg.hs.namsinh = DateTime.Parse(con[3]); tg.hs.email = con[4]; tg.hs.dtb = double.Parse(con[5]); tg.hs.malop = con[6]; //them TT SV vua doc tu tep vao DS SV ds n++; if (ds == null) { ds = tg; } else { tg.link = ds; ds = tg; } s = fr.ReadLine(); } } } else { Console.WriteLine("tep rong!!!"); } Console.WriteLine("Du lieu vua doc duoc tu tep HOCSINH.TXT nhu sau:"); hienthi(); fr.Close(); }
public void hoanvi(Nodehs p, Nodehs q) { Nodehs tg = new Nodehs(); tg.hs = p.hs; p.hs = q.hs; q.hs = tg.hs; }
//Ghi them thong tin vao cuoi tep public void ghitep(Nodehs tg) { StreamWriter fw = File.AppendText("HocSinh.txt"); fw.WriteLine(); fw.Write("{0}#{1}#{2}#{3}#{4}#{5}#{6}", tg.hs.mahs, tg.hs.hoten, tg.hs.gioitinh, tg.hs.namsinh.ToString("dd/MM/yyyy"), tg.hs.email, tg.hs.dtb, tg.hs.malop); fw.Close(); }
public void SearchTen(string ten) { Nodehs tg = ds; while (tg != null) { if (tg.hs.hoten.IndexOf(ten) >= 0) { tg.hs.hienthi(tg.hs); } tg = tg.link; } }
public void SearchMa(int ma) { Nodehs tg = ds; while (tg != null) { if (tg.hs.mahs == ma) { tg.hs.hienthi(tg.hs); break; } tg = tg.link; } }
public void ThongkeTyLe() { StreamWriter ftk; if (File.Exists("ThongkeTyLe.txt")) { ftk = File.AppendText("ThongkeTyLE.txt"); } else { ftk = File.CreateText("ThongkeTyLE.txt"); } int dg, dk, dtb, dy; dg = dk = dtb = dy = 0; Nodehs tg = this.ds; while (tg.link != null) { if (tg.hs.dtb >= 8) { dg++; } else if (tg.hs.dtb >= 7) { dk++; } else if (tg.hs.dtb >= 5) { dtb++; } else { dy++; } tg = tg.link; } Console.WriteLine("Ty le Gioi (8..10) : {0} / {1} ", dg, this.n); Console.WriteLine("Ty le Kha (7..8) : {0} / {1} ", dk, this.n); Console.WriteLine("Ty le TrungBinh(5..7): {0} / {1} ", dtb, this.n); Console.WriteLine("Ty le Yeu (<5) : {0} / {1} ", dy, this.n); DateTime dt = DateTime.Now; ftk.WriteLine("Thoi diem thong ke:" + dt.ToString("dd/MM/yyyy")); ftk.WriteLine("Ty le Gioi (8..10) : {0} / {1} ", dg, this.n); ftk.WriteLine("Ty le Kha (7..8) : {0} / {1} ", dk, this.n); ftk.WriteLine("Ty le TrungBinh(5..7): {0} / {1} ", dtb, this.n); ftk.WriteLine("Ty le Yeu (<5) : {0} / {1} ", dy, this.n); ftk.Close(); }
public void hienthi() { Nodehs tg = new Nodehs(); tg = this.ds; Console.WriteLine("MaHS\tHoTen\tGioiTinh\tNamSinh\tEmail\tDTB\tMaLop"); if (tg != null) { while (tg != null) { Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", tg.hs.mahs, tg.hs.hoten, tg.hs.gioitinh, tg.hs.namsinh.ToString("dd/MM/yyyy"), tg.hs.email, tg.hs.dtb, tg.hs.malop); //tg.hs.hienthi(tg.hs); tg = tg.link; } } else { Console.WriteLine("Danh sách trong"); } }
public void SortDiem() { Nodehs i, j; i = new Nodehs(); j = new Nodehs(); i = this.ds; j = this.ds.link; if (!(i.link == null || i.link.link == null)) { while (i.link.link != null) { j = i.link; while (j.link != null) { if (i.hs.dtb < j.hs.dtb) { hoanvi(i, j); } j = j.link; } i = i.link; } } hienthi(); }
public void Insert() { Nodehs tg = new Nodehs(); tg.hs = new HocSinh(); tg.link = null; //??Kiem tra ma lop da co chua? Neu chua=> bao loi; neu co: 1 ghi them SV vao tep hocsinh.txt; cap nhat siso tep Lop.txt? //TT HS hop le thi them vao DS HS va ghi vao tep Nodehs tghs = new Nodehs(); danhsachlop dsl = new danhsachlop(); dsl.doctep(); NodeL tgl = new NodeL(); int mahs; string malop; bool ok1; bool ok2;//SV có mã lớp chưa có do { ok1 = true; Console.Write("Nhap Ma hoc sinh: "); mahs = int.Parse(Console.ReadLine()); tghs = this.ds; while (tghs != null)//XL { if (tghs.hs.mahs == mahs) { ok1 = false; } tghs = tghs.link; } if (!ok1) { Console.WriteLine("DL ko hop le: Ma HS da co! Moi nhap lai"); } } while (!ok1); tg.hs.mahs = mahs; tg.hs.nhap1(); do { ok2 = false; Console.Write("Nhap ma lop: "); malop = Console.ReadLine(); tgl = dsl.ds; while (tgl != null) { if (string.Compare(tgl.L.malop, malop) == 0) { ok2 = true; break; } tgl = tgl.link; } if (!ok2) { Console.WriteLine("DL ko hop le: Ma lop chua co! Moi nhap lai"); } } while (!ok2);//XL tg.hs.malop = String.Copy(malop); ghitep(tg); //Cap nhat si so tep Lop.txt tg.link = ds; ds = tg; }
int n; //so HS //StreamWriter fw = File.CreateText("TKhocsinh.txt"); #region Doc Du lieu tu tep hocsinh.txt va day vao danh sach moc noi don ds; Hien thi public void doctep() { StreamReader fr = File.OpenText("hocsinh.txt"); ds = null; n = 0; Nodehs tg; string s; string[] con; //cac truong DL s = fr.ReadLine(); //doc dong dau=> duoc ban ghi dau tien if (s != null) { int d = 0;//d so truong DL, d=so dau #+1 for (int i = 0; i < s.Length; i++) { if (s[i] == '#') { d++; } } con = new string[d + 1]; while (s != null)//lan luot doc het tep { if (s.Length > 0) { con = s.Split('#'); tg = new Nodehs(); tg.hs = new HocSinh(); tg.hs.mahs = int.Parse(con[0]); tg.hs.hoten = con[1]; tg.hs.gioitinh = con[2]; //Xử lý chuoi thoi gian //tg.hs.namsinh = DateTime.Parse(con[3]); //string dt = string.Copy(con[3]); // Console.WriteLine(con[3]); string[] tmp = con[3].Split('/'); //Tach xau thoi gian thanh => ngay thang nam DateTime dt = new DateTime(int.Parse(tmp[2]), int.Parse(tmp[1]), int.Parse(tmp[0])); //khoi tao doi tuong dt //Console.WriteLine(dt.ToString("dd/MM/yyyy"));//ghi du lieu ngay thang ra man hinh tg.hs.NamSinh = dt; //Lenh sai ko nhan duoc DL: tg.hs.namsinh = dt; //Console.WriteLine(tg.hs.namsinh.ToString("DD/MM/yyyy"));//ghi du lieu ngay thang ra man hinh theo dinh dang tg.hs.email = con[4]; tg.hs.dtb = double.Parse(con[5]); tg.hs.malop = con[6]; //them TT SV vua doc tu tep vao DS SV ds n++; if (ds == null) { ds = tg; } else { tg.link = ds; ds = tg; } s = fr.ReadLine(); } } } else { Console.WriteLine("tep rong!!!"); } Console.WriteLine("Du lieu vua doc duoc tu tep HOCSINH.TXT nhu sau:"); hienthi(); fr.Close(); }