avatar
Untitled

Guest 121 14th Mar, 2019

                                           
                         #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

// ham xu ly ngay thang nam
int minYear=0,maxYear=3000;
class Ngay_Thang_Nam{
protected:
    int Ngay;int Thang;int Nam;
public:
    Ngay_Thang_Nam();
    Ngay_Thang_Nam(int ngay, int thang, int nam);
    void setNgay(int ngay);
    int getNgay();
    void setThang(int thang);
    int getThang();
    void setNam(int nam);
    int getNam();
    void nhap();
    void xuat();
    bool Check_Ngay();
    bool Check_Thang();
    bool Check_Nam();
    bool Check_Lich();

};
Ngay_Thang_Nam::Ngay_Thang_Nam(){
    Ngay=0;
    Thang=0;
    Nam=0;
}
Ngay_Thang_Nam::Ngay_Thang_Nam(int ngay, int thang, int nam){
    Ngay=ngay;
    Thang=thang;
    Nam=nam;
}
void Ngay_Thang_Nam::setNgay(int ngay){
    Ngay=ngay;
}
int Ngay_Thang_Nam::getNgay(){
    return Ngay;
}
void Ngay_Thang_Nam::setThang(int thang){
    Thang=thang;
}
int Ngay_Thang_Nam::getThang(){
    return Thang;
}
void Ngay_Thang_Nam::setNam(int nam){
    Nam=nam;
}
int Ngay_Thang_Nam::getNam(){
    return Nam;
}
void Ngay_Thang_Nam::nhap(){
    do{
        cout<<"Nhap ngay: ";
        cin>>Ngay;
        cout<<"Nhap thang: ";
        cin>>Thang;
        cout<<"Nhap nam: ";
        cin>>Nam;
        if(!Check_Ngay()){
            cout<<"Nhap khong hop le ! Nhap lai !!!";
        }
        if(!Check_Thang()){
            cout<<"Nhap khong hop le ! Nhap lai !!!";

        }
        if(!Check_Nam()){
            cout<<"Nhap khong hop le ! Nhap lai !!!";

        }
        if(!Check_Lich()){

        }
    }
    while(!Check_Ngay()||!Check_Thang()||!Check_Nam());


}

bool Ngay_Thang_Nam::Check_Ngay(){
    if ((Thang == 2) && (Ngay > 0)) {
        if(( Nam % 4 == 0 && Nam % 100 != 0) || Nam % 400 == 0){
            if(Ngay<30)
                return true;

        }
        else{
            if (Ngay<29) {
                return true;
            }
        }
        return false;
    }
    if (((Thang == 1)||(Thang == 3)||(Thang == 5)||(Thang == 7)||(Thang == 8)||(Thang == 10)||(Thang == 12)) && (Ngay > 0) && (Ngay < 32)) {
        return true;
    }
    if (((Thang==4) ||(Thang==6) ||(Thang==9) ||(Thang==11)) && ((Ngay>0) && (Ngay<31)))
    {
        return true;
    }
    return false;
}
bool Ngay_Thang_Nam::Check_Thang(){
    if(Thang > 0 && Thang < 13){
        return true;
    }
    else
        return false;
}

bool Ngay_Thang_Nam::Check_Nam(){
    if(Nam < minYear||Nam>maxYear)
        return false;
    return true;
}
bool Ngay_Thang_Nam::Check_Lich(){
    // công thức tính thứ mấy trong tuần.
    int JMD = (Ngay + ((153 * (Thang + 12 * ((14 - Thang) / 12) - 3) + 2) / 5) +
               (365 * (Nam + 4800 - ((14 - Thang) / 12))) +
               ((Nam + 4800 - ((14 - Thang) / 12)) / 4) -
               ((Nam + 4800 - ((14 - Thang) / 12)) / 100) +
               ((Nam + 4800 - ((14 - Thang) / 12)) / 400)  - 32045) % 7;
    //       int JMD = (year - 1 + ((year - 1)/4) - ((year - 1)/100) + ((year - 1)/400) + day) % 7;
    string Thu[]={"Thu 2","Thu 3", "Thu 4","Thu 5","Thu 6","Thu 7", "Chu nhat"};
    cout<<Thu[JMD]<<endl;
    return false;
}
void Ngay_Thang_Nam::xuat(){
    cout<<"Ngay xuat hoa don: "<< getNgay()<<"/"<<getThang()<<"/"<<getNam()<<endl;
}

