- Code:
using System;
class Date
{
public Date(byte ngay, byte thang, short nam)
{
this.ngay = ngay;
this.thang = thang;
this.nam = nam;
}
public void getNgay(out byte ngay, out byte thang, out short nam)
{
ngay = this.ngay;
thang = this.thang;
nam = this.nam;
}
byte ngay;
byte thang;
short nam;
}
- Code:
using System;
class Time
{
public Time(byte gio,byte phut)
{
this.gio = gio;
this. phut = phut;
}
public void getGio(out byte gio, out byte phut)
{
gio = this.gio;
phut = this.phut;
}
byte gio;
byte phut;
}
- Code:
using System;
class FlightOfTicket
{
public
FlightOfTicket(Date ngayKhoiHanh, Time gioKhoiHanh, string
hoVaTenKhachHang, byte soLuongVe, double giaVe, byte loaiCabin, bool
khuyenMai)
{
this.ngayKhoiHanh = ngayKhoiHanh;
this.gioKhoiHanh = gioKhoiHanh;
this.hoVaTenKhachHang = hoVaTenKhachHang;
this.soLuongVe = soLuongVe;
this.giaVe = giaVe;
this.loaiCabin = loaiCabin;
this.khuyenMai = khuyenMai;
}
public Date NgayKhoiHanh
{
get
{
return ngayKhoiHanh;
}
set
{
ngayKhoiHanh=value;
}
}
public Time GioKhoiHanh
{
get
{
return gioKhoiHanh;
}
set
{
gioKhoiHanh = value;
}
}
public double TienKhuyenMai()
{
byte day, month,hour,minute;
short year;
double TienKM = 0;
if (khuyenMai)
{
if (loaiCabin == 1 && soLuongVe > 3)
TienKM = 0.2 * soLuongVe * giaVe;
if (loaiCabin == 2 && soLuongVe > 2)
TienKM = 0.25 * soLuongVe * giaVe * loaiCabin;
if (loaiCabin == 3 && soLuongVe > 1)
TienKM = 0.3 * soLuongVe * giaVe * loaiCabin;
}
ngayKhoiHanh.getNgay(out day, out month, out year);
gioKhoiHanh.getGio(out hour, out minute);
if (hour < 6 || hour == 6 && minute < 31 )
TienKM += 0.15 * soLuongVe * giaVe * loaiCabin;
else if (day < 6)
TienKM += 0.1 * soLuongVe * giaVe * loaiCabin;
return TienKM;
}
public double TongTienVe()
{
return soLuongVe * giaVe * loaiCabin - TienKhuyenMai();
}
public void HienThiNgay()
{
byte day, month;
short year;
ngayKhoiHanh.getNgay(out day, out month, out year);
Console.WriteLine("{0} / {1} /{2}", day, month, year);
}
public void HienThiGio()
{
byte hour, minute;
gioKhoiHanh.getGio(out hour, out minute);
Console.WriteLine("{0} : {1}", hour, minute);
}
public void HienThiThongTinVe()
{
Console.WriteLine("Ho ten khach hang: {0}",hoVaTenKhachHang);
Console.WriteLine("So luong ve: {0}", soLuongVe);
Console.WriteLine("Loai ve: {0}", loaiCabin);
Console.Write("Ngay khoi hanh: "); HienThiNgay();
Console.Write("Gio khoi hanh: "); HienThiGio();
Console.WriteLine("Tong tien phai tra: {0}", TongTienVe());
}
Date ngayKhoiHanh;
Time gioKhoiHanh;
string hoVaTenKhachHang;
byte soLuongVe;
double giaVe;
byte loaiCabin;
bool khuyenMai;
}
- Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Tester
{
public static void Main()
{
Date day = new Date(20,10,2009);
Time time = new Time(5,30);;
FlightOfTicket ve = new FlightOfTicket(day, time," Nguyen van A ", 2, 100000,3, true);
Console.WriteLine("thong tin khach hang: "); ve.HienThiThongTinVe();
Console.ReadLine();
}
}