5月15日学习总结

这两天学习有点乱,找不到重心。下面就分享下通讯录更新后的版本吧!

#include<bits/stdc++.h>
using namespace std;
class Phone
{
    string name,tel;
    public:
    Phone()
    {
        name="li";
        tel="123456789";
    }
    Phone(string na,string te):name(na),tel(te){}
    string getname(){return name;}
    string gettel(){return tel;}
    void xiugai(string a,string b)
    {
        name=a;
        tel=b;
    }
    void pri()
    {
        cout<<name<<" "<<tel<<endl;
    }
};
class Setphone
{
    vector<Phone>all;
    multimap<string,string>find1;
    public:
    void addphone();
    void fixphone();
    void cutphone();
    void readphone();
    void writephone();
    void chaname();
};
void Setphone::addphone()
{
    string na,te;
    cin>>na>>te;
    find1.insert(make_pair(na,te));
}
void Setphone::chaname()
{
    multimap<string,string>::iterator it2;
    string na;
    cin>>na;
    for(it2=find1.lower_bound(na);it2!=find1.upper_bound(na);it2++)
    {
        cout<<it2->first<<" "<<it2->second<<endl;
    }
}
void Setphone::cutphone()
{
    multimap<string,string>::iterator it2;
    string na;
    cin>>na;
    it2=find1.find(na);
    if(it2!=find1.end())
    find1.erase(na);
}
void Setphone::fixphone()
{
    multimap<string,string>::iterator it2;
    string na,newphone1;
    cin>>na>>newphone1;
    it2=find1.find(na);
    if(it2!=find1.end())
    it2->second=newphone1;
}
void Setphone::readphone()
{
    ifstream in;
    in.open("C:\\GameDownload\\student.txt");
    while(!in.eof())
    {
        string one;
        string nams,tels;
        getline(in,one);
        if(one.empty())
        continue;
        istringstream is(one);
        is>>nams;
        is>>tels;
        find1.insert(make_pair(nams,tels));
    }
    in.close();
}
void Setphone::writephone()
{
    ofstream out;
    out.open("C:\\GameDownload\\student.txt");
    all.clear();
    for(auto it1=find1.begin();it1!=find1.end();it1++)
    {
        Phone me;
        me.xiugai(it1->first,it1->second);
        all.push_back(me);
    }
    for(auto it1=all.begin();it1!=all.end();it1++)
    {
        out<<(*it1).getname()<<"\t"<<(*it1).gettel()<<endl;
    }
    out.close();
}
int main()
{
    int n;
    Setphone cao;
    cao.readphone();
    cin>>n;
    while(n--)
    {
        cao.addphone();
    }
    cao.chaname();
    cao.cutphone();
    cao.chaname();
    cao.fixphone();
    cao.chaname();
    cao.writephone();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值