Untitled

 avatar
unknown
plain_text
3 years ago
2.6 kB
7
Indexable
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class nguoild
{
    protected:
        int mnv;
        string ht;
        string cv;
        int hsl;
    public:
        nguoild(int mnv=0,string ht="",string cv="",int hsl=0)
        {
           this ->mnv=mnv;
           this ->ht=ht;
           this ->cv=cv;
           this ->hsl=hsl;
        }
        ~nguoild(){}
    void nhap()
    {
        cout <<"Nhap ma nhan vien: ";
        cin >>mnv;
        fflush (stdin);
        cout <<"Nhap ho va ten: ";
        getline(cin,ht);
        cout <<"Nhap chuc vu: ";
        getline(cin,cv);
        cout <<"Nhap he so luong: ";
        cin >>hsl;
    }
    void xuat()
    {
        cout<<setw(20)<<mnv
            <<setw(20)<<ht
            <<setw(20)<<cv
            <<setw(20)<<hsl;
    }
};
class lanhdao: public nguoild
{
    private:
        int snct;
    public:
        lanhdao(int mnv=0,string ht="",string cv="",int hsl=0,int snct=0):nguoild(mnv,ht,cv,hsl)
        {
            this ->snct=snct;
        }
        ~lanhdao(){}
    friend istream& operator >>(istream& is,lanhdao& ld)
        {
            ld.nhap();
            cout <<"Nhap so nam cong tac: ";
            is >>ld.snct;
            return is;
        }
    int tinh()
        {
            if(cv=="GD")
                return 500;
            if(cv=="TP")
                return 300;
            return 200;
        }
    friend ostream& operator <<(ostream& os,lanhdao ld)
        {
            ld.xuat();
               os<<setw(25)<<ld.snct
                 <<setw(20)<<ld.tinh();
            return os;
        }
};
void tieude()
{
    cout <<setw(20)<<"Ma nhan vien"
         <<setw(20)<<"Ho va Ten"
         <<setw(20)<<"Chuc vu"
         <<setw(20)<<"He so luong";
}
void tieudeld()
{
    tieude();
    cout <<setw(25)<<"So nam cong tac"
         <<setw(20)<<"tien phu cap";
}
int main()
{
    int n;
    cout <<"Nhap so nguoi: ";
    cin >>n;
    nguoild nld[n];
    for (int i=0;i<n;i++)
    {
        cout <<"Nhap so nguoi thu "<<i+1<<endl;
        nld[i].nhap();
    }
    tieude();
    cout <<endl;
    for (int i=0;i<n;i++)
    {
        nld[i].xuat();
    }
    cout <<"\nNhap so nguoi lanh dao: ";
    cin >>n;
    lanhdao ld[n];
    for (int i=0;i<n;i++)
    {
        cout <<"Nhap so nguoi thu "<<i+1<<endl;
        cin >>ld[i];
    }
    tieudeld();
    cout <<endl;
    for (int i=0;i<n;i++)
    {
        cout <<ld[i]<<endl;
    }
}
Editor is loading...