通讯录系统

通讯录系统

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
struct Xx
{
    string name;
    string tel;
    Xx(string nname,string ttel):name(nname),tel(ttel){}
    Xx(){};
    string getname()
    {
        return name;
    }
    string gettel()
    {
        return tel;
    }
};
istream &operator >> (istream &is,Xx &a)
{
    is>>a.name>>a.tel;
    return is;
}
ostream &operator << (ostream &os,vector<Xx>::iterator it)
{
    os<<it->name<<" "<<it->tel<<endl;
    return os;
}
class Phone
{
private:
    Xx x;
    map<string,int>lxr1;
    map<string,int>lxr2;
    vector<Xx>lxr;
    map<string,int>::iterator it1;
    map<string,int>::iterator it2;
    vector<Xx>::iterator it;
public:
    void down()
    {
         int i=0;
        ifstream infile("qf.txt",ios::in);
        while(!infile.eof())
        {

            infile>>x;
			if((x.tel).size()==11)
            {
                lxr.push_back(x);
                lxr1.insert(make_pair(x.name,i));
                lxr2.insert(make_pair(x.tel,i));
                i=i+1;
            }
        }
        infile.close();
       while(cin >> x)
        {
           if(x.name!="0"&&x.tel!="0")
           {
               if((x.tel).size()==11)
               {
                   //Xx x(nn,tt);
                   lxr.push_back(x);
                   lxr1.insert(make_pair(x.name,i));
                   lxr2.insert(make_pair(x.tel,i));
                   i=i+1;
                }
                else cout<<"Error tel"<<endl;
           }
           else break;
        }
    }
    void shann()
    {
        cin>>x.name;
        it1=lxr1.find(x.name);
        if(it1!=lxr1.end())
        {
            it=lxr.begin()+it1->second;
            lxr.erase(it);
        }
        else cout<<"No name!"<<endl;
    }
    void shant()
    {
        cin>>x.tel;
        it2=lxr2.find(x.tel);
        if(it2!=lxr2.end())
        {it=lxr.begin()+it2->second;
        lxr.erase(it);}
        else cout<<"No tel!"<<endl;
    }
    void chan()
    {
        cin>>x.name;
        it1=lxr1.find(x.name);
        if(it1!=lxr1.end())
        {
            it=lxr.begin()+it1->second;
            cout<<it;
        }
        else cout<<"No name!"<<endl;
    }
    void chat()
    {
        cin>>x.tel;
        it2=lxr2.find(x.tel);
        if(it2!=lxr2.end())
        {
            it=lxr.begin()+it2->second;
            cout<<it;
        }
        else cout<<"No tel!"<<endl;
    }
    void gain()
    {
        string nn;
        string tt;
        cin>>nn>>tt;
        if((tt).size()==11)
        {
            it2=lxr2.find(tt);
            if(it2!=lxr2.end())
            {
                it=lxr.begin()+it2->second;
                it->name=nn;
            }
            else cout<<"No tel!"<<endl;
        }
        else cout<<"Error tel!"<<endl;
    }
    void gait()
    {
        string nn;
        string tt;
        cin>>nn>>tt;
        if((tt).size()==11)
        {
            it1=lxr1.find(nn);
            if(it1!=lxr1.end())
            {
                it=lxr.begin()+it1->second;
                it->tel=tt;
            }
            else cout<<"No name!"<<endl;
        }
        else cout<<"Error tel!"<<endl;
    }
    void all()
    {
         for(it=lxr.begin();it!=lxr.end();it++)
        {

            cout<<it;
        }
    }
    void save()
    {
        ofstream outfile("fq.txt");
        for(it=lxr.begin();it!=lxr.end();it++)
        {

            outfile<<it;
        }
    }

};
int main()
{
    Phone p;
    p.down();
    p.shann();
    p.shant();
    p.chan();
    p.chat();
    p.gain();
    p.gait();
    p.save();
    //p.all();
}

上一篇:Mui-页面跳转传递参数


下一篇:Mui-页面跳转