• 备忘录模式(C++)


    #include <iostream>
    #include <string>
    #include <vector>
    #include <iomanip>
    using namespace std;
    
    class info
    {
    public:
        info():pc(0){}
        ~info(){}
        void input(string name,int age,int salary)
        {
            _name.push_back(name);
            _age.push_back(age);
            _salary.push_back(salary);
            pc++;
        }
    
        void show()
        {
            for (int i=0;i<pc;i++)
            {
                cout<<"name  :"<<_name[i]<<setw(10);
                cout<<"age   :"<<_age[i]<<setw(10);
                cout<<"salary:"<<_salary[i]<<endl;
            }
        }
    
        info* operator=(info* p)
        {
            info* temp;
            temp->_name=p->_name;
            temp->_age=p->_age;
            temp->_salary=p->_salary;
            temp->pc=p->pc;
            return temp;
        }
    
    private:
        int pc;
        vector<string> _name;
        vector<int> _age;
        vector<int> _salary;
    
    };
    
    class Memorandum
    {
    public:
        Memorandum(){}
        ~Memorandum(){}
    
        void Save(info p)
        {
            _wh.push_back(p);
        }
    
        info Load()
        {
            vector<info>::reverse_iterator rit;
            rit=_wh.rbegin();
            return *rit;
        }
    
    private:
        vector<info> _wh;
    };
    
    int main()
    {
        Memorandum *p_wh=new Memorandum;
        info p_info;
        p_info.input("zhangsan",20,4000);
        p_wh->Save(p_info);
        p_info.show();
        cout<<endl;
    
        p_info.input("lisi",22,5000);
        p_info.input("wangwu",23,6000);
        p_info.show();
    
        cout<<endl;
        p_info=p_wh->Load();
        p_info.show();
    
        delete p_wh;
        system("pause");
        return 0;
    }
  • 相关阅读:
    将Excel文件.xls导入SQL Server 2005
    linux mount命令
    python write file
    vim visual模式 复制
    chef简介
    录音整理文字工具otranscribe简介
    ftp put get 的使用方法
    yum lock 解决方法
    phalcon builder get raw sql
    centos7安装VirtualBox
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2568698.html
Copyright © 2020-2023  润新知