-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlap1.3.cs
More file actions
383 lines (336 loc) · 9.71 KB
/
Copy pathlap1.3.cs
File metadata and controls
383 lines (336 loc) · 9.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/* Bai 1: Quan Ly Can Bo
- Nhap thong tin can bo (ho ten, nam sinh, gioi tinh, dia chi)
- Phan loai can bo (Cong Nhan, Ky Su, Nhan Vien)
- Tim kiem can bo theo ho ten
- Hien thi danh sach can bo
using System;
using System.Collections.Generic;
class CanBo
{
public string HoTen { get; set; }
public int NamSinh { get; set; }
public string GioiTinh { get; set; }
public string DiaChi { get; set; }
public virtual void Nhap()
{
Console.Write("Nhap ho ten: ");
HoTen = Console.ReadLine();
Console.Write("Nhap nam sinh: ");
NamSinh = int.Parse(Console.ReadLine());
Console.Write("Nhap gioi tinh: ");
GioiTinh = Console.ReadLine();
Console.Write("Nhap dia chi: ");
DiaChi = Console.ReadLine();
}
public virtual void HienThi()
{
Console.WriteLine($"Ho ten: {HoTen}, Nam sinh: {NamSinh}, Gioi tinh: {GioiTinh}, Dia chi: {DiaChi}");
}
}
class CongNhan : CanBo
{
public string Bac { get; set; }
public override void Nhap()
{
base.Nhap();
Console.Write("Nhap bac cong nhan (VD: 3/7): ");
Bac = Console.ReadLine();
}
public override void HienThi()
{
base.HienThi();
Console.WriteLine($"Bac cong nhan: {Bac}");
}
}
class KySu : CanBo
{
public string NganhDaoTao { get; set; }
public override void Nhap()
{
base.Nhap();
Console.Write("Nhap nganh dao tao: ");
NganhDaoTao = Console.ReadLine();
}
public override void HienThi()
{
base.HienThi();
Console.WriteLine($"Nganh dao tao: {NganhDaoTao}");
}
}
class NhanVien : CanBo
{
public string CongViec { get; set; }
public override void Nhap()
{
base.Nhap();
Console.Write("Nhap cong viec: ");
CongViec = Console.ReadLine();
}
public override void HienThi()
{
base.HienThi();
Console.WriteLine($"Cong viec: {CongViec}");
}
}
class QLCB
{
private List<CanBo> danhSachCanBo = new List<CanBo>();
public void NhapCanBoMoi()
{
Console.WriteLine("Chon loai can bo muon nhap:");
Console.WriteLine("1. Cong nhan");
Console.WriteLine("2. Ky su");
Console.WriteLine("3. Nhan vien");
Console.Write("Lua chon cua ban: ");
int luaChon = int.Parse(Console.ReadLine());
CanBo canBo = null;
switch (luaChon)
{
case 1:
canBo = new CongNhan();
break;
case 2:
canBo = new KySu();
break;
case 3:
canBo = new NhanVien();
break;
default:
Console.WriteLine("Lua chon khong hop le!");
return;
}
canBo.Nhap();
danhSachCanBo.Add(canBo);
}
public void HienThiDanhSach()
{
Console.WriteLine("\n--- Danh sach can bo ---");
foreach (var cb in danhSachCanBo)
{
cb.HienThi();
Console.WriteLine("----------------------");
}
}
public void TimKiemTheoTen(string ten)
{
Console.WriteLine($"\nKet qua tim kiem voi ten chua: {ten}");
foreach (var cb in danhSachCanBo)
{
if (cb.HoTen.ToLower().Contains(ten.ToLower()))
{
cb.HienThi();
Console.WriteLine("----------------------");
}
}
}
}
class Program
{
static void Main(string[] args)
{
QLCB qlcb = new QLCB();
int luaChon;
do
{
Console.WriteLine("\n=== MENU ===");
Console.WriteLine("1. Nhap can bo moi");
Console.WriteLine("2. Tim kiem can bo theo ho ten");
Console.WriteLine("3. Hien thi danh sach can bo");
Console.WriteLine("4. Thoat");
Console.Write("Nhap lua chon: ");
luaChon = int.Parse(Console.ReadLine());
switch (luaChon)
{
case 1:
qlcb.NhapCanBoMoi();
break;
case 2:
Console.Write("Nhap ten can bo muon tim: ");
string ten = Console.ReadLine();
qlcb.TimKiemTheoTen(ten);
break;
case 3:
qlcb.HienThiDanhSach();
break;
case 4:
Console.WriteLine("Dang thoat chuong trinh...");
break;
default:
Console.WriteLine("Lua chon khong hop le!");
break;
}
} while (luaChon != 4);
}
}
*/
/*
Bai 2: Quan Ly Tai Lieu
- Nhap thong tin tai lieu (ma tai lieu, ten nha xuat ban, so ban phat hanh)
- Phan loai tai lieu (Sach, Tap Chi, Bao)
- Tim kiem tai lieu theo loai
- Hien thi danh sach tai lieu
using System;
using System.Collections.Generic;
class TaiLieu
{
public string MaTaiLieu { get; set; }
public string NhaXuatBan { get; set; }
public int SoBanPhatHanh { get; set; }
public virtual void Nhap()
{
Console.Write("Nhap ma tai lieu: ");
MaTaiLieu = Console.ReadLine();
Console.Write("Nhap ten nha xuat ban: ");
NhaXuatBan = Console.ReadLine();
Console.Write("Nhap so ban phat hanh: ");
SoBanPhatHanh = int.Parse(Console.ReadLine());
}
public virtual void HienThi()
{
Console.WriteLine($"Ma: {MaTaiLieu}, NXB: {NhaXuatBan}, So ban: {SoBanPhatHanh}");
}
public virtual string LoaiTaiLieu()
{
return "Tai lieu";
}
}
class Sach : TaiLieu
{
public string TenTacGia { get; set; }
public int SoTrang { get; set; }
public override void Nhap()
{
base.Nhap();
Console.Write("Nhap ten tac gia: ");
TenTacGia = Console.ReadLine();
Console.Write("Nhap so trang: ");
SoTrang = int.Parse(Console.ReadLine());
}
public override void HienThi()
{
base.HienThi();
Console.WriteLine($"Tac gia: {TenTacGia}, So trang: {SoTrang}");
}
public override string LoaiTaiLieu() => "Sach";
}
class TapChi : TaiLieu
{
public int SoPhatHanh { get; set; }
public int ThangPhatHanh { get; set; }
public override void Nhap()
{
base.Nhap();
Console.Write("Nhap so phat hanh: ");
SoPhatHanh = int.Parse(Console.ReadLine());
Console.Write("Nhap thang phat hanh: ");
ThangPhatHanh = int.Parse(Console.ReadLine());
}
public override void HienThi()
{
base.HienThi();
Console.WriteLine($"So PH: {SoPhatHanh}, Thang PH: {ThangPhatHanh}");
}
public override string LoaiTaiLieu() => "Tap chi";
}
class Bao : TaiLieu
{
public string NgayPhatHanh { get; set; }
public override void Nhap()
{
base.Nhap();
Console.Write("Nhap ngay phat hanh (dd/mm/yyyy): ");
NgayPhatHanh = Console.ReadLine();
}
public override void HienThi()
{
base.HienThi();
Console.WriteLine($"Ngay PH: {NgayPhatHanh}");
}
public override string LoaiTaiLieu() => "Bao";
}
class QuanLyTaiLieu
{
private List<TaiLieu> danhSach = new List<TaiLieu>();
public void NhapTaiLieu()
{
Console.WriteLine("Chon loai tai lieu:");
Console.WriteLine("1. Sach");
Console.WriteLine("2. Tap chi");
Console.WriteLine("3. Bao");
Console.Write("Nhap lua chon: ");
int chon = int.Parse(Console.ReadLine());
TaiLieu tl = null;
switch (chon)
{
case 1: tl = new Sach(); break;
case 2: tl = new TapChi(); break;
case 3: tl = new Bao(); break;
default:
Console.WriteLine("Lua chon khong hop le!");
return;
}
tl.Nhap();
danhSach.Add(tl);
}
public void HienThiTatCa()
{
Console.WriteLine("\n--- DANH SACH TAI LIEU ---");
foreach (var tl in danhSach)
{
Console.WriteLine($"Loai: {tl.LoaiTaiLieu()}");
tl.HienThi();
Console.WriteLine("------------------------");
}
}
public void TimKiemTheoLoai(string loai)
{
Console.WriteLine($"\n--- Tim tai lieu theo loai: {loai} ---");
foreach (var tl in danhSach)
{
if (tl.LoaiTaiLieu().ToLower() == loai.ToLower())
{
tl.HienThi();
Console.WriteLine("------------------------");
}
}
}
}
class Program
{
static void Main(string[] args)
{
QuanLyTaiLieu qltl = new QuanLyTaiLieu();
int luaChon;
do
{
Console.WriteLine("\n=== MENU ===");
Console.WriteLine("1. Nhap tai lieu moi");
Console.WriteLine("2. Hien thi danh sach tai lieu");
Console.WriteLine("3. Tim tai lieu theo loai (Sach, Tap chi, Bao)");
Console.WriteLine("4. Thoat");
Console.Write("Nhap lua chon: ");
luaChon = int.Parse(Console.ReadLine());
switch (luaChon)
{
case 1:
qltl.NhapTaiLieu();
break;
case 2:
qltl.HienThiTatCa();
break;
case 3:
Console.Write("Nhap loai tai lieu muon tim: ");
string loai = Console.ReadLine();
qltl.TimKiemTheoLoai(loai);
break;
case 4:
Console.WriteLine("Dang thoat chuong trinh...");
break;
default:
Console.WriteLine("Lua chon khong hop le!");
break;
}
} while (luaChon != 4);
}
}
*/