64,683
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
#include<stdlib.h>
#include<stdlib.h>
#include<ctype.h>
static int m=0;
class Direct//定义储存成员信息的类
{
private:
string name;
string telephone;
string qq;
string emaile;
string address;
public:
Direct()
{
}
~Direct()
{
}
void set_name(string &s)
{
name=s;
}
string get_name()
{
return name;
}
void set_tel(string &s)
{
telephone=s;
}
string get_tel()
{
return telephone;
}
void set_qq(string &s)
{
qq=s;
}
string get_qq()
{
return qq;
}
void set_add(string &s)
{
address=s;
}
string get_add()
{
return address;
}
void set_emaile(string &s)
{
emaile=s;
}
string get_emaile()
{
return emaile;
}
void show()
{
cout<<"姓名:"<<name<<endl;
cout<<"电话:"<<telephone<<endl;
cout<<"QQ:"<<qq<<endl;
cout<<"住址:"<<address<<endl;
cout<<"电子邮件:"<<emaile<<endl;
}
}Dir[100];
void print()//输出联系人函数
{
string s;
int i=0;
fstream FILE;
FILE.open("mybook.txt",ios_base::in);
cout<<"☆☆☆全部联系人信息☆☆☆"<<endl;
while(getline(FILE,s))
{
cout<<s<<endl;
}
FILE.close();
cout<<"☆☆☆点任意键返回主菜单☆☆☆"<<endl;
system("pause");
system("cls");
}
void add()//添加联系人函数
{
string name,telephone,qq,address,emaile;
int temp=1,i=0;
fstream FILE;
FILE.open("mybook.txt",ios_base::out|ios_base::app);
while(temp)
{
int i=m;
int n=1;
cout<<"☆☆☆添加联系人☆☆☆"<<endl;
cout<<"姓名:";
cin>>name;
Dir[i].set_name(name);
cout<<"电话:";
cin>>telephone;
Dir[i].set_tel(telephone);
cout<<"QQ:";
cin>>qq;
Dir[i].set_qq(qq);
cout<<"住址:";
cin>>address;
Dir[i].set_add(address);
cout<<"电子邮件:";
cin>>emaile;
Dir[i].set_emaile(emaile);
FILE<<Dir[i].get_name()<<endl;
FILE<<"电话:"<<Dir[i].get_tel()<<endl;
FILE<<"QQ:"<<Dir[i].get_qq()<<endl;
FILE<<"地址:"<<Dir[i].get_add()<<endl;
FILE<<"电子邮件:"<<Dir[i].get_emaile()<<endl;
FILE<<endl;
m++;i++;
while(n)
{
cout<<"是否继续添加: 1.是 0.否"<<endl;
cout<<"选择:";
cin>>temp;
if(temp==1||temp==0) n=0;
else
{
cout<<"☆☆☆错误:请输入0或1!☆☆☆"<<endl;
cout<<" ☆☆☆请重新输入:☆☆☆"<<endl;
}
}
system("cls");
}
FILE.close();
}
//将忽略字符串前后的换行字符和空格
void mySpecicalStrcpy(char* arr, string str)
{
char* chArr = new char[str.length()];
strcpy(chArr, str.c_str());
while( *chArr != '\0' )
{
if( *chArr == ' ' || *chArr == '\n' )
{
++chArr;
continue;
}
*arr++ = *chArr++;
}
*arr='\0';
}
void seek()//查找联系人函数
{
string sname,s;
fstream FILE;
FILE.open("mybook.txt",ios_base::in);
FILE.seekg(0,ios::beg);
cout<<"☆☆☆查找联系人☆☆☆"<<endl;
cout<<"输入要查找联系人的姓名,以#号键结束:";
getline(cin,sname,'#');
/*
const char *arr = sname.c_str();
for(int i=0; i<sname.length(); ++i)
{
cout << "arr["<<i<<"]="<<"'"; //这里第一个字符会输出换行符
cout << arr[i]<<"'"<<endl;
}
*/
char *snameArr=new char[sname.length()];
mySpecicalStrcpy(snameArr, sname);
while(!getline(FILE,s).eof())
{
if( strcmp(snameArr, s.c_str()) == 0)
{
cout<<"找到了,信息如下:"<<endl;
cout<<s<<endl;
for(int i=1; i<=4; ++i)
{
getline(FILE,s);
cout<<s<<endl;
}
break;
}
}
FILE.close();
}
void change()
{}
void delet()
{}
void save()
{}
void main()
{
system("color 3F");//改变背景和字体颜色
cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆";//选择前界面
cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆";
cout<<" ┬┴┬┌─ ●─┬─ │─┼─┐ ●├─┤○"<<endl;
cout<<" ┴┬┴├┬ ┌─┼─ │◎ │ │ ○└┬┘●"<<endl;
cout<<" ─┼─││ │ │ ││─┴─┴ ──┼──"<<endl;
cout<<" ●│○││ ┴─┼─ │○ ● / │ \"<<endl;
cout<<endl<<endl;
cout<<" ▇▇▇▇▇ ▇▇▇▇▇ ▇▇▇▇▇ ▇▇▇▇▇ "<<endl;
cout<<" ◢▇▇▇▇▇◣ ◢▇▇▇▇▇◣ ◢▇▇▇▇▇◣ ◢▇▇▇▇▇◣"<<endl;
cout<<" ▇ 欢 ▇ ▇ 迎 ▇ ▇ 使 ▇ ▇ 用 ▇"<<endl;
cout<<" ◥▇▇▇▇▇◤ ◥▇▇▇▇▇◤ ◥▇▇▇▇▇◤ ◥▇▇▇▇▇◤"<<endl;
cout<<" ▇▇▇▇▇ ▇▇▇▇▇ ▇▇▇▇▇ ▇▇▇▇▇ "<<endl;
cout<<" | | | | | | | | | | | | | | "<<endl;
cout<<endl;
cout<<" 通讯录管理系统"<<endl;
cout<<endl<<endl;
cout<<" 姓名: 史环宇"<<endl;
cout<<" 班级: 软件09-2"<<endl;
cout<<" 学号: 200920205059"<<endl;
cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆";
cout<<endl;
system("pause");
system("cls");
int select=1;
while(select)
{
cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆";
cout<<endl;
cout<<" 1.输出联系人 2.添加联系人"<<endl;
cout<<" 3.查找联系人 4.修改联系人"<<endl;
cout<<" 5.删除联系人 6.保存到文件 0.退出"<<endl;
cout<<endl;
cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆";
cout<<"请选择:";
cin>>select;
switch(select)
{
case 1: system("cls");print();break;
case 2: system("cls");add();break;
case 3: system("cls");seek();break;
case 4: system("cls");change();break;
case 5: system("cls");delet();break;
case 6: system("cls");save();break;
case 0: break;
}
if(!(select==0||select==1||select==2||select==3||select==4||select==5||select==6))
{
system("cls");
cout<<"输入错误,请输入0~6的整数!"<<endl;
}
if(select==0)
cout<<"感谢您的使用!"<<endl;
}
}