class Khach_Hang:public Ngay_Thang_Nam{
protected:
    int ID; // ma khach hang
    string Ho_Ten;
    string Dia_Chi;
    float So_Luong;
    float Don_Gia;
    bool Kiem_Tra; // true la gia dinh.  flase la doanh
public:
    Khach_Hang();
    Khach_Hang(int id,string hoten, string diachi,float soluong, float dongia);
    void setID(int id);
    int getID();
    void setHo_Ten(string hoten);
    string getHo_Ten();
    void setDia_Chi(string diachi);
    string getDia_Chi();
    void setSo_Luong(float soluong);
    float getSo_Luong();
    void setDon_Gia(float dongia);
    float getDon_Gia();
    void setKiem_Tra(bool kt);
    bool getKiem_Tra();
    virtual void nhap();
    virtual void xuat();
    virtual float So_Tien()=0;
};

Khach_Hang::Khach_Hang(){
    ID=0;
    Ho_Ten="";
    Dia_Chi="";
    So_Luong =0;
    Don_Gia=0;
}
Khach_Hang::Khach_Hang(int id,string hoten, string diachi, float soluong, float dongia){
    ID =id;
    Ho_Ten=hoten;
    Dia_Chi=diachi;
    So_Luong=soluong;
    Don_Gia=dongia;

}
void Khach_Hang::setKiem_Tra(bool kt){
    Kiem_Tra=kt;
}
bool Khach_Hang::getKiem_Tra(){
    return Kiem_Tra;
}
void Khach_Hang::setID(int id){
    ID=id;
}
int Khach_Hang::getID(){
    return ID;
}
void Khach_Hang::setHo_Ten(string hoten){
    Ho_Ten=hoten;
}
string Khach_Hang::getHo_Ten(){
    return Ho_Ten;
}
void Khach_Hang::setDia_Chi(string diachi){
    Dia_Chi=diachi;
}
string Khach_Hang::getDia_Chi(){
    return Dia_Chi;
}
void Khach_Hang::setSo_Luong(float soluong){
    So_Luong=soluong;
}
float Khach_Hang::getSo_Luong(){
    return So_Luong;
}
void Khach_Hang::setDon_Gia(float dongia){
    Don_Gia=dongia;
}
float Khach_Hang::getDon_Gia(){
    return Don_Gia=1.549;  // nghin dong / kWh
}
void Khach_Hang::nhap(){
    cout<<"Nhap ma khach hang: "; cin>>ID;
    cout<<"Ho ten: ";
    cin.ignore();
    getline(cin,Ho_Ten);
    cout<<"Dia chi: ";
    getline(cin,Dia_Chi);
    cout<<"So luong: ";
    cin>>So_Luong;
    Ngay_Thang_Nam::nhap();

}

void Khach_Hang::xuat(){
    cout<<"Ma khach hang: "<<getID()<<endl;
    cout<<"Ho ten: "<<getHo_Ten()<<endl;
    cout<<"Dia chi: "<<getDia_Chi()<<endl;
    Ngay_Thang_Nam::xuat();
    cout<<"So luong: "<<getSo_Luong()<<endl;
    cout<<"Don gia: "<<getDon_Gia()<<endl;
}


class Gia_Dinh:public Khach_Hang{
private:
    float Dinh_Muc;
   // float So_Tien;
public:
    Gia_Dinh();
    Gia_Dinh(float dinhmuc);
    void setDinh_Muc(float dinhmuc);
    float getDinh_Muc();

    void nhap();
    void xuat();
    float So_Tien();
};
Gia_Dinh::Gia_Dinh(){
    Dinh_Muc=10;

}
Gia_Dinh::Gia_Dinh(float dinhmuc){
    Dinh_Muc=dinhmuc;
}
void Gia_Dinh::setDinh_Muc(float dinhmuc){
    Dinh_Muc =dinhmuc;
}
float Gia_Dinh::getDinh_Muc()
{
    return Dinh_Muc;
}

float Gia_Dinh::So_Tien(){
    if(getSo_Luong()<Dinh_Muc){
        return getSo_Luong()*getDon_Gia();
    }
    else{
        float Vuot=getSo_Luong()-Dinh_Muc;
        return getSo_Luong()*getDon_Gia()*Dinh_Muc +Vuot*getDon_Gia()*2.5;
    }

}

void Gia_Dinh::nhap(){
    Khach_Hang::nhap();
}
void Gia_Dinh::xuat(){
    Khach_Hang::xuat();
    cout<<"So tien:"<<So_Tien();

}
class Doanh_Nghiep:public Khach_Hang{
private:
    int Ma_So_Thue;
public:
    Doanh_Nghiep();
    Doanh_Nghiep(int masothue);
    void nhap();
    void xuat();
    float So_Tien();

};
Doanh_Nghiep arrDN[100];
int so_doanh_nghiep=0;
Doanh_Nghiep::Doanh_Nghiep(){
    Ma_So_Thue =0;
}
Doanh_Nghiep::Doanh_Nghiep(int masothue){
    Ma_So_Thue=masothue;
}

float Doanh_Nghiep::So_Tien(){
    return getDon_Gia()*getSo_Luong();
}

void Doanh_Nghiep::nhap(){
    Khach_Hang::nhap();
    cout<<"Ma so thue: ";
    cin>>Ma_So_Thue;
    so_doanh_nghiep++;

}
void Doanh_Nghiep::xuat(){
    Khach_Hang::xuat();
    cout<<"Ma so thue: "<<Ma_So_Thue<<endl;
    cout<<"So tien: "<<So_Tien()<<endl;
}

class Quan_Ly{
private:
    vector<Khach_Hang *> ds_Khach_Hang;
public:
    Quan_Ly();
    void nhap();
    void xuat();
    void them();
    void xoa();
    void sua();
    float So_Tien();
    void sapsep();
    float Tien_Gia_Dinh();
    float Tien_Doanh_Nghiep();
    float Doanh_Thu();
};
Quan_Ly::Quan_Ly(){

}
Khach_Hang *x;

void Quan_Ly::nhap(){
    int chon;
    do{
        cout<<"1)Nhap ho gia dinh: "<<endl<<"2)Nhap doanh nghiep: "<<endl;
        cout<<"Nhap su lua chon: ";
        cin>>chon;
        switch(chon){
            case 1:
                x = new Gia_Dinh;
                cout<<"Ho gia dinh: "<<endl;
                x->nhap();
                x->setKiem_Tra(true);
                ds_Khach_Hang.push_back(x);
                break;
            case 2:
                x = new Doanh_Nghiep;
                cout<<"Doanh nghiep: "<<endl;
                x->nhap();
                x->setKiem_Tra(false);
                ds_Khach_Hang.push_back(x);
                break;
        }
    }
    while(chon>=1&&chon<=2);
}

void Quan_Ly::xuat(){
    if(ds_Khach_Hang.empty()==true){
        cout<<"Danh sach rong!!"<<endl;
    }
    else{
        for (int i=0; i<ds_Khach_Hang.size(); i++) {
            if(ds_Khach_Hang[i]->getKiem_Tra()==true){
                cout<<"\nHo gia dinh thu "<<i+1<<endl;
                ds_Khach_Hang[i]->xuat();
            }
            else{
                cout<<"Doanh nghiep thu "<<i+1<<endl;
                ds_Khach_Hang[i]->xuat();
            }
        }
    }
}

void Quan_Ly::them(){
    int chonn=0;
    cout<<"1)Them gia dinh "<<endl<<"2)Them doanh nghiep"<<endl;
    cin>>chonn;
    if(chonn==1){
        x = new Gia_Dinh;
        cout<<"Ho gia dinh: "<<endl;
        x->nhap();
        x->setKiem_Tra(true);
        ds_Khach_Hang.insert(ds_Khach_Hang.begin(), x);
        
    }
    if(chonn==2){
        x = new Doanh_Nghiep;
        cout<<"Doanh nghiep: "<<endl;
        x->nhap();
        x->setKiem_Tra(false);
        ds_Khach_Hang.insert(ds_Khach_Hang.end(), x);
    }
    
}
void Quan_Ly::xoa(){
    if(ds_Khach_Hang.empty()==true){
        cout<<"Danh sach rong!!"<<endl;;
    }
    else{
        int k=0;  // nhap ma can xoa
        cout<<"Nhap ma khach hang: ";
        cin>>k;
        for(int i=0;i<ds_Khach_Hang.size();i++){
            if(k==ds_Khach_Hang[i]->getID()){
                cout<<"Xoa khach hang: "<<endl;
                ds_Khach_Hang.erase(ds_Khach_Hang.begin()+i);
            }
        }
    }
}
void Quan_Ly::sua(){
    if(ds_Khach_Hang.empty()==true){
        cout<<"Danh sach rong!!"<<endl;
    }
    else{
        cout<<"Tim theo ma khach hang !"<<endl;
        int k =0;
        cout<<"Nhap ma can sua: ";
        cin>>k;
        for(int i =0; i<ds_Khach_Hang.size();i++){
            if(k==ds_Khach_Hang[i]->getID()){
                cout<<"Cap nhat thong tin: "<<endl;
                ds_Khach_Hang.erase(ds_Khach_Hang.begin()+i);
                x->nhap();
                ds_Khach_Hang.insert(ds_Khach_Hang.begin()+1, x);
            }
        }
    }
}

