📄 list.cpp
字号:
case 'D':
cout<<"新手机:"; cin>>temp->info.mobile;
break;
case 'e':
case 'E':
cout<<"新生日:"; cin>>temp->info.birthday;
break;
case 'f':
case 'F':
cout<<"新 Q Q:"; cin>>temp->info.qq;
break;
case 'g':
case 'G':
cout<<"新email:"; cin>>temp->info.email;
break;
case 'h':
case 'H':
cout<<"新邮编:"; cin>>temp->info.postalcode;
break;
case 'i':
case 'I':
cout<<"a.家庭住址 b.工作地址";
cin>>get;
if(get=='a' || get=='A')
{
cout<<"新家庭住址:";
cin>>temp->info.homeaddr;
}
if(get=='b' || get=='B')
{
cout<<"新工作住址:";
cin>>temp->info.workaddr;
}
break;
case 'j':
case 'J':
goto label;
break;
}
cout<<"继续修改吗?(Y/N)...";
cin>>get;
if(get=='N' || get=='n') goto label;
}while(/*cout<<"继续修改吗?(Y/N)...",cin>>get,(get=='Y' || get=='y')*/1);//1问题
}//if
else
{
temp=temp->pnext;
}
}
}//while(0!=strcmp(getname,"B") || 0!=strcmp(getname,"b"));
}
bool CAddrList::IsemptyOfFile()
{
bool btemp;
FILE *fp;
char ch;
if((fp=fopen("myaddrlist.txt","r+"))==NULL)
{
fclose(fp);
return false;
}
ch=fgetc(fp);
if(feof(fp)) btemp=true;
else btemp=false;
fclose(fp);
this->m_isempty=btemp;
return btemp;
}
void CAddrList::createchain()
{
Person temp;
FILE *fp;
if((fp=fopen("myaddrlist.txt","r+"))==NULL)
{
cout<<"建立链表时文件打开失败!"<<endl;
return;
}
if(this->m_isempty)
{
cout<<"建立链表的文件为空!任意键返回..."<<endl;
system("pause>nul");
}
chain *end,*p;
for(int i=0;1; i++)
{
fread(&temp,sizeof(Person),1,fp);
if(feof(fp)) break;
p=(chain*)malloc(sizeof(chain));
p->info=temp;
if(0==i)
{
this->head=end=p;
}
else
{
end->pnext=p;
end=p;
}
}
end->pnext=NULL; //为什么有问题
fclose(fp);
if(this->m_ischain == false) m_ischain=true;
}
bool CAddrList::GetStateOfChain()
{
return m_ischain;
}
void CAddrList::save()
{
FILE *fp;
chain *temp;
if(m_ischain)
{
if((fp=fopen("myaddrlist.txt","w+"))==NULL)
{
cout<<"保存文件时打开文件失败!"<<endl;
return;
}
temp=head;
while(1)
{
fwrite(&(temp->info),sizeof(Person),1,fp);
if(temp->pnext == NULL) return;
temp=temp->pnext;
}
}
}
bool CAddrList::GetEmptyOfList()
{
return this->m_isempty;
}
void CAddrList::detail()
{
if(false==m_ischain)
{
cout<<"通讯录为空!任意键返回..."<<endl;
system("pause>nul");
return;
}
chain *temp;
char getname[15];
while(1)
{
temp=this->head;
system("cls");
this->display();
cout<<" 返回主菜单(BACK)"<<endl;
cout<<"想看谁的详情?(输入姓名):";
cin>>getname;
if(strcmp(getname,"back")==0 || strcmp(getname,"back")==0) break;
while(temp!=NULL)
{
if(strcmp(getname,temp->info.name)==0)
{
cout<<endl;
cout<<getname<<"的详细情况:"<<endl;
cout<<"═════════════════════"<<endl;
cout<<"名字: "; cout<<temp->info.name<<endl;
cout<<"性别: "; cout<<temp->info.sex<<endl;
cout<<"手机: "; cout<<temp->info.mobile<<endl;
cout<<"座机: "; cout<<temp->info.telph<<endl;
cout<<"生日: "; cout<<temp->info.birthday<<endl;
cout<<"邮件: "; cout<<temp->info.email<<endl;
cout<<"邮编: "; cout<<temp->info.postalcode<<endl;
cout<<"家庭住址:"; cout<<temp->info.homeaddr<<endl;
cout<<"工作地址:"; cout<<temp->info.workaddr<<endl;
cout<<"Q Q 号码:"; cout<<temp->info.qq<<endl;
cout<<"任意键继续查看..."<<endl;
system("pause>nul");
}
temp=temp->pnext;
}
}
}
void CAddrList::gettell(int i, char *getchs)
{
if(!m_ischain)
{
cout<<"通讯录为空!任意键继续..."<<endl;
return;
}
bool state=false;
chain *temp;
temp=this->head;
switch(i)
{
case 1: //姓名
while(temp!=NULL)
{
if(strcmp(getchs,temp->info.name)==0)
{
if(state==false) state=true;
cout<<temp->info.name<<"的详细情况:"<<endl;
cout<<"═════════════════════"<<endl;
cout<<"名字: \t"; cout<<temp->info.name<<endl;
cout<<"性别: \t"; cout<<temp->info.sex<<endl;
cout<<"手机: \t"; cout<<temp->info.mobile<<endl;
cout<<"座机: \t"; cout<<temp->info.telph<<endl;
cout<<"生日: \t"; cout<<temp->info.birthday<<endl;
cout<<"邮件: \t"; cout<<temp->info.email<<endl;
cout<<"邮编: \t"; cout<<temp->info.postalcode<<endl;
cout<<"家庭住址:\t"; cout<<temp->info.homeaddr<<endl;
cout<<"工作地址:\t"; cout<<temp->info.workaddr<<endl;
cout<<"Q Q 号码:\t"; cout<<temp->info.qq<<endl;
}
temp=temp->pnext;
}
break;
case 2: //性别
while(temp!=NULL)
{
if(strcmp(getchs,temp->info.sex)==0)
{
if(state==false) state=true;
cout<<temp->info.name<<"的详细情况:"<<endl;
cout<<"═════════════════════"<<endl;
cout<<"名字: \t"; cout<<temp->info.name<<endl;
cout<<"性别: \t"; cout<<temp->info.sex<<endl;
cout<<"手机: \t"; cout<<temp->info.mobile<<endl;
cout<<"座机: \t"; cout<<temp->info.telph<<endl;
cout<<"生日: \t"; cout<<temp->info.birthday<<endl;
cout<<"邮件: \t"; cout<<temp->info.email<<endl;
cout<<"邮编: \t"; cout<<temp->info.postalcode<<endl;
cout<<"家庭住址:\t"; cout<<temp->info.homeaddr<<endl;
cout<<"工作地址:\t"; cout<<temp->info.workaddr<<endl;
cout<<"Q Q 号码:\t"; cout<<temp->info.qq<<endl;
}
temp=temp->pnext;
}
break;
case 3: //座机
while(temp!=NULL)
{
if(state==false) state=true;
if(strcmp(getchs,temp->info.telph)==0)
{
cout<<temp->info.name<<"的详细情况:"<<endl;
cout<<"═════════════════════"<<endl;
cout<<"名字: \t"; cout<<temp->info.name<<endl;
cout<<"性别: \t"; cout<<temp->info.sex<<endl;
cout<<"手机: \t"; cout<<temp->info.mobile<<endl;
cout<<"座机: \t"; cout<<temp->info.telph<<endl;
cout<<"生日: \t"; cout<<temp->info.birthday<<endl;
cout<<"邮件: \t"; cout<<temp->info.email<<endl;
cout<<"邮编: \t"; cout<<temp->info.postalcode<<endl;
cout<<"家庭住址: \t"; cout<<temp->info.homeaddr<<endl;
cout<<"工作地址: \t"; cout<<temp->info.workaddr<<endl;
cout<<"Q Q 号码: \t"; cout<<temp->info.qq<<endl;
}
temp=temp->pnext;
}
break;
case 4: //手机
while(temp!=NULL)
{
if(strcmp(getchs,temp->info.mobile)==0)
{
if(state==false) state=true;
cout<<temp->info.name<<"的详细情况:"<<endl;
cout<<"═════════════════════"<<endl;
cout<<"名字: \t"; cout<<temp->info.name<<endl;
cout<<"性别: \t"; cout<<temp->info.sex<<endl;
cout<<"手机: \t"; cout<<temp->info.mobile<<endl;
cout<<"座机: \t"; cout<<temp->info.telph<<endl;
cout<<"生日: \t"; cout<<temp->info.birthday<<endl;
cout<<"邮件: \t"; cout<<temp->info.email<<endl;
cout<<"邮编: \t"; cout<<temp->info.postalcode<<endl;
cout<<"家庭住址:\t"; cout<<temp->info.homeaddr<<endl;
cout<<"工作地址:\t"; cout<<temp->info.workaddr<<endl;
cout<<"Q Q 号码:\t"; cout<<temp->info.qq<<endl;
}
temp=temp->pnext;
}
break;
case 5: //邮编
while(temp!=NULL)
{
if(strcmp(getchs,temp->info.postalcode)==0)
{
if(state==false) state=true;
cout<<temp->info.name<<"的详细情况:"<<endl;
cout<<"═════════════════════"<<endl;
cout<<"名字: \t"; cout<<temp->info.name<<endl;
cout<<"性别: \t"; cout<<temp->info.sex<<endl;
cout<<"手机: \t"; cout<<temp->info.mobile<<endl;
cout<<"座机: \t"; cout<<temp->info.telph<<endl;
cout<<"生日: \t"; cout<<temp->info.birthday<<endl;
cout<<"邮件: \t"; cout<<temp->info.email<<endl;
cout<<"邮编: \t"; cout<<temp->info.postalcode<<endl;
cout<<"家庭住址:\t"; cout<<temp->info.homeaddr<<endl;
cout<<"工作地址:\t"; cout<<temp->info.workaddr<<endl;
cout<<"Q Q 号码:\t"; cout<<temp->info.qq<<endl;
}
temp=temp->pnext;
}
break;
default:
break;
}
if(state==false)
cout<<"没找到匹配的记录!"<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -