// Ham khoi dung sao chep
 public ThoiGian(ThoiGian tg)
 {
     nam   = tg.Nam;
     thang = tg.thang;
     ngay  = tg.ngay;
     gio   = tg.gio;
     phut  = tg.phut;
     giay  = tg.giay;
 }
示例#2
0
        public static void Main()
        {
            // Khoi tao doi tuong 1 voi ham khoi dung DateTime
            ThoiGian t1 = new ThoiGian(DateTime.Now);

            t1.ThoiGianHienHanh();

            // Khoi tao doi tuong 2 voi ham khoi dung co bien thanh vien mac dinh
            ThoiGian t2 = new ThoiGian(2016, 06, 27, 14, 32);

            t2.ThoiGianHienHanh();

            // Khoi tao doi tuong 3 voi ham khoi dung sao chep
            ThoiGian t3 = new ThoiGian(t1);

            t3.ThoiGianHienHanh();

            // Get time dung tham chieu ref
            int gio = 0, phut = 0, giay = 2;

            t3.GetTime(ref gio, ref phut, ref giay);
            Console.WriteLine("get time: {0}:{1}:{2}", gio, phut, giay);

            // Get date dung tham chieu out
            int nam, thang, ngay;

            t3.GetDay(out nam, out thang, out ngay);
            Console.WriteLine("Get day: {0}/{1}/{2}", nam, thang, ngay);

            // Truy cap bang thuoc tinh
            // Lay du lieu tu thuoc tinh
            int pNam = t3.Nam;

            Console.WriteLine("Lay Nam: {0}", pNam);
            pNam++;
            t3.Nam = pNam;
            Console.WriteLine("Update Nam: {0}", pNam);

            // Phuong thuc
            Console.WriteLine();
            int       var1 = 5;
            float     var2 = 10.5f;
            Parameter pa   = new Parameter();

            pa.SomeMethod(var1, var2);

            // Dem so luong Cats
            Console.WriteLine();
            Cat.HowManyCats();
            Cat mun = new Cat();

            Cat.HowManyCats();
            Cat muop = new Cat();
            Cat miu  = new Cat();

            Cat.HowManyCats();

            // bai tap duong tron
            Console.WriteLine();
            DuongTron dt = new DuongTron(4, new Point(2, 3));

            Console.WriteLine("Chu vi duong tron: {0:F2}", dt.ChuVi());
            Console.WriteLine("Dien tich duong tron: {0:F2}", dt.DienTich());

            DuongTron dt2 = new DuongTron(6, new Point(3, 5));

            dt2.BanKinh = 4;
            Console.WriteLine("Chu vi duong tron: {0:F2}", dt2.ChuVi());
            Console.WriteLine("Dien tich duong tron: {0:F2}", dt2.DienTich());

            // Bai tap phuong trinh bac 2
            Console.WriteLine();
            PTBac2 pt1        = new PTBac2(1, -2, 1);
            bool   KtCoNghiem = pt1.TinhNghiem();

            if (KtCoNghiem == false)
            {
                Console.WriteLine("PT vo nghiem");
            }
            else
            {
                Console.WriteLine("PT co nghiem x1 = {0:F2}", pt1.X1);
                Console.WriteLine("PT co nghiem x2 = {0:F2}", pt1.X2);
            }

            //

            Console.ReadLine();
        }