Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 10 của 10
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Quản lý Số lượng khách hàng thuê xe

    Mã nguồn PHP:
    using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ClassPTIENVANTAI{ class Program { class PTVanTai { protected string tenkhach; protected string socmdn; public string loaixe; public string xe1 = "XeDap"; public string xe2 = "XeMay"; protected DateTime Ngaythue; public double sogiothue; protected double SOGIOTHUE { get { return sogiothue; } set { sogiothue = value; } } protected string TENKHACH { get { return tenkhach; } set { tenkhach = value; } } protected DateTime NGAYGIOTHUE { get { return Ngaythue; } set { Ngaythue = value; } } public string SOCMND { get { return socmdn; } set { socmdn = value; } } public void Nhap1() { Console.Write("Ten KH: "); tenkhach = Console.ReadLine(); Console.Write("So Gio Thue Xe: "); sogiothue = Convert.ToDouble(Console.ReadLine()); Console.Write("So CMND: "); socmdn = Console.ReadLine(); Console.Write("Ngay Thue: "); Ngaythue = DateTime.Parse(Console.ReadLine()); } } class XEDAP : PTVanTai { public double tien; public double tongtien1() { XEDAP x = new XEDAP(); if (x.sogiothue > 1) { x.tien = 20 + x.sogiothue * 10; return x.tien; } else if (sogiothue <= 1 && x.sogiothue > 0) { x.tien = 20; return x.tien; } else /*Console.Write("Nhap sai!!!");*/ return x.tien; } public void Nhap2() { base.Nhap1(); } public void Xuat1() { XEDAP x3 = new XEDAP(); Console.WriteLine("Ten KH: " + TENKHACH); Console.WriteLine("So Gio Thue Xe: " + SOGIOTHUE); Console.WriteLine("So CMND: " + SOCMND); Console.WriteLine("Ngay cho thue: " + NGAYGIOTHUE); Console.Write("Tong Tien: ",x3.tongtien1()); } class XEMAY : PTVanTai { public int phankhoixe; public string biensoxe; public double tien2; public int PHANKHOIXE { get { return phankhoixe; } set { phankhoixe = value; } } public string BIENSOXE { get { return biensoxe; } set { biensoxe = value; } } public void Nhap3() { base.Nhap1(); Console.Write("Bien So: "); biensoxe = Console.ReadLine(); Console.Write("Phan khoi xe:"); phankhoixe = Convert.ToInt32(Console.ReadLine()); } public void tongtien2() { XEMAY y = new XEMAY(); if (y.phankhoixe>100) { if (y.sogiothue > 1) y.tien2 = 80 + y.sogiothue * 50; else if (y.sogiothue > 0 && y.sogiothue < 1) y.tien2 = 80; else Console.Write("Sai!!!"); } else if (phankhoixe<100) { if (y.sogiothue > 1) y.tien2 = 40 + y.sogiothue * 20; else if (y.sogiothue > 0 && y.sogiothue < 1) y.tien2 = 40; else Console.Write("Nhap sai!!!"); /* return y.tien2;*/ } } public void xuat3() { XEMAY A = new XEMAY(); Console.Write("Ten KH: " + TENKHACH); Console.Write("So Gio Thue Xe: " + SOGIOTHUE); Console.Write("So CMND: " + SOCMND); Console.Write("Ngay cho thue: " + NGAYGIOTHUE); Console.Write("Bien so xe: " + BIENSOXE); Console.Write("Tien Thue: "); A.tongtien2(); } } static void Main(string[] args) { XEDAP[] KH = new XEDAP[100]; Console.Write("So Luong KH: "); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { KH[i] = new XEDAP(); Console.WriteLine("------"); Console.WriteLine("Khach Hang Thu: "+(i + 1)); KH[i].Nhap2(); } Console.Clear(); Console.WriteLine("-------- Danh Sach KH------------"); for (int i = 0; i < n; i++) { KH[i].Xuat1(); Console.WriteLine("---------------"); } Console.ReadLine(); } } }}  
    sao nó không in ra sô tiền thuê xe nhi?mặc dù mình đã viết ham rùi mà!!!

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    trong hàm xuat3() thêm;
    Console.WriteLine(A.tongtien2(sogiothue)); nhé

  3. #3
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    hình như bạn chưa hiểu thì phải!bạn coppy code chạy thử là hiểu ngay ý mà

  4. #4
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Mã:
    using System;
    using System.Collections.Generic;
    
    using System.Text;
    
    namespace ClassPTIENVANTAI
    {
        class Program
        {
            class PTVanTai
            {
                protected string tenkhach;
                protected string socmdn;
                public string loaixe;
                public string xe1 = "XeDap";
                public string xe2 = "XeMay";
                protected DateTime Ngaythue;
                public int sogiothue;
    
                protected int SOGIOTHUE
                {
                    get { return sogiothue; }
                    set { sogiothue = value; }
                }
    
                protected string TENKHACH
                {
                    get { return tenkhach; }
                    set { tenkhach = value; }
                }
                protected DateTime NGAYGIOTHUE
                {
                    get { return Ngaythue; }
                    set { Ngaythue = value; }
                }
    
                public string SOCMND
                {
                    get { return socmdn; }
                    set { socmdn = value; }
                }
    
                public void Nhap1()
                {
                    Console.Write("Ten KH: ");
                    tenkhach = Console.ReadLine();
    
                    Console.Write("So Gio Thue Xe: ");
                    sogiothue = Convert.ToInt32(Console.ReadLine());
    
                    Console.Write("So CMND: ");
                    socmdn = Console.ReadLine();
    
                    Console.Write("Ngay Thue: ");
                    Ngaythue = DateTime.Parse(Console.ReadLine());
                }
            }
            class XEDAP : PTVanTai
            {
                public int tien;
                public int tongtien1(int giothue)
                {
                    XEDAP x = new XEDAP();
                    if (giothue > 1)
                    {
                        x.tien = 20000 + giothue * 10000;
                    }
                    else if (giothue <= 1 && giothue > 0)
                    {
                        x.tien = 20000;
                    }
                    else
                        return x.tien;
                    return x.tien;
                }
                public void Nhap2()
                {
                    base.Nhap1();
                }
                protected void Xuat1()
                {
                    Console.Write("Ten KH: " + TENKHACH);
                    Console.Write("So Gio Thue Xe: " + SOGIOTHUE);
                    Console.Write("So CMND: " + SOCMND);
                    Console.Write("Ngay cho thue: " + NGAYGIOTHUE);
                    Console.Write("Tong Tien: ");
                    tongtien1(sogiothue);
                }
                class XEMAY : PTVanTai
                {
                    public int phankhoixe;
                    public string biensoxe;
                    public int tien2;
                    public int PHANKHOIXE
                    {
                        get { return phankhoixe; }
                        set { phankhoixe = value; }
                    }
                    public string BIENSOXE
                    {
                        get { return biensoxe; }
                        set { biensoxe = value; }
                    }
                    public void Nhap3()
                    {
                        base.Nhap1();
                        Console.Write("Bien So: ");
                        biensoxe = Console.ReadLine();
                        Console.Write("Phan khoi xe:");
                        phankhoixe = Convert.ToInt32(Console.ReadLine());
                    }
    
                    public int tongtien2(int giothue2)//Lồi chỗ này 
                    {
                        if (phankhoixe > 100)
                        {
                            if (giothue2 > 1)
                                tien2 = 80000 + giothue2 * 50000;
                            else if (giothue2 > 0 && giothue2 < 1)
                                tien2 = 80000;
                            else
                                return tien2;
                        }
                        else if (phankhoixe < 100)
                        {
                            if (giothue2 > 1)
                                tien2 = 40000 + giothue2 * 20000;
                            else if (giothue2 > 0 && giothue2 < 1)
                                tien2 = 40000;
                            else
                                return tien2;
                        }
                        return tien2;
                    }
                    public void xuat3()
                    {
                        XEMAY A = new XEMAY();
                        Console.Write("Ten KH: " + TENKHACH);
                        Console.Write("So Gio Thue Xe: " + SOGIOTHUE);
                        Console.Write("So CMND: " + SOCMND);
                        Console.Write("Ngay cho thue: " + NGAYGIOTHUE);
                        Console.Write("Bien so xe: " + BIENSOXE);
                        Console.Write("Tien Thue: ");
                        Console.WriteLine(A.tongtien2(sogiothue));
    
                    }
                }
                static void Main(string[] args)
                {
                    XEMAY[] KH = new XEMAY[100];
                    Console.Write("So Luong KH: ");
                    int n = int.Parse(Console.ReadLine());
                    for (int i = 0; i < n; i++)
                    {
                        KH[i] = new XEMAY();
                        Console.Write("------");
                        Console.Write("Khch Hang Thu: " + (i + 1));
                        KH[i].Nhap3();
                    }
                    Console.Clear();
                    Console.WriteLine("-------- Danh Sach KH------------");
                    for (int i = 0; i < n; i++)
                    {
                        KH[i].xuat3();
                        Console.WriteLine("---------------");
                    }
                    Console.ReadLine();
                }
            }
        }
    }
    mình hiểu ý bạn ,mình thêm vào thì chạy bt mà

  5. #5
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    sao nhập vào số phân khối >100 thì kq sai nhỉ!!!
    giờ mình thấy đau đầu wa!!

  6. #6
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    khi phân khối> 100 thì tính sai do bạn khai báo mội đối tượng mới trong hàm xuất nên nó hiểu phân khối ==0 và luôn chạy vào trường hợp phân khối xe < 100.Sửa lại hàm xuat3 thành
    Mã:
     public void xuat3()
                    {
                        
                        Console.Write("Ten KH: " + TENKHACH);
                        Console.Write("So Gio Thue Xe: " + SOGIOTHUE);
                        Console.Write("So CMND: " + SOCMND);
                        Console.Write("Ngay cho thue: " + NGAYGIOTHUE);
                        Console.Write("Bien so xe: " + BIENSOXE);
                        Console.Write("Tien Thue: ");
                        Console.WriteLine(tongtien2(sogiothue));
    
                    }

  7. #7
    Ngày tham gia
    Dec 2015
    Bài viết
    0
    Thanhks you nhìu nhé!!!yahoo của mình đây:motchotatca2311
    add vào có gì liên lạc học tập!!!!
    Thank you very much!!

  8. #8
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    CODE CHUẨN
    Mã nguồn PHP:
    using System;using System.Collections.Generic;using System.Text;namespace ClassPTIENVANTAI{ class Program { class PTVanTai { protected string tenkhach; protected string socmdn; public string loaixe; protected DateTime Ngaythue; public int sogiothue; protected int SOGIOTHUE { get { return sogiothue; } set { sogiothue = value; } } protected string TENKHACH { get { return tenkhach; } set { tenkhach = value; } } protected DateTime NGAYGIOTHUE { get { return Ngaythue; } set { Ngaythue = value; } } public string SOCMND { get { return socmdn; } set { socmdn = value; } } public void Nhap() { Console.Write("Ten KH: "); tenkhach = Console.ReadLine(); Console.Write("So Gio Thue Xe: "); sogiothue = Convert.ToInt32(Console.ReadLine()); Console.Write("So CMND: "); socmdn = Console.ReadLine(); Console.Write("Ngay Thue: "); Ngaythue = DateTime.Parse(Console.ReadLine()); } } class XEDAP : PTVanTai { public int tien1; public int tongtien1(int giothue1) { if (giothue1 > 1) { tien1 = 20 + (giothue1-1) * 10; return tien1; } else if (giothue1 <= 1 && giothue1 > 0) { tien1 = 20; return tien1; } else return tien1; } public void Nhap1() { base.Nhap(); } protected void Xuat1() { Console.Write("Ten KH: " + TENKHACH); Console.Write("So Gio Thue Xe: " + SOGIOTHUE); Console.Write("So CMND: " + SOCMND); Console.Write("Ngay cho thue: " + NGAYGIOTHUE); Console.WriteLine("Tien Thue Xe Trong " + SOGIOTHUE + " gio La: " + tongtien1(sogiothue) + "K"); } class XEMAY : PTVanTai { public int phankhoixe; public string biensoxe; public int tien2; public int PHANKHOIXE { get { return phankhoixe; } set { phankhoixe = value; } } public string BIENSOXE { get { return biensoxe; } set { biensoxe = value; } } public void Nhap2() { base.Nhap(); Console.Write("Bien So: "); biensoxe = Console.ReadLine(); Console.Write("Phan khoi xe:"); phankhoixe = Convert.ToInt32(Console.ReadLine()); } public int tongtien2(int giothue2) { if (phankhoixe > 100) { if (giothue2 > 1) tien2 = 80 + (giothue2-1) * 50; else if (giothue2 > 0 && giothue2 <= 1) tien2 = 80; else return tien2; } else { if (giothue2 > 1) tien2 = 40 + (giothue2-1) * 20; else if (giothue2 > 0 && giothue2 <= 1) tien2 = 40; else return tien2; } return tien2; } public void xuat2() { Console.WriteLine("Ten KH: " + TENKHACH); Console.WriteLine("So Gio Thue Xe: " + SOGIOTHUE); Console.WriteLine("So CMND: " + SOCMND); Console.WriteLine("Ngay cho thue: " + NGAYGIOTHUE); Console.WriteLine("Bien so xe: " + BIENSOXE); Console.WriteLine("Tien Thue Xe Trong " + SOGIOTHUE +" gio La: "+ tongtien2(sogiothue) + "K"); } } static void Main(string[] args) { Console.WriteLine("Xe May(m)***Xe Dap(d):"); if (Console.ReadLine() == "M") { Console.Write("So Luong KH: "); int n = int.Parse(Console.ReadLine()); XEMAY[] XE1 = new XEMAY[100]; for (int i = 0; i < n; i++) { XE1[i] = new XEMAY(); Console.WriteLine("------"); Console.WriteLine("Khach Hang Thu: " + (i + 1)); XE1[i].Nhap2(); } Console.Clear(); Console.WriteLine("-------- Danh Sach KH------------"); for (int i = 0; i < n; i++) { XE1[i].xuat2(); Console.WriteLine("==============="); } } else if (Console.ReadLine() == "D") { Console.Write("So Luong KH: "); int n = int.Parse(Console.ReadLine()); XEDAP[] XE2 = new XEDAP[100]; for (int i = 0; i < n; i++) { XE2[i] = new XEDAP(); Console.WriteLine("------"); Console.WriteLine("Khach Hang Thu: " + (i + 1)); XE2[i].Nhap1(); } Console.Clear(); Console.WriteLine("-------- Danh Sach KH------------"); for (int i = 0; i < n; i++) { XE2[i].Xuat1(); Console.WriteLine("==============="); } } Console.ReadLine(); } } }}  

  9. #9
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

  10. #10
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Ai có nhu cầu thì viết thêm cái hàm timespan để tính độ lệch của 2 khoảng thời gian hêy!!

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •