某天下午闲的蛋疼随手写的一个,后来就重构了……

参考一下还是可以的,过几天放完整的。

现在用的vector……可能会改链表,或者改vector的find类库吧

#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<iomanip>
using namespace std;

class Adress{
private:
	unsigned long long int telphone;
	string name;
public:
	static int cont;
	Adress();
	~Adress();
	Adress(const Adress & p);
	string show_name(){return name;}
	long long show_tel(){return telphone;}

	friend void del_adress(Adress &);
	friend void import(Adress &,ifstream &);
	friend void outport(Adress &,ofstream &);

	friend istream & operator >>(istream&input,Adress &);
	friend ostream & operator <<(ostream&putput,Adress&);
};
void del_adress(Adress & temp){
	temp.telphone=0;
	temp.name="0";
}
void import(Adress & temp,ifstream &infile){
	infile>>temp.name;
	infile>>temp.telphone;
}
void outport(Adress & temp,ofstream & outfile){
	outfile<<temp.name<<" "<<temp.telphone;
	outfile<<"\n";
}
istream & operator >>(istream&input,Adress&A){
	input>>A.name>>A.telphone;
	return input;
}
ostream & operator <<(ostream&output,Adress&A){
	output<<A.name<<" "<<A.telphone;
	return output;
}
Adress::Adress(const Adress & p){
	this->name=p.name;
	this->telphone=p.telphone;
}
Adress::Adress(){
	telphone=0;
	name="0";
}
Adress::~Adress(){}
int Adress::cont=0;
void write_function(){
	vector<Adress> vec;
	Adress newone;
	ifstream infile("tongxunlu.txt");
	if(infile==0){
	    cout<<"ERROR"<<endl;
		return;
	}
	while(!infile.eof()){
		import(newone,infile);
		vec.push_back(newone);
	}
	infile.close();

	ofstream outfile("tongxunlu.txt",ios::app);
	if(outfile==0){
	    cout<<"ERROR"<<endl;
		return;
	}
	cout<<"name number(空请输入0)"<<endl;
	cin>>newone;
	unsigned int i;
	for(i=0;i<vec.size();i++){
		if(newone.show_tel()==vec.at(i).show_tel()){
			break;
		}
	}
	if(i==vec.size()||vec.size()==0){
	    outport(newone,outfile);
		cout<<"successfully"<<endl;
		return ;
	}
	else{
	    cout<<"already exist"<<endl;
		cout<<vec.at(i)<<endl;
		system("pause");
		return ;
	}
	outfile.close();
}
#include"adress.h"
#include"funcation.h"

int main(){
	int a;
	while(1){
	    cin>>a;
		switch (a)
		{
		case 1:
			write_function();
			break;
		case 2:
			delete_function();
			break;
		case 0:
			return 0;
		//case 11:
		//	demo();
			break;
		default:
			break;
		}
	}
	return 0;
}

 

2 Replies to “通讯录v1.0”

  1. Android Webkit 4.0 Android Webkit 4.0 Android 8.0.0 Android 8.0.0
    Mozilla/5.0 (Linux; Android 8.0.0; MHA-AL00 Build/HUAWEIMHA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36

    大佬,膜

  2. Google Chrome 63.0.3239.132 Google Chrome 63.0.3239.132 Windows 10 x64 Edition Windows 10 x64 Edition
    Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36

    %

发表评论

电子邮件地址不会被公开。 必填项已用*标注