float Quan_Ly::Tien_Gia_Dinh(){
    float summ=0;
    for(int i = 0; i<ds_Khach_Hang.size();i++){
        if(ds_Khach_Hang[i]->getKiem_Tra()==true){
            cout<<"Tong tien Ho gia dinh la: "<<endl;
            summ += ds_Khach_Hang[i]->So_Tien();
        }
    }
    return summ;
}

float Quan_Ly::Tien_Doanh_Nghiep(){
    float sum =0;
    for(int i=0; i<ds_Khach_Hang.size();i++){
        if(ds_Khach_Hang[i]->getKiem_Tra()==false){
            sum += ds_Khach_Hang[i]->So_Tien();
        }
    }
    return sum;
}

float Quan_Ly::So_Tien(){
    float sum=0;
    for(int i =0; i<ds_Khach_Hang.size();i++){
        sum += ds_Khach_Hang[i]->So_Tien();
    }
    return sum;
}
float Quan_Ly::Doanh_Thu(){
    float sum =0;
    for( int i =0; i<ds_Khach_Hang.size();i++){
        for( int j =i+1; j<ds_Khach_Hang.size();j++){
            if(ds_Khach_Hang[i]->getNgay()==ds_Khach_Hang[j]->getNgay()){
                float tien = ds_Khach_Hang[i]->So_Tien()+ds_Khach_Hang[j]->So_Tien();
                sum +=tien;
            }
        }
    }
    return sum;
}
bool id(Khach_Hang *kh1, Khach_Hang *kh2){
    return kh1->getID()<kh2->getID();
}

bool nam(Khach_Hang *kh1, Khach_Hang *kh2){
     if(kh1->getNam()<kh2->getNam()){
         return kh1->getNam()<kh2->getNam();
    }
     else if(kh1->getNam()==kh2->getNam()){
         if(kh1->getThang()<kh2->getThang()){
             return kh1->getThang()<kh2->getThang();
         }
         else if( kh1->getThang()==kh2->getThang()){
             if(kh1->getNgay()<kh2->getNgay()){
                 return kh1->getNgay()<kh2->getNgay();
             }
             else if(kh1->getNgay()==kh2->getNgay()){
                 if(kh1->So_Tien()>kh2->So_Tien())
                     return kh1->So_Tien()>kh2->So_Tien();
             }
         }
     }
    return 0;
}

void Quan_Ly::sapsep(){
    sort(ds_Khach_Hang.begin(),ds_Khach_Hang.end(),nam);
}

int main(int argc, const char * argv[]) {
    Quan_Ly *x = new Quan_Ly;
    int choon=0;
    do{
        cout<<"\n1) Nhap khach hang: "<<endl<<"2) Them khach hang "<<endl<<"3) Xoa khach hang "<<endl<<"4) Sua thong tin khach hang "<<endl<<"5) In khach hang"<<endl<<"6) Tong tien"<<endl<<"7)Sap xep"<<endl;
        cout<<"Nhap su lua chon: "; cin>>choon;
        switch (choon) {
            case 1:
                cout<<"Nhap khach hang\n";
                x->nhap();
                break;
            case 2:
                cout<<"Them khach hang\n";
                x->them();
                break;
            case 3:
                cout<<"Xoa khach hang\n";
                x->xoa();
                break;
            case 4:
                cout<<"Sua thong tin khach hang\n";
                x->sua();
                break;
            case 5:
                cout<<"In danh sach khach hang\n";
                x->xuat();
                 cout<<"Tong tien: "<<x->Doanh_Thu();
                break;
           
            case 6:
                int k;
                do{
                    cout<<"1)Tien ho gia dinh"<<endl<<"2) Tien doanh nghiep"<<endl<<"3) Tong tien"<<endl;
                    cout<<"Chon"; cin>>k;
                    switch (k) {
                        case 1:
                            cout<<"Tong tien ho gia dinh: "<<x->Tien_Gia_Dinh();
                            break;
                        case 2:
                            cout<<"Tong tien doanh nghiep: "<<x->Tien_Doanh_Nghiep();
                            break;
                        case 3:
                            cout<<"Tong tien dien: "<<x->So_Tien();
                        default:
                            break;
                    }
                }
                while (k!=0) ;
            case 7:
                cout<<"Sap xep: ";
                x->sapsep();
            default:
                break;
        }

    }
    while (choon!=0);

    delete x;
    return 0;
}
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes