主题:大一学生,考试在即跪求C++编写电子通讯录程序
最西西弗
[专家分:0] 发布于 2012-05-07 11:02:00
1.问题描述:
电子通讯录功能如下:1.Read
2.Append
3.Delete
4.Search
5.Isert。
说明:上图是电子通讯录的主菜单,利用它,将能够轻松地录入一个朋友的性别、出生日期、通讯地址、电话号码,而且它还提供了浏览、删除、检索和插入功能。 1)添加:在原有数据资料的基础上按顺序增加记录;2)删除:给出删除位置,执行删除后,查询是否被删除,显示通讯录的内容; 3)查询:给出姓名,列出该记录的信息。4)插入:给出插入位置,执行插入后,查询是否被插入,显示通讯录的内容;
2.解决方案:
用线性表顺序表设计电子通讯录的结构,为了表示较为复杂的数据内容,一般用结构这种数据类型,第一步就是在结构中定义所需要的各项信息。 一般的通讯录都包括姓名,性别,出生年月,通讯地址和联系电话这几项,而在这几项中,出生年月又包括年份,月份和日期三项,通讯地址包括邮编和家庭地址二项,我们把这些联系较为紧密的内容又用单独的结构表示,这样就产生了电子通讯录的基本结构。
回复列表 (共7个回复)
沙发
最西西弗 [专家分:0] 发布于 2012-05-07 11:04:00
急急急!
跪求各高手帮忙!!!
板凳
海盗许毅 [专家分:120] 发布于 2012-05-12 14:59:00
我也是刚在学习c++,写的不好还望楼主见谅。
#include<iostream>
#include<cstring>
using namespace std;
struct Address
{
double Dyoubian;
char Chomeaddress[60];
};
struct Time
{
int Iyear;
int Imonth;
int Iday;
};
typedef struct stu
{
char Csex;
char Cname[30];
Address address;
double Dnumber;
Time time;
stu *next;
}Member,*Pmember;
Pmember Phead=NULL, Pnow=NULL, Pnext=NULL, Plast=NULL;
char * inName();
void myRead();
void myInsert(char *);
bool myDelete(char *);
void myAppend();
Pmember mySearch(char *);
void myOut(Pmember );
void myCreat();
void myIn(Pmember );
void myView();
void myEat(int *);
int main()
{
myCreat();
system("cls");
myView();
int symbol=0;
cin >>symbol;
myEat(&symbol);
if(symbol<0||symbol>5)
{
cout<<" Warning :The number is not exit!!!";
cin.get();
cin.get();
myView();
}
while(symbol)
{ char *name=NULL;
Pmember j=NULL;
switch(symbol)
{
case 1: myRead();
cin.get();
cin.get();
break;
case 2: myAppend();
break;
case 3: name=inName();
myInsert(name);
break;
case 4: name=inName();
if(j=mySearch(name))
myOut(j);
cin.get();
break;
case 5: name=inName();
myDelete(name);
break;
default : ;
}
myView();
cin >>symbol;
myEat(&symbol);
}
cout<<" *********************************************************************************"<<endl;
cout<<" **************************** Good bye! *****************************"<<endl;
cout<<" *********************************************************************************"<<endl;
return 0;
}
3 楼
海盗许毅 [专家分:120] 发布于 2012-05-12 15:00:00
void myOut(Pmember t)
{
cout<< "name:"<<t->Cname<<" sex:"<<t->Csex<<endl;
cout<<"born :"<<t->time.Iyear<<","<<t->time.Imonth<<","<<t->time.Iday<<" "<<
"phone numbers:"<< t->Dnumber<<endl;
cout<<"youbain:"<<t->address.Dyoubian<<" "<<"homeaddress:"<<t->address.Chomeaddress<<endl;
cout<<endl<<endl;
}
void myIn(Pmember Pin)
{
cout<<" please input name:";
cin.get(Pin->Cname,30);
cout<<"please input sex(m or w) and telephone numbers:";
cin >> Pin->Csex>>Pin->Dnumber;
cout<< "please input born time like 1998 2 19 :";
cin >> Pin->time.Iyear>>Pin->time.Imonth>>Pin->time.Iday;
cout <<"please input youbain: ";
cin>>Pin->address.Dyoubian;
cin.get();
cout <<"please input homeaddress:";
cin.getline(Pin->address.Chomeaddress,60);
}
void myCreat()
{
Phead=Plast=Pnow=new Member;
Pnow->next=NULL;
}
void myAppend()
{
Pnow=Plast->next=new Member;
Plast=Pnow;
Plast->next=NULL;
cin.get();
myIn(Pnow);
}
void myRead()
{
Pnext=Phead->next;
if(!Pnext)
{
cout << "no person!" <<endl;
cin.get();
cin.get();
}
while(Pnext)
{
myOut(Pnext);
Pnext=Pnext->next;
}
}
Pmember mySearch(char *nam)
{
Pnext=Phead;
Pnow=Pnext;
Pnext=Pnow->next;
while(Pnext&&(strcmp(Pnext->Cname,nam)))
{
Pnow=Pnext;
Pnext=Pnext->next;
}
if(!Pnext)
{
cout << "no such person" <<endl;
cin.get();
return NULL;
}
else
return Pnext;
}
bool myDelete(char *nam)
{
Pmember p=NULL;
p=mySearch(nam);
if(!p)
{
cin.get();
return false;
}
if(p->next)
{
Pnow->next=p->next;
delete p;
return true;
}
else
{
Plast=Pnow;
Plast->next=NULL;
delete p;
return true;
}
}
void myInsert (char *name)
{
Pmember a, p=mySearch(name);
if(p)
{
a=new Member;
Pnow->next=a;
a->next=p;
myIn(a);
}
}
void myView()
{
system("cls");
cout<<endl;
cout<<" Welcome to the Contacts!"<<endl<<endl<<endl;
cout<<" 1:Read,"<<endl;
cout<<" 2:Append,"<<endl;
cout<<" 3:Insert,"<<endl;
cout<<" 4:Search,"<<endl;
cout<<" 5:Delete."<<endl;
cout<<" 0:quit!"<<endl;
cout<<" What do you want to do ? "<<"Please choose the number :";
}
char * inName()
{
char *name=new char[50];
cout <<"Please input name:";
cin.get();
cin.getline(name,50);
return name;
}
void myEat(int *p)
{
if(cin.fail()==true)
{
cin.clear();
while(cin.get()!='\n')
continue;
cout<<"please input number:";
cin >> *p;
}
}
4 楼
最西西弗 [专家分:0] 发布于 2012-05-14 10:46:00
太感谢了 !! [em2]
5 楼
最西西弗 [专家分:0] 发布于 2012-05-14 10:47:00
饿 可能是我学的太差了,我看不懂饿 ,是C++吗
不过还是谢谢啊!!!
6 楼
海盗许毅 [专家分:120] 发布于 2012-05-23 21:12:00
恩,就是c++呀。呵呵,没事,慢慢学就好了。
7 楼
最西西弗 [专家分:0] 发布于 2012-05-25 11:00:00
对了 这两个一个程序吗 好长啊!!
我来回复