//类似//#include "stdafx.h"
#include
#include
#include
class stu
{
char name[20];
double age,homephone,telphone;
char sex;
public:
stu(){}
stu(char n[20],char se,double ag,double ho,double te)
{
strcpy(name, n);
age=ag;
homephone=ho;
telphone=te;
}
friend void main();
}; void main()
{
cout<<"请选择您需要的操作!"<
int i=0;
int j=0;
bool flag2=0;
char p;
do
{
cin>>p;
if((p>='0'&&p<='5'))
flag2=1;
else
cout<<"指令错误!请重新输入:"<
{ case '0': //(0)通讯录录入
{
char name[20];
double age,homephone,telphone;
char sex,c;
do{ cout<<"请输入姓名:"<
cout<<"请输入性别:"<
cout<<"请输入年龄:"<
cout<<"请输入家里的电话号码:"<
cout<<"请输入移动电话号码:"<
j++;
s[i]=new stu(name, sex, age, homephone , telphone);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<
flag2=0;
do
{
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
}
else
flag2=1;
}while(flag2==0);
}while(c=='y');
break; }
////////////////////////////////////////////////////////////////////
case '1': //(1)增加人员(Add)
{
char name[20];
double age,homephone,telphone;
char sex,c;
do{ cout<<"请输入姓名:"<
cout<<"请输入性别:"<
cout<<"请输入年龄:"<
cout<<"请输入家里的电话号码:"<
cout<<"请输入移动电话号码:"<
j++;
s[i]=new stu(name, sex, age, homephone , telphone);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<
flag2=0;
do
{
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
}
else
flag2=1;
}while(flag2==0);
}while(c=='y');
break; } case '2': //(2)删除人员(Delete)
{
char name[20];bool flag3=0;char c;
do{
cout<<"请输入您要删除的学生姓名:"<
for(int h=0;h{
if(strcmp(name,s[h]->name)==0)
{
flag3=1;
i--;
do{
s[h]=s[h+1];
h++;
}while(h<=i);
}
}
if(flag3==0)
cout<<"您要求删除的对象本来就不存在!请检查输入的正确性!";
cout<<"要继续删除吗?(y/n)"<
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
}
}while(c=='y');
break; }
case '3': //(3)修改数据(Alter)
{
char name[20],se;double ag,ho,te;flag2=0;
char c;
do
{
cout<<"请输入您要修改的学生的姓名:"<
for(int h=0;h{
if(strcmp(name,s[h]->name)==0)
{
flag2=1;
cout<<"请输入性别:"<
cout<<"请输入年龄:"<
cout<<"请输入家里的电话号码:"<
cout<<"请输入移动电话号码:"<
s[h]->sex=se;
s[h]->age=ag;
s[h]->homephone=ho;
s[h]->telphone=te;
cout<<"数据修改成功!";
}
}
if(flag2==0)
{
cout<<"您要修改的学生本来就不存在!请检查重新输入!"<
cout<<"想继续修改吗(y/n)"<
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
}
}while(c=='y');
break; }
case '4': //(4)显示记录(List)
{
cout<<"本系统所有通讯录的数据如下:"<
cout<<"管理系统中没有录入数据或者数据已经被删除!"<
cout<
"性别:"<<" "<sex<<"年龄:"<<" "<age
<<"家里的电话号码:"<<" "<homephone<<"移动电话号码:"
<<" "<telphone<
break; } }
cout<<"您想继续进行其他操作吗?(y/n)"<
do
{
cin>>p;
if(p!='y'&&p!='n')
cout<<"指令错误!请重新输入!"<
flag4=1;
}while(flag4==0); if(p=='y')
cout<<"请输入操作代码(0 通讯录录入\n1 增加人员(Add)\n2 删除人员(Delete)\n3 修改数据(Alter)\n4 显示记录(List)\n 5 退出(Exit))"<
for(int x=0;x{
delete s[x];
cout<<"删除所有成员!"<