public void Xuat public TienDienMoistring hoTen, string diaChi, int soThangtruoc, int soThangnay, int soMucquydinh : basehoTen, diaChi, soThangtruoc, soThangnay Console.Write"Nhap so m
Trang 1class Program
{ static void Main(string[] args) {
TienDienMoi a = new TienDienMoi("xuan truong", "Nha trang",
{ public string hoTen{get;set;}
public string diaChi{get;set;}
public int soThangtruoc{get;set;}
public int soThangnay{get;set;}
public TienDien() { } public TienDien(string hoTen, string diaChi, int soThangtruoc, int
soThangnay) { this.hoTen = hoTen; this.diaChi = diaChi;
this.soThangtruoc = soThangtruoc; this.soThangnay = soThangnay;
} public void Nhap() {
Console.Write("Nhap hoten: ");
hoTen = Console.ReadLine();
Console.Write("Nhap diachi: ");
diaChi = Console.ReadLine();
Console.Write("Nhap sothangtruoc: ");
soThangtruoc = int.Parse(Console.ReadLine());
Console.Write("Nhap sothangnay: ");
soThangnay = int.Parse(Console.ReadLine());
}
Class tiềndiệnString hotenString diachiInt
sôcôngtothangtruocInt
socongtothangnayVoid nhap()Void xuat()Double sotien()
Class tiendienmoiInt
somucquydinhVoid nhap()Void xuat()Double sotien()
Trang 2public void Xuat()
public TienDienMoi(string hoTen, string diaChi, int soThangtruoc,
int soThangnay, int soMucquydinh)
: base(hoTen, diaChi, soThangtruoc, soThangnay)
Console.Write("Nhap so muc quy dinh: ");
soMucquydinh = int.Parse(Console.ReadLine());
Trang 3Class person String name;
Int age;
String nationality Void nhap() Void xuat()
public string name { get; set; }
public int age { get; set; }
Class coach Int numberyear; Void nhap() Void xuat()
Class player int number;
string vitrithidau;
string doithidau;
Void nhap() Void xuat()
Trang 4public string nationality { get; set; }
Console.Write("Nhap ten: ");
name = Console.ReadLine();
Console.Write("Nhap tuoi: ");
age = int.Parse(Console.ReadLine());
Console.Write("Nhap quoc tich: ");
nationality = Console.ReadLine();
Console.Write("Nhap so ao: ");
number = int.Parse(Console.ReadLine());
Console.Write("Nhap vi tri thi dau: ");
viTrithidau = Console.ReadLine();
Trang 5Console.Write("Nhap so nam kinh nghiem: ");
numberYear = int.Parse(Console.ReadLine());
Console.Write("Nhap ten doi: ");
tenDoi = Console.ReadLine();
Console.Write("Nhap so cau thu: ");
number = int.Parse(Console.ReadLine());
listOfPlayer = new Player[number];
for (int i = 0; i < number; i++)
Console.WriteLine("\nTen doi: " + tenDoi);
Console.WriteLine("\nDanh sach cau thu: ");
for (int i = 0; i < number; i++)
Team t = new Team();
public void Nhap()
{
Trang 6t.Nhap();
} public void Xuat() {
t.Xuat();
} }}
BÀI THỰC HÀNH 4 Bài1:
class Program
{ static void Main(string[] args) {
QuanLyNhanVien a = new QuanLyNhanVien();
a.Nhap();
a.Xuat();
} } class NhanVien
{
Class nhanvien
string hoTen { get; set; }
DateTime ngaySinh { get;
set; }
string diaChi { get;
set; }
virtual void Nhap()
virtual void Xuat()
virtual double Luong()
Class nhanvienquanly
double heSoluong, luongCoban;
override void Nhap()
override void Xuat()
override double
Luong()
Class nhanviencongnhat
int soNgayCong;
override void Nhap()
override void Xuat()
override double Luong()
Class danhsachnhanvien
int soLuongnhanvien;NhanVien[] ds;
override void Nhap()
override void Xuat()
override double
Luong()
Trang 7public string hoTen { get; set; }
public DateTime ngaySinh { get; set; }
public string diaChi { get; set; }
Console.Write("Nhap ho ten: ");
hoTen = Console.ReadLine();
Console.Write("Nhap ngay sinh: ");
ngaySinh =Convert.ToDateTime( Console.ReadLine());
Console.Write("Nhap dia chi: ");
diaChi = Console.ReadLine();
Console.Write("Nhap so san pham: ");
soSanPham = int.Parse(Console.ReadLine());
Trang 8}
public override void Nhap()
{
base.Nhap();
Console.Write("Nhap so ngay cong: ");
soNgayCong = int.Parse(Console.ReadLine());
Console.Write("Nhap he so luong: ");
heSoluong = Convert.ToDouble(Console.ReadLine());
Console.Write("Nhap luong co ban: ");
luongCoban = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("1 Nhan vien san xuat");
Console.WriteLine("2 Nhan vien cong nhat");
Console.WriteLine("3 Nhan vien quan ly");
}
public void Nhap()
{
Console.Write("Nhap so luong nhan vien: ");
soLuongnhanvien = int.Parse(Console.ReadLine());
ds = new NhanVien[soLuongnhanvien];
int chonmuc;
Trang 9for (int i = 0; i < soLuongnhanvien; i++) {
HienThi();
Console.Write("Chon muc: "); chonmuc =
int.Parse(Console.ReadLine());
Trang 10string hoTen { get;
virtual void Nhap()
virtual void Xuat()
class sinhvien
string maSinhvien,lop;
public string hoTen { get; set; }
public DateTime ngaySinh { get; set; }
public string queQuan { get; set; }
Trang 11{
Console.Write("Nhap ho ten: ");
hoTen = Console.ReadLine();
Console.Write("Nhap ngay sinh: ");
ngaySinh =Convert.ToDateTime( Console.ReadLine());
Console.Write("Nhap que quan: ");
queQuan = Console.ReadLine();
public SinhVien(string hoTen, DateTime ngaySinh, string queQuan,
string maSinhvien, string lop)
Trang 12class GiaoVien class
NhanVienHanhChinh
class DSCanBo
override void Nhap()
override double Luong()
override void Xuat()
override void Nhap()
override double Luong()
override void Xuat()
public string hoTen { get; set; }
public string diaChi { get; set; }
public double heSoluong { get; set; }
public double luongCoban { get; set; }
public CanBo() { }
public CanBo(string hoTen, string diaChi, double heSoluong, double
luongCoban)
{
this.hoTen = hoTen; this.diaChi = diaChi; this.heSoluong =
heSoluong; this.luongCoban = luongCoban;
}
public virtual void Nhap()
{
Console.Write("Nhap ten: "); hoTen = Console.ReadLine();
Console.Write("Nhap dia chi: "); diaChi = Console.ReadLine();
virtual void Nhap()
virtual void Xuat()
virtual double Luong()
Trang 13Console.Write("Nhap he so luong: "); heSoluong
=Convert.ToDouble( Console.ReadLine());
Console.Write("Nhap luong co ban: "); luongCoban =
Convert.ToDouble(Console.ReadLine());
}
public virtual void Xuat()
{
Console.WriteLine("Ho ten: " + hoTen + "\nDia chi: " + diaChi +
"\nHe so luong: " + heSoluong +
"\nLuong co ban: " + luongCoban + "\nLuong: " + Luong()); }
public virtual double Luong()
Console.WriteLine("1 Giao vien");
Console.WriteLine("2 Nhan vien hanh chinh");
}
public void Nhap()
{
Trang 14Console.Write("Nhap so nhan vien: "); number =
int.Parse(Console.ReadLine());
ds = new CanBo[number];
for (int i = 0; i < number; i++)
{
HienThi();
Console.Write("Chon muc: "); chonmuc =
int.Parse(Console.ReadLine());
Trang 15class Program
{ static void Main(string[] args) {
HoaDon h = new HoaDon();
h.Nhap();
h.HienThi();
} } class DichVu
{ protected double DonGia { get; set; } public DichVu(){}
public DichVu(double DonGia){this.DonGia = DonGia;}
public virtual void Nhap() {
Console.Write("Don Gia : "); DonGia =
Convert.ToDouble(Console.ReadLine());
} public virtual void Xuat() {
Console.WriteLine("Don Gia : " + DonGia);
Console.WriteLine("Thanh Tien : " + TinhTien());
} public virtual double TinhTien() { return 0; } }
class DichVuGiatTay : DichVu {
int SoKg { get; set; } public DichVuGiatTay() : base() { } public DichVuGiatTay(double DonGia, int SoKg) : base(DonGia) {
this.SoKg = SoKg; }
Trang 16public override void Nhap()
{
Console.Write("So Kg : "); SoKg =
int.Parse(Console.ReadLine());
base.Nhap();
}
public override void Xuat()
{
Console.WriteLine("Giat Ui");
Console.WriteLine("So Kg : " + SoKg);
int SoGio { get; set; }
public DichVuThueXe():base() { }
public DichVuThueXe(double DonGia, int SoGio) : base(DonGia) {
this.SoGio = SoGio; }
public override void Nhap()
{
Console.Write("So Gio : "); SoGio =
int.Parse(Console.ReadLine());
base.Nhap();
}
public override void Xuat()
{
Console.WriteLine("Thue Xe");
Console.WriteLine("So Gio : " + SoGio);
string MaKH, TenKH;
List<DichVu> DS = new List<DichVu>();
Console.Write("So Dich Vu : ");
int n = int.Parse(Console.ReadLine());
Trang 17Console.Write("1 Thue Xe\n2 Giat Ui\n");
Console.Write("Chon muc: ");
int n = int.Parse(Console.ReadLine());
DichVu dv = new DichVu();
void HienThi()
void Nhap()
void Xuat()
Trang 18class Phong class PhongA class PhongB class PhongCint soNgaythue {
get; set; } doubletienSudungDichVu; overrideTinhTien()double
Console.WriteLine("1 Phong A");
Console.WriteLine("2 Phong B");
Console.WriteLine("3 Phong C");
}
public void Nhap()
{
Trang 19Console.Write("Nhap ten: "); hoTen = Console.ReadLine();
Console.Write("Nhap dia chi: "); diaChi = Console.ReadLine(); Console.WriteLine("Phong nao?");
HienThi();
int chonmuc;
Console.Write("Chon phong: "); chonmuc =
int.Parse(Console.ReadLine());
Console.Write("Nhap so ngay thue: "); soNgaythue =
int.Parse(Console.ReadLine());
Trang 20base.Nhap();
Console.Write("Nhap so tien su dung dich vu: ");
tienSudungDichVu = Convert.ToDouble(Console.ReadLine());
Trang 22protected string BS { get; set; }
public abstract void Nhap();
public abstract void Xuat();
public abstract double TinhTien(double SoGio);
string HoTen { get; set; }
int SoGio { get; set; }
Xe XeThue;
public void Nhap()
{
Console.Write("Ho Ten : "); HoTen = Console.ReadLine();
Console.Write("So Gio Thue : "); SoGio =
int.Parse(Console.ReadLine());
Console.WriteLine("Chon loai xe:");
Console.WriteLine("1 Xe Tai\n2 Xe Khach");
Console.Write("Chon muc: ");
int n = int.Parse(Console.ReadLine());
if (n == 1) XeThue = new XeTai();
else XeThue = new XeKhach();
XeThue.Nhap();
}
public void Xuat()
Trang 23{
Console.WriteLine("Ten : " + HoTen + "| So Gio : " + SoGio + "|Loai xe : " + (XeThue is XeKhach ? " Xe Khach" : "Xe Tai") + "| So tien: "+ TinhTien());
Console.Write("Nhap so khach hang thue xe: ");
n = int.Parse(Console.ReadLine());
virtual void Nhap()
virtual void Xuat()
Trang 24class MayLanh class MayGiat class TiVi class ThuNghiemstring maLuc {
get; set; } doubletrongLuong {
public string nhaSanxuat { get; set; }
string moDel { get; set; }
double giaThanh { get; set; }
public DienTu() { }
public DienTu(string nhaSanxuat, string moDel, double giaThanh)
{
Trang 25this.nhaSanxuat = nhaSanxuat; this.moDel = moDel; this.giaThanh
public string maLuc { get; set; }
public MayLanh(string nhaSanxuat, string moDel, double giaThanh,
public double trongLuong { get; set; }
public MayGiat(string nhaSanxuat, string moDel, double giaThanh,
Console.Write("Nhap trong luong: "); trongLuong =
Convert.ToDouble(Console.ReadLine());
Trang 26Console.Write("Nhap kich co man hinh: "); kichCo =
Convert.ToDouble(Console.ReadLine());
Console.WriteLine("1 May Lanh");
Console.WriteLine("2 May Giat");
Console.WriteLine("3 Ti Vi");
}
public void Nhap()
{
Console.Write("Nhap so san pham: "); n =
int.Parse(Console.ReadLine());
Console.Write("Chon muc: "); chon =
int.Parse(Console.ReadLine());
Trang 27Console.WriteLine("Cac mat hang may lanh: ");
for(int i=0;i<n;i++)
if (ds[i] is MayLanh)
{
ds[i].Xuat();
}
Console.WriteLine("Cac mat hang may giat: ");
for (int i = 0; i < n; i++)
if (ds[i] is MayGiat)
{
ds[i].Xuat();
}
Console.WriteLine("Cac mat hang Ti vi: ");
for (int i = 0; i < n; i++)
bool []DanhDau = new bool[n];
for(int i=0;i<n;i++)DanhDau[i] = true;
for (int i = 0; i < n; i++)
Trang 28ds.AddNewCar(new XeKhach("XK01", true, 15));
ds.AddNewCar(new XeKhach("XK02", true, 20));
ds.AddNewCar(new XeKhach("XK03", false, 18));
ds.AddNewCar(new XeTai("KT01", true, 2.5));
ds.AddNewCar(new XeTai("KT02", false, 5.0));
ds.AddNewCar(new XeTai("KT03", true, 15));
protected string MaSo { get; set; }
protected Boolean TrangThai { get; set; }
// Constructor
public Xe() { }
public Xe(string MaSo, Boolean TrangThai)
{ this.MaSo = MaSo; this.TrangThai = TrangThai; }
// Method
public virtual void Nhap()
{
Console.Write("Ma so : "); MaSo = Console.ReadLine();
Console.Write("Trang Thai (T/F): ");
String s = Console.ReadLine();
if (s == "T") TrangThai = true; else TrangThai = false; }
public virtual void Xuat()
public XeTai():base() { }
public XeTai(string MaSo, Boolean TrangThai, double TrongTai) :
base(MaSo, TrangThai)
{ this.TrongTai = TrongTai; }
// Method
public override void Nhap()
{
base.Nhap();
Console.Write("Trong Tai : "); TrongTai =
Convert.ToDouble(Console.ReadLine());
}
Trang 29public override void Xuat()
public XeKhach():base() { }
public XeKhach(string MaSo, Boolean TrangThai, int SoChoNgoi)
: base(MaSo, TrangThai)
Console.Write("So Cho : "); SoChoNgoi =
int.Parse(Console.ReadLine());
Console.Write("So xe : ");
int n = int.Parse(Console.ReadLine());
while (n > 0) AddNewCar();
}
public void Xuat()
{
Console.WriteLine("\tThong tin DS Xe : \n");
foreach (Xe x in DS) x.Xuat();
int SoChoNgoi; double TrongTai;
KhaNangDapUng(out SoChoNgoi, out TrongTai);
Console.WriteLine("\nKha nang dap ung : " + SoChoNgoi + " cho,
va " + TrongTai + " tan.\n");
}
public void AddNewCar()
{
Console.Write("1 Xe Tai\n2 Xe Khach : ");
int n = int.Parse(Console.ReadLine());
Xe x;
if (n == 1) x = new XeTai(); else x = new XeKhach();