附录
程序的源代码清单:
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<fstream>
#include<algorithm>
#define SPACE "\t\t\t"
using namespace std;
struct Record{
string name;
string tel;
public:
friend ostream& operator<<(ostream& os,const Record *rec){
return os<<rec->name<<SPACE<<rec->tel<<endl;
};
friend istream& operator>>(istream& is,Record *rec){
is>>rec->name;
is>>rec->tel;
return is;
}
static bool comp(string patten,int type,Record *rec){
switch(type){
case 0: {return rec->name==patten;}break;
case 1: {return rec->tel==patten;}break;
}
return false;
}
static bool isvan(Record *rec){
return (rec->name==""&&rec->tel=="");
}
};
class RecordList:public list<Record*>
{
public:
friend ostream& operator<<(ostream& os,const RecordList &c_rl){
RecordList::const_iterator it=c_rl.begin();
while(it!=c_rl.end()){
os<<*it;
it++;
}
return os;
}
friend istream& operator>>(istream& is,RecordList &rl){
RecordList::const_iterator it;
while(!is.eof()){
Record *prec=new Record;
is>>prec;
if(Record::isvan(prec)) continue;
rl.list<Record*>::push_back(prec);
}
return is;
}
void clear();
iterator erase(iterator pos);
~RecordList(){
this->clear();
}
};
void RecordList::clear(){
RecordList::const_iterator it=this->begin();
while(it!=this->end()){
delete(*it);
it++;
}
this->list<Record*>::clear();
}
RecordList::iterator RecordList::erase(iterator pos){
delete(*pos);
return list<Record*>::erase(pos);
}
class AddressList{
protected:
RecordList recList;
public:
typedef RecordList::iterator Iterator;
//从通信录中寻找一个记录
virtual Iterator findRecord(string patten,int type,Iterator from);
virtual void addRecord(Record* rec);
virtual void removeRecord(Iterator it);
virtual void editRecord(Record* rec,Iterator it);
virtual void saveRecords(ostream& os);
上一页 [1] [2] [3] [4] [5] [6] [7] 下一页