资源简介

c++课程设计中的通讯录,详看博客http://blog.csdn.net/mybelief321

资源截图

代码片段和文件信息

/*TelBook.cpp*/
#include
#include
#include
#include

using namespace std;
string ID;//字符串类ID全局变量,具有唯一性

class Person //定义人类
{
protected:
string StuId;//学号
string Age; //年龄
char Name[20]; //姓名
char Sex[10]; //性别
string Tel;  //电话
Person *next; //Person类对象指针变量
public:
Person(string IDchar *Namechar *Sexstring Age string Tel)
{
strcpy(this->NameName);
strcpy(this->SexSex);
this->Tel=Tel;
this->StuId=ID;
this->Age=Age;
}

friend class Manage;//友元类
/*Manage类是Person类的友元类,则Manage类的所有成员函数都是Person
类的友元函数,都可以访问Person类的私有和保护成员*/
};

class Manage  //管理 类
{
public:
Manage()  //构造函数
{
person=0;
Load();  //成员函数
}
~Manage()  //析构函数
{
Person *p;//Person类的对象指针变量
p=person;
while(p) //当p不为0,即电话簿中记录不为0
{
p=p->next;
delete person; //删除该类对象
person=p;//准备删除下一对象
}
person=0;
}

void Find(char Name[20]);//按姓名查找
void Find(string ID); //按学号查找
void Add(); //添加信息
void Delete();//删除信息
void Modify(string ID);//修改信息
void Query(); //查询信息
void TJ(); //清除文件信息
void Save();//保存数据
void Load();//读入数据
void Look();//预览
void DesTory();//
void Output(Person *p)
{
cout<<“\t\t学号: “<StuId< cout<<“\t\t姓名: “<Name< cout<<“\t\t性别: “<Sex< cout<<“\t\t年龄: “<Age< cout<<“\t\t电话: “<Tel< cout<
}
private:
Person *person; //Person类对象指针
};
void Manage::Add()
{
system(“clear“);//清屏命令Windows对应的是cls
Person *p*p2; //新节点指针
string StuIdAgeTel;
char Name[20]Sex[10];
char c;
cout<<“\n** 新增学生通讯录 **\n“;
//输入学生信息
cout<<“输入学号:\t“;
cin>>StuId;
cout< {//块作用域
Person *p1;
p1=person;
while(p1)
{
if(p1->StuId==StuId)
{
break;
}
else
{
p1=p1->next;
}
}
if(p1!=NULL)
{
cout<<“该学号已存在,是否修改学生信息(Y/N):“< cin>>c;
if(toupper(c)==‘Y‘) //touper()函数是将字符转换为对应的大写字母
{
cout<<“该学生信息为: “< Find(StuId);
cout< Modify(StuId);
return ;
}
else
return ;
}
}//块作用域
cout<<“输入姓名:\t“;
cin>>Name;
cout<
cout<<“输入性别:\t“;
cin>>Sex;
cout<
cout<<“输入年龄:\t“;
cin>>Age;
cout<
cout<<“输入电话:\t“;
cin>>Tel;
cout<
p=new Person(StuIdNameSexAgeTel);
p->next=0;
//学生节点加入链表
    if(person)  //若已经存在节点
{
p2=person;
while(p2->next) //查找尾节点
{
p2=p2->next;
}
p2->next=p; //连接
}
else //若不存在节点(表空)
{
person=p; //连接
}
system(“clear“);
cout<<“\t\t\t ****添加成功***\n“< cout<<“是否继续添加?(Y/N)“< cin>>c;
if(toupper(c)==‘Y‘)
{
Add();
return ;
}
else
return;
}

void Manage::Delete()  //删除人员
{
system(“clear“);
char c;
char ch;
string StuId;
cout<<“\n** 删除信息 **\n“;
cout<<“输入要删除的学生ID:\t“;
cin>>StuId;
cout< //查找要删除的节点
Person *p1*p2;
p1=person;
while(p1)
{
if(p1->StuId==StuId)
break;
else
{
p2=p1;
p1=p1->next;
}
}
//删除节点
if(p1!=NULL) //若找到节点,则删除
{
cout<<“所要删除的学生的信息如下:\n“< Output(p1);
cout<<“确定是否删除(Y/N): “;
cin>>c;
if(toupper(c)!=‘Y‘)
return;
if(p1==

评论

共有 条评论