• 十周 工程2 员工有自己的工资 扩张


    #include <iostream>
    #include <cstring>
    using namespace std;
    class CPerson
    {
    protected:
    	char *m_szName;
    	char *m_szId;
    	int m_nSex;//0:women,1:man
    	int m_nAge;
    public:
    	CPerson(char *name,char *id,int sex,int age);
    	void Show1();
    	~CPerson();
    };
    
    CPerson::CPerson(char *name,char *id,int sex,int age)
    {
        m_szName=new char[strlen(name)+1];
        m_szId=new char[strlen(id)+1];
        m_szName=name;//以为有了m_szName=new char[strlen(name)+1]这句 就不用写 m_szName=name呢 看来我错了
        m_szId=id;
        m_nSex=sex;
        m_nAge=age;
    }
    CPerson::~CPerson()
    {
        delete []m_szName;
        delete []m_szId;
    }
    class CEmployee:public CPerson
    {
    private:
    	char *m_szDepartment;
    	float m_Salary;
    public:
    	CEmployee(char *name,char *id,int sex,int age,char *department,float salary);
    	void Show2();
    	~CEmployee();
    };
    
    CEmployee::CEmployee(char *name,char *id,int sex,int age,char *department,float salary):CPerson(name,id,sex,age)
    {
        m_szDepartment=new char[strlen(department)+1];
        m_szDepartment=department;
        m_Salary=salary;
    }
    CEmployee::~CEmployee()
    {
        delete []m_szDepartment;
    }
    void CEmployee::Show2()
    {
        cout<<"姓名:    "<<m_szName<<endl;
        cout<<"身份证号:"<<m_szId<<endl;
        cout<<"性别:    "<<m_nSex<<endl;
        cout<<"年龄:    "<<m_nAge<<endl;
        cout<<"部门:    "<<m_szDepartment<<endl;
        cout<<"月薪:    "<<m_Salary<<endl;
    }
    int main()
    {
    	char name[10],id[19],department[10];
    	int sex,age;
    	float salary;
    	cout<<"input employee's name,id,sex(0:women,1:man),age,department,salary:
    ";
    	cin>>name>>id>>sex>>age>>department>>salary;
    	CEmployee employee1(name,id,sex,age,department,salary);
    	employee1.Show2();
    	return 0;
    }
    

    感悟:对深复制还是不多熟悉,会老是出错!但是,这一点还是很疯狂的编程啊。

    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    Delphi通过调用COM对象实现更改桌面壁纸
    Delphi之TDrawGrid绘制
    Delphi中的消息截获(六种方法:Hook,SubClass,Override WndProc,Message Handler,RTTI,Form1.WindowProc:=@myfun)good
    从一般管理原则看微软的重组
    Delphi使用Windows API函数AnimateWindow实现窗体特效
    Delphi下URL汉字编码解码的两个函数
    Delphi2007下CIS的clHttp使用
    Delphi使用XmlHttp获取时间
    提升进程权限为DEBUG权限
    VS 2012 单元测试简单配置
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4750108.html
Copyright © 2020-2023  润新知