}
change_num++;
Color(10);
}
////////Address_Book。
H
#ifndefADDRESS_BOOK_H
#defineADDRESS_BOOK_H
classAddress_Book
{
public:
Address_Book();
Address_Book(char*,char*);
~Address_Book();
voidOutputList();
voidAdd(char[20],char[13],int);
voidDelete(char[20]);
voidShow1();
voidShow2();
intCompare(char[20],int);
intCompare2(char[12],int);
intget_num();
private:
charname[20];
charnumber[12];
intnum;
};
#endif
////////////Address_Book.cpp
#include
#include"Address_Book.h"
#include
Address_Book:
:
Address_Book()
{
}
Address_Book:
:
Address_Book(char*a,char*b)
{
strcpy(name,a);
strcpy(number,b);
}
Address_Book:
:
~Address_Book()
{
}
voidAddress_Book:
:
Add(chara[20],charb[13],intc)
{
inti=0;
for(i=0;i<20;i++)
{
name[i]=a[i];
}
for(i=0;i<13;i++)
{
number[i]=b[i];
}
num=c;
}
voidAddress_Book:
:
Delete(chara[20])
{
if(strcmp(name,a)==0)
{
num=0;
}
}
voidAddress_Book:
:
Show1()
{
cout<}
voidAddress_Book:
:
Show2()
{
cout<}
intAddress_Book:
:
Compare(chara[20],intb)
{
if(strncmp(name,a,b)==0)
{
return1;
}
if(strncmp(name,a,b)<0)
{
return0;
}
if(strncmp(name,a,num)>0)
{
return2;
}
return3;
}
intAddress_Book:
:
Compare2(chara[12],intb)
{
intj=0;
for(inti=0;i
{
if(number[i]==a[i])
{
j++;
}
}
if(j==b)
{
return1;
}
return0;
}
intAddress_Book:
:
get_num()
{
returnnum;
}
//////main()
#include
#include
#include
#include"Address_Book.h"
#include"Text.h"
#include
#include
structnode
{
Address_BookA;
node*next;
};
voidWhere(int,int);
node*CreatList(int&);
voidoutputList(node*,int);
intmain()
{
charnum_choose;
intnum_read=-1;//用于记录链表中元素的个数
node*ListHead=NULL,*temp=NULL;
ListHead=CreatList(num_read);
outputList(ListHead,num_read);
Texttext;
text.CreatText(num_read);
Where(12,14);
num_choose=getche();
do
{
//删除一个名单
if(num_choose=='1')
{
inti,j;
temp=ListHead;
charnum2[20];
Where(2,16);
cout<<"输入所要删除人的名字,按'#'返回菜单;"<Where(2,18);
cout<<"按'@'删除前一个字母,按'!
'键结束输入"<for(i=0;i<100;i++)
{
Where(2+i,20);
num2[i]=getche();
num2[i+1]=0;
Where(2+i,20);
cout<<""<if(num2[i]=='#')
{
gotoend2;
}
if(num2[i]=='!
')
{
num2[i]=0;
Where(2+i,20);
cout<<""<break;
}
if(num2[i]=='@')
{
num2[i-1]=0;
i=i-2;
Where(2+i,20);
cout<<""<}
for(j=0;j<20;j++)
{
if(num2[j]!
=0)
{
Where(2+j,20);
cout<}
if(num2[j]==0)
{
num2[j+1]=0;
break;
}
}
}
while(temp)
{
temp->A.Delete(num2);
temp=temp->next;
}
ofstreamoutFile("Address_List.dat",ios:
:
out|ios:
:
binary);
while(ListHead)
{
if(ListHead->A.get_num()!
=0)
{
outFile.write((char*)&(ListHead->A),sizeof(ListHead->A));
}
ListHead=ListHead->next;
}
outFile.close();
}
///增加一个名单
if(num_choose=='2')
{
inti,j,k=0;
temp=NULL;
charnum3[20],num4[13];
intnum5=0;
Where(2,16);
cout<<"输入所要添加人的名字,按'#'返回菜单;"<Where(2,18);
cout<<"按'@'删除前一个字母,按'!
'键结束输入"<for(i=0;i<100;i++)
{
Where(2+i,20);
num3[i]=getche();
num3[i+1]=0;
Where(2+i,20);
cout<<""<if(num3[i]=='#')
{
num3[i]=0;
num3[i+1]=0;
gotoend1;
}
if(num3[i]=='!
')
{
num3[i]=0;
Where(2+i,20);
cout<<""<break;
}
if(num3[i]=='@')
{
num3[i-1]=0;
i=i-2;
Where(2+i,20);
cout<<""<}
for(j=0;j<20;j++)
{
if(num3[j]!
=0)
{
Where(2+j,20);
cout<}
if(num3[j]==0)
{
num3[j+1]=0;
break;
}
}
}
Where(2,22);
cout<<"输入所要添加人的号码,按'#'返回菜单;"<Where(2,24);
cout<<"按'@'删除前一个字母,按'!
'键结束输入"<for(i=0;i<100;i++)
{
Where(2+i,26);
num4[i]=getche();
num4[i+1]=0;
if(num4[i]=='#')
{
gotoend1;
}
if(num4[i]=='!
')
{
num4[i]=0;
Where(2+i,26);
cout<<""<break;
}
if(num4[i]=='@')
{
num4[i-1]=0;
Where(2+i,26);
cout<<""<i=i-2;
}
for(j=0;j<11;j++)
{
if(num4[j]!
=0)
{
Where(2+j,26);
cout<}
if(num4[j]==0)
{
num4[j+1]=0;
break;
}
}
}
for(i=0;i<20;i++)
{
if((num3[i]>='A')&&(num3[i]<='z'))
{
num5++;
}
}
node*B1;
B1=newnode;
B1->A.Add(num3,num4,num5);
B1->next=NULL;
temp=ListHead;
node*tith;
while(temp)
{
k++;
tith=temp->next;
if((temp->A.Compare(num3,num5)==0)&&((tith->A.Compare(num3,num5)==2))&&(tith!
=NULL))
{
temp->next=B1;
B1->next=tith;
gotoend1;
}
if((temp->A.Compare(num3,num5)==1)&&k==1)
{
B1->next=temp;
ListHead=B1;
gotoend1;
}
if((tith->A.Compare(num3,num5)==1)&&(k!
=1))
{
temp->next=B1;
B1->next=tith;
gotoend1;
}
if((temp->A.Compare(num3,num5)==0)&&(tith==NULL))
{
tith->next=B1;
gotoend1;
}
/*if((temp->A.Compare(num3,num5)==2)&&(tith!
=NULL))
{
B1->next=temp;
ListHead=B1;
gotoend1;
}*/
temp=temp->next;
}
end1:
cout<ofstreamoutFile("Address_List.dat",ios:
:
out|ios:
:
binary);
while(ListHead)
{
if(ListHead->A.get_num())
{
outFile.write((char*)&(ListHead->A),sizeof(ListHead->A));
}
ListHead=ListHead->next;
}
outFile.close();
}
if(num_choose=='4')
{
gotoend3;
}
//////查找名单
if(num_choose=='3')
{
Where(2,16);
cout<<"①按名字查找,②按号码查找"<Where(2,18);
num_choose=getche();
Where(2,18);
cout<<""<if(num_choose=='1')
{
charnum6[20],num8;
intnum9=6;
num8='~';
intnum7=0;
for(inti=0;i<100;i++)
{
temp=ListHead;
if(num8=='#')
{
gotoend2;
}
if(num8=='@')
{
num7--;
num6[num7]=0;
}
if((num8>='A')&&(num8<='z'))
{
num6[num7]=num8;
num7++;
}
Where(2,16);
cout<<"输入索要查找到名字,按'#'键结束返回菜单"<Where(7,18);
cout<<"按'@'键删除"<for(intj=0;j{
Where(j+1,20);
cout<}
while(temp)
{
if(temp->A.Compare(num6,num7)==1)
{
Where(24,num9);
temp->A.Show1();
Where(46,num9);
temp->A.Show2();
}
temp=temp->next;
num9=num9+2;
}
Where(2+num7,20);
num8=getche();
num9=6;
system("cls");
text.CreatText(num_read);
}
}
if(num_choose=='2')
{
charnum6[12],num8;
intnum9=6;
num8='~';
intnum7=0;
for(inti=0;i<100;i++)
{
temp=ListHead;
if(num8=='#')
{
gotoend2;
}
if(num8=='@')
{
num7--;
num6[num7]=0;
}
if((num8>='0')&&(num8<='9'))
{
num6[num7]=num8;
num7++;
}
Where(2,16);
cout<<"输入索要查找的号码,按'#'键结束返回菜单"<Where(7,18);
cout<<"按'@'键删除"<for(intj=0;j{
Where(j+1,20);
cout<}
while(temp)
{
if(temp->A.Compare2(num6,num7)==1)
{
Where(24,num9);
temp->A.Show1();
Where(46,num9);
temp->A.Show2();
}
temp=temp->next;
num9=num9+2;
}
Where(2+num7,20);
num8=getche();
num9=6;
system("cls");
text.CreatText(num_read);
}
}
}
end2:
system("cls");
num_read=-1;
ListHead=CreatList(num_read);
outputList(ListHead,num_read);
text.CreatText(num_read);
Where(12,14);
num_choose=getche();
}
while((num_choose>='1')&&(num_choose<='4'));
end3:
Where(2,16);
return0;
}
///////////////////////从文件中读取链表
node*CreatList(int&num_read)
{
node*temp=NULL,*t