#include <iostream>
#include <string>
#include <algorithm>//??????
#include <vector>
#include "FunctionClass.h"
using namespace std;
vector<TXL>ss;//TXL:结构
//void FunctionClass::mainframe();
//void FunctionClass::print(TXL *temp);
void FunctionClass::addition()
{
TXL temp;
char ch='Y';
while(toupper(ch)=='Y')
{
cout<<"姓名:";
cin>>temp.NAME;
cout<<"性别:";
cin>>temp.GENDER;
cout<<"电话:";
cin>>temp.TEL;
cout<<"地址:";
cin>>temp.CITY;
cout<<"邮编:";
cin>>temp.EIP;
ss.push_back(temp);
cout<<"是否要继续添加联系人?Y|N:";
cin>>ch;
}
mainframe();
}
void FunctionClass::dele()
{
if(!ss.size())
{
cout<<"通讯录中没有联系人!请进行其他操作……"<<endl;
mainframe();
}
cout<<"请输入你要删除联系人的 1.姓名 2.删除全部联系人:";
char ch;
int i=0;
cin>>ch;
switch(ch)
{
case '1':
{
cout<<"请输入姓名:";
char name[8];
cin>>name;
for(i=0;i<ss.size();i++)
{
if(strcmp(ss[i].NAME,name))//strcmp(const string *str1,const string *str2)比较字符串str1和str2
ss.erase(ss.begin()+i);//erase(interator loc)||erase(interator start,interator end)删除loc位置的元素或者删除从start开始到end的元素
return;
}
cout<<"查无此人!"<<endl;
mainframe();
}
break;
case '2':
{
ss.erase(ss.begin(),ss.end());
}
break;
default:
{
cout<<"输入错误!";
}
}
}
void FunctionClass::found()
{
char name_temp[8];
cout<<"输入要查找的联系人的姓名:";
cin>>name_temp;
char ch='Y';
while(toupper(ch)=='Y')
{
for(int i=0;i<ss.size();i++)
{
if(strcmp(name_temp,ss[i].NAME)==0)
{
print(&ss[i]);
cout<<"是否继续查找?Y/N:";
cin>>ch;
if(toupper(ch)=='Y')
{
cout<<"输入要查找的联系人的姓名:";
cin>>name_temp;
}
}
//return;
}
}
//cout<<"查无此人!"<<endl;
//pause();
mainframe();
}
void FunctionClass::modify()
{
if(!ss.size())
{
cout<<"通讯录中没有联系人!请进行其他操作……"<<endl;
mainframe();
}
cout<<"1.姓名 2.电话"<<endl;
cout<<"请输入你要查找的方式:";
char ch;
cin>>ch;
switch(ch)
{
case '1':
{
cout<<"请输入你要编辑人的姓名:";
char name_temp[8];
cin>>name_temp;
for(int i=0;i<ss.size();i++)
{
if(!strcmp(name_temp,ss[i].NAME))
{
cout<<"你要修改的是:1.性别 2.电话 3.地址 4.邮编:";
char choice_num;
cin>>choice_num;
switch(choice_num)
{
case '1':
{
cout<<"请输入新的性别:";
char sex;
cin>>sex;
ss[i].GENDER=sex;
}
break;
case '2':
{
cout<<"请输入新的电话:";
char tel[7];
cin>>tel;
strcpy(ss[i].TEL,tel);//strcpy(char *to,const cha *from)复制字符串from中的字符到字符串to中
}
break;
case '3':
{
cout<<"请输入新的地址:";
char city[30];
cin>>city;
strcpy(ss[i].CITY,city);
}
break;
case '4':
{
cout<<"请输入新的邮编:";
char eip[7];
cin>>eip;
strcpy(ss[i].EIP,eip);
}
break;
default:
{
cout<<"输入错误!";
continue;
}
}//endswitch
}//endif
else
cout<<"查无此人!";
}//endfor
}//endcase
break;
case '2':
{
cout<<"请输入你要编辑人的电话:";
char TEL_temp[7];
cin>>TEL_temp;
for(int i=0;i<ss.size();i++)
{
if(!strcmp(TEL_temp,ss[i].TEL))
{
cout<<"你要修改的是:1.姓名 2.性别 3.地址 4.邮编:";
char choice_num;
cin>>choice_num;
switch(choice_num)
{
case '1':
{
cout<<"请输入新的性别:";
char sex;
cin>>sex;
ss[i].GENDER=sex;
}
break;
case '2':
{
cout<<"请输入新的电话:";
char tel[7];
cin>>tel;
strcpy(ss[i].TEL,tel);
}
break;
case '3':
{
cout<<"请输入新的地址:";
char city[30];
cin>>city;
strcpy(ss[i].CITY,city);
}
break;
case '4':
{
cout<<"请输入新的邮编:";
char eip[7];
cin>>eip;
strcpy(ss[i].EIP,eip);
}
break;
default:
{
cout<<"输入错误!";
continue;
}
}//endswitch
}//endif
}//endfor
}//endcase
break;
}//endswitch
}//endmodify
void FunctionClass::listall()
{
if(ss.empty())
{
cout<<"没有联系人!"<<endl;
mainframe();
}
int num=1;
for(int i=0;i<ss.size();i++)
{
cout<<"第"<<num<<"个联系人:"<<endl;
print(&ss[i]);
num++;
}
num=ss.size();
cout<<"总共有"<<num<<"个联系人。"<<endl;
mainframe();
}
void FunctionClass::print(TXL *temp)
{
cout<<"姓名:"<<(*temp).NAME<<endl;
if((*temp).GENDER==1)//1男
cout<<"性别:"<<"男"<<endl;
else
cout<<"性别:"<<"女"<<endl;
cout<<"电话:"<<(*temp).TEL<<endl;
cout<<"城市:"<<(*temp).CITY<<endl;
cout<<"邮编:"<<(*temp).EIP<<endl;
return ;
}
void FunctionClass::NewTXL()
{
int num=ss.size();
if(num!=0)
{
cout<<"通讯录不为空! 不可以再创建新通讯录"<<endl;
mainframe();
}
addition();
}
void FunctionClass::mainframe()
{
int c=0;
back:
cout<<"---------------------主菜单---------------------"<<endl;
cout<<"1.浏览全部联系人 2.创建新通讯录\n";
cout<<"3.添加新联系人 4.查找联系人\n";
cout<<"5.修改联系人信息 6.删除联系人\n";
cout<<"7.菜单 8.退出\n";
cout<<"请选择:";
cin>>c;
switch(c)
{
case 1:
listall();
break;
case 2:
NewTXL();
break;
case 3:
addition();
break;
case 4:
found();
break;
case 5:
modify();
break;
case 6:
dele();
break;
case 7:
//goto back;
mainframe();
break;
case 8:
return;
break;
default:
cout<<"输入错误!";
break;
}
}
提示 unexpect end 我看了,花括号都匹配呀,求大神指点,谢谢!头文件"FunctionClass.h"已经定义了
少了#include "stdafx.h"
少了#include "stdafx.h"