Hello大家好,本次呢,来给大家开来一个c++课设(通讯录管理系统),此次内容呢是在学习了c++语言之后,借助参考资料及课设要求来写的。
课题名称:《个人通讯录管理软件》
来源:通过这次设计,要求在逻辑特性和结构的设计及其实现等方面中加深对课程基本内容的理解。在程序结构与功能上,充分运用面向对象的思想和方法,包括信息封装、继承、多态以及文件的操作。
建立一通讯录,输入姓名、电话号码、住址等信息,然后对通信簿进行显示、查找、添加、修改及删除。
功能要求
(1) 通讯录的每一条信息包括姓名、单位、固定电话、移动手机、分类(如同事、朋友、同学、家人等)、EMAIL、QQ等。
(2) 输入功能:可以一次完成若干条信息的输入。
(3) 显示功能:完成全部通讯录信息的显示(一屏最多显示10条,超过十条应能够自动分屏显示)
(4) 查找功能:可以按姓名等多种方式查找通讯信息
(5) 增加、删除、修改功能:完成通讯录信息的多种更新
(6)信息保存到文件及从文件调入(在输入时就可实现时时保存)
描述程序文件的总体结构,最好给出程序(系统)的功能结构图或类层次关系图。
表一:person类
数据名称 | 类型定义 |
---|---|
姓名 | String name |
关系 | Int relationship |
年龄 | int age |
固定电话(传真) | long fixed |
移动电话 | long mobile |
家庭住址 | string address |
函数名称 … 函数类型 | 功能 |
Xiugai …void | 修改联系人 |
Chazhao …void | 查找联系人 |
Xianshi… void | 显示所有联系人 |
Tianjia … void | 添加联系人 |
tuichu …void | 退出系统 |
shanchu… void | 删除联系人 |
jiance… void | 检测 |
Jiance_1 … void | 检测 |
Xieru… void | 文件写入 |
Xieru_1 …void | 文件写入 |
duqu …void | 文件读取 |
表二:菜单类Face(父类)FACE(子类)
|函数名称 | 函数类型 |功能
Face_1| virtual void |主菜单
Face_2| virtual void |修改菜单
Face_3| virtual void |查找菜单
父类中定义纯虚函数;
子类继承父类,父类指针指向子类对象,实现多态
class Face//父类
{
public:
Face()
{
}
~Face()
{
}
virtual void Face_1() = 0;
virtual void Face_2() = 0;
virtual void Face_3() = 0;
};
class FACE :public Face//继承(子类 )
{
public:
FACE()
{
}
~FACE()
{
}
void Face_1();
void Face_2();
void Face_3();
};
该类为核心,包含一系列功能的函数的声明及实现。
class Person //创建一个类(主类)
{
public:
string name;
int relationship;
int age;
long fixed;
long mobile;
string address;
Person* next;
public:
Person()
{
}
void xiugai();//修改
void chazhao();//查找
void xianshi();//显示
void tianjia();//添加
void tuichu();//退出
void shanchu();//删除
void jiance();//检测
void jiance_1();//检测-2
void xieru(); //写入
void xieru_1();//写入-2
void duqu(); //读取
~Person()
{
}
};
本程序实现了添加、显示、删除、修改、清空、查找功能。
添加:
void tianjia()//添加及查重
{
int n;
int y;
class Person* p1;
class Person* p2;
if (m==0)
{
p1 = new Person;
p2 = new Person;
head = p1;
p1->next = p2;
m++;
}
else
{
p1 = head;
while (p1->next != NULL)
{
p1 = p1->next;
cout << "2" << endl;
}
p2 = new Person;
p1->next = p2;
}
cout << "您想添加几位联系人?" << endl;
cin >> n;
for (int i = 1; i <= n; i++)
{
p1 = new Person;
cout << "请输入第" << i << "位联系人姓名:";
cin >> p2->name;
cout << "请输入第" << i << "位联系人类型:";
cout << "1 代表 同学; 2 代表 老师; 3 表示 亲人" << endl;
cin >> p2->relationship;
cout << "请输入第" << i << "位联系人年龄:";
cin >> p2->age;
cout << "请输入第" << i << "位联系人固定电话号:";
cin >> p2->fixed;
cout << "请输入第" << i << "位联系人移动电话号:";
cin >> p2->mobile;
cout << "请输入第" << i << "位联系人地址:";
cin >> p2->address;
int c = jiance(p2->mobile);
if (c == 1)
{
c = 0;
cout << "此联系人已存在请重新添加联系人!" << endl;
i--;
continue;
}
if (i == n)
{
cout << "添加联系人完成!" << endl;
break;
}
cout << "是否提前结束输入?" << endl;
cout << "'0'代表结束" << endl;
cin >> y;
if (y == 0)
{
cout << "成功提前结束输入!" << endl;
break;
}
p2->next = p1;
p2 = p1;
}
}
显示
void xianshi()
{
int h = 1;
int n = 1;
class Person* p1;
p1 = new Person;
p1 = head->next;
do
{
cout << "第" << n << "名联系人的姓名为:" << p1->name << endl;
if (p1->relationship == 1)
cout << "第" << n << "名联系人是:同学" << endl;
else if (p1->relationship == 2)
cout << "第" << n << "名联系人是:老师" << endl;
else if (p1->relationship == 3)
cout << "第" << n << "名联系人是:亲人" << endl;
cout << "第" << n << "名联系人的年龄为:" << p1->age << endl;
cout << "第" << n << "名联系人的固定电话号为:" << p1->fixed << endl;
cout << "第" << n << "名联系人的移动电话号为:" << p1->mobile << endl;
cout << "第" << n << "名联系人的家庭住址为:" << p1->address << endl << endl;
p1 = p1->next;
if (n % 10 == 0)
{
cout << "\t\t\t第" << h << "页" << endl;
system("pause");
system("cls");
h++;
}
} while (p1 != NULL);
}
删除
void shanchu()
{
long number;
class Person* p1;
class Person* p2;
p1 = new Person;
p2 = new Person;
p1 = head;
cout << "请输入您想删除联系人的移动电话号码:";
cin >> number;
int n = jiance_1(number);
if (n == 1)
{
do
{
p2 = p1;
p1 = p1->next;
if (p1->mobile == number)
{
p2->next = p1->next;
cout << "删除完毕!" << endl;
break;
}
} while (p1->next != NULL);
}
else
cout << "通讯录中没有相关的联系人信息!" << endl;
}
修改
void xiugai()//修改
{
Face* W = new FACE; //
int m;
string str;// 定义
class Person* p;
p = head->next;
while (1)
{
int n = 0;
cout << "请输入您想修改联系人的姓名:" << endl;
cin >> str;
while (p != NULL)
{
if (p->name == str)
{
while (1)
{
W->Face_2();
cin >> m;
if (m == 1)
{
cout << "请输入修改地正确的年龄:";
cin >> p->age;
}
if (m == 2)
{
cout << "请输入修改地正确的固定电话号(传真):";
cin >> p->fixed;
}
if (m == 3)
{
cout << "请输入修改地正确的移动电话号:";
cin >> p->mobile;
}
if (m == 4)
{
cout << "请输入修改地正确的家庭住址:";
p->address;
}
if (m == 5)
{
cout << "请输入修改地正确的联系人关系:";
p->relationship;
}
if (m == 0)
break;
}
n++;
}
p = p->next;
}
if (n == 0)
{
cout << "查无此人" << endl;
}
cout << "是否结束联系人信息修改?" << endl << "0表示结束修改联系人信息";
cin >> m;
if (m == 0)
break;
}
}
清空
void qingkong()
{
head = NULL;
m = 0;
xieru_1();
cout << "成功清空通讯录" << endl;
}
查找
void chazhao()
{
long Num;
class Person* p1;
p1 = new Person;
p1 = head->next;
cout << "请输入您想查询联系人的联系方式:" << endl;
cin >> Num;
while (p1 != NULL)
{
if (Num == p1->mobile)
{
cout << "该联系人的姓名为:" << p1->name << endl;
if (p1->relationship == 1)
cout << "该联系人是:同学" << endl;
else if (p1->relationship == 2)
cout << "该联系人是:老师" << endl;
else if (p1->relationship == 3)
cout << "该名联系人是:亲人" << endl;
cout << "该联系人的年龄为:" << p1->age << endl;
cout << "该联系人的电话号为:" << p1->mobile << endl;
cout << "该联系人的家庭住址为:" << p1->address << endl;
break;
}
p1 = p1->next;
}
}
#include<iostream>
#include<string.h>
#include<fstream>
using namespace std;
int l=0;
int A;
int m = 0;
char x[100];
class Person* head = NULL;
class Face//父类
{
public:
Face()
{
}
~Face()
{
}
virtual void Face_1() = 0;
virtual void Face_2() = 0;
virtual void Face_3() = 0;
};
class FACE :public Face//继承(子类 )
{
public:
FACE()
{
}
~FACE()
{
}
void Face_1();
void Face_2();
void Face_3();
};
class Person //创建一个类(主类)
{
public:
string name;
int relationship;
int age;
long fixed;
long mobile;
string address;
Person* next;
public:
Person()
{
}
void xiugai();//修改
void chazhao();//查找
void xianshi();//显示
void tianjia();//添加
void tuichu();//退出
void shanchu();//删除
void jiance();//检测
void jiance_1();//检测-2
void xieru(); //写入
void xieru_1();//写入-2
void duqu(); //读取
~Person()
{
}
};
void FACE::Face_1()
{
system("cls");
system("color 55");
system("date/T");//日期
system("TIME/T");//时间
cout << "\t\t\t\t**************************************************" << endl;
cout << "\t\t\t\t***** 个人通讯录软件 *****" << endl;
cout << "\t\t\t\t*****========================================*****" << endl;
cout << "\t\t\t\t***** 1.添加联系人 *****" << endl;
cout << "\t\t\t\t***** *****" << endl;
cout << "\t\t\t\t***** 2.显示联系人 *****" << endl;
cout << "\t\t\t\t***** *****" << endl;
cout << "\t\t\t\t***** 3.删除联系人 *****" << endl;
cout << "\t\t\t\t***** *****" << endl;
cout << "\t\t\t\t***** 4.修改联系人 *****" << endl;
cout << "\t\t\t\t***** *****" << endl;
cout << "\t\t\t\t***** 5.清空联系人 *****" << endl;
cout << "\t\t\t\t***** *****" << endl;
cout << "\t\t\t\t***** 6.查找联系人 *****" << endl;
cout << "\t\t\t\t***** *****" << endl;
cout << "\t\t\t\t***** 7.退出通讯录 *****" << endl;
cout << "\t\t\t\t**************************************************" << endl;
}
void FACE::Face_2()
{
system("cls");
system("date/T");//日期
system("TIME/T");//时间
cout << "\t\t\t\t***********************************" << endl;
cout << "\t\t\t\t**** 1.修改年龄 ****" << endl;
cout << "\t\t\t\t**** ****" << endl;
cout << "\t\t\t\t**** 2.修改固话(传真) ****" << endl;
cout << "\t\t\t\t**** ****" << endl;
cout << "\t\t\t\t**** 3.修改移动电话 ****" << endl;
cout << "\t\t\t\t**** ****" << endl;
cout << "\t\t\t\t**** 4.修改家庭住址 ****" << endl;
cout << "\t\t\t\t**** ****" << endl;
cout << "\t\t\t\t**** 5.修改联系人关系 ****" << endl;
cout << "\t\t\t\t**** ****" << endl;
cout << "\t\t\t\t**** 0.退出修改 ****" << endl;
cout << "\t\t\t\t***********************************" << endl;
}
void FACE::Face_3()
{
//system("color ");
system("cls");
system("date/T");//日期
system("TIME/T");//时间
cout << "\t\t\t\t***********************************" << endl;
cout << "\t\t\t\t**** 1.按姓名查找 ****" << endl;
cout << "\t\t\t\t**** ****" << endl;
cout << "\t\t\t\t**** 2.按手机号查找 ****" << endl;
cout << "\t\t\t\t***********************************" << endl;
}
void xiugai()//修改
{
Face* W = new FACE; //
int m;
string str;// 定义
class Person* p;
p = head->next;
while (1)
{
int n = 0;
cout << "请输入您想修改联系人的姓名:" << endl;
cin >> str;
while (p != NULL)
{
if (p->name == str)
{
while (1)
{
W->Face_2();
cin >> m;
if (m == 1)
{
cout << "请输入修改地正确的年龄:";
cin >> p->age;
}
if (m == 2)
{
cout << "请输入修改地正确的固定电话号(传真):";
cin >> p->fixed;
}
if (m == 3)
{
cout << "请输入修改地正确的移动电话号:";
cin >> p->mobile;
}
if (m == 4)
{
cout << "请输入修改地正确的家庭住址:";
p->address;
}
if (m == 5)
{
cout << "请输入修改地正确的联系人关系:";
p->relationship;
}
if (m == 0)
break;
}
n++;
}
p = p->next;
}
if (n == 0)
{
cout << "查无此人" << endl;
}
cout << "是否结束联系人信息修改?" << endl << "0表示结束修改联系人信息";
cin >> m;
if (m == 0)
break;
}
}
void duqu()
{
Person* p = head->next, * p2 = NULL, * p3 = NULL;//*p3指针是用于解决eof()函数所引起的末尾重复问题
ifstream out("D:/txlglxt.txt", ios::binary);
if (!out) {
cout << "文件打开失败!" << endl;
return;
}
while (!out.eof()) {
p2 = new Person;
if (out.peek() == EOF)break;
out >> p2->name >> p2->relationship >> p2->age >> p2->fixed >> p2->mobile >> p2->address;
p->next = p2;
p3 = p;
p = p->next;
}
p3->next = NULL;
out.close();
}
void xieru_1()
{
Person* p = head;
ofstream in("D:/txlglxt.txt", ios::binary);
if (!in) {
cout << "文件无法创建" << endl;
return;
}
while (p != NULL) {
in << p->name << "\t" << p->relationship << "\t" << p->age << "\t" << p->fixed << "\t" << p->mobile << "\t" << p->address << "\n";
p = p->next;
}
in.close();
}
void xieru()
{
Person* p = head->next;
ofstream in("D:/txlglxt.txt", ios::binary);
if (!in) {
cout << "文件无法创建" << endl;
return;
}
while (p != NULL) {
in << p->name << "\t" << p->relationship << "\t" << p->age << "\t" << p->fixed << "\t" << p->mobile << "\t" << p->address << "\n";
p = p->next;
}
in.close();
system("cls");
cout << "***********************************" << endl;
cout << "*** 通讯录保存成功! ***" << endl;
cout << "***********************************" << endl;
}
int jiance_1(int Num)
{
class Person* p1;
p1 = new Person;
p1 = head;
do
{
if (p1->mobile == Num)
{
l = 1;
break;
}
else
{
l = 0;
}
p1 = p1->next;
} while (p1 != NULL);
return l;
}
int jiance(int Num)
{
class Person* p1;
p1 = new Person;
p1 = head;
while (p1->next != NULL)
{
if (p1->mobile== Num)
{
l = 1;
break;
}
else
{
l = 0;
}
p1 = p1->next;
}
return l;
}
void qingkong()
{
head = NULL;
m = 0;
xieru_1();
cout << "成功清空通讯录" << endl;
}
void shanchu()
{
long number;
class Person* p1;
class Person* p2;
p1 = new Person;
p2 = new Person;
p1 = head;
cout << "请输入您想删除联系人的移动电话号码:";
cin >> number;
int n = jiance_1(number);
if (n == 1)
{
do
{
p2 = p1;
p1 = p1->next;
if (p1->mobile == number)
{
p2->next = p1->next;
cout << "删除完毕!" << endl;
break;
}
} while (p1->next != NULL);
}
else
cout << "通讯录中没有相关的联系人信息!" << endl;
}
void chazhao()
{
long Num;
class Person* p1;
p1 = new Person;
p1 = head->next;
cout << "请输入您想查询联系人的联系方式:" << endl;
cin >> Num;
while (p1 != NULL)
{
if (Num == p1->mobile)
{
cout << "该联系人的姓名为:" << p1->name << endl;
if (p1->relationship == 1)
cout << "该联系人是:同学" << endl;
else if (p1->relationship == 2)
cout << "该联系人是:老师" << endl;
else if (p1->relationship == 3)
cout << "该名联系人是:亲人" << endl;
cout << "该联系人的年龄为:" << p1->age << endl;
cout << "该联系人的电话号为:" << p1->mobile << endl;
cout << "该联系人的家庭住址为:" << p1->address << endl;
break;
}
p1 = p1->next;
}
}
void xianshi()
{
int h = 1;
int n = 1;
class Person* p1;
p1 = new Person;
p1 = head->next;
do
{
cout << "第" << n << "名联系人的姓名为:" << p1->name << endl;
if (p1->relationship == 1)
cout << "第" << n << "名联系人是:同学" << endl;
else if (p1->relationship == 2)
cout << "第" << n << "名联系人是:老师" << endl;
else if (p1->relationship == 3)
cout << "第" << n << "名联系人是:亲人" << endl;
cout << "第" << n << "名联系人的年龄为:" << p1->age << endl;
cout << "第" << n << "名联系人的固定电话号为:" << p1->fixed << endl;
cout << "第" << n << "名联系人的移动电话号为:" << p1->mobile << endl;
cout << "第" << n << "名联系人的家庭住址为:" << p1->address << endl << endl;
p1 = p1->next;
if (n % 10 == 0)
{
cout << "\t\t\t第" << h << "页" << endl;
system("pause");
system("cls");
h++;
}
} while (p1 != NULL);
}
void tianjia()//添加及查重
{
int n;
int y;
class Person* p1;
class Person* p2;
if (m==0)
{
p1 = new Person;
p2 = new Person;
head = p1;
p1->next = p2;
m++;
}
else
{
p1 = head;
while (p1->next != NULL)
{
p1 = p1->next;
cout << "2" << endl;
}
p2 = new Person;
p1->next = p2;
}
cout << "您想添加几位联系人?" << endl;
cin >> n;
for (int i = 1; i <= n; i++)
{
p1 = new Person;
cout << "请输入第" << i << "位联系人姓名:";
cin >> p2->name;
cout << "请输入第" << i << "位联系人类型:";
cout << "1 代表 同学; 2 代表 老师; 3 表示 亲人" << endl;
cin >> p2->relationship;
cout << "请输入第" << i << "位联系人年龄:";
cin >> p2->age;
cout << "请输入第" << i << "位联系人固定电话号:";
cin >> p2->fixed;
cout << "请输入第" << i << "位联系人移动电话号:";
cin >> p2->mobile;
cout << "请输入第" << i << "位联系人地址:";
cin >> p2->address;
int c = jiance(p2->mobile);
if (c == 1)
{
c = 0;
cout << "此联系人已存在请重新添加联系人!" << endl;
i--;
continue;
}
if (i == n)
{
cout << "添加联系人完成!" << endl;
break;
}
cout << "是否提前结束输入?" << endl;
cout << "'0'代表结束" << endl;
cin >> y;
if (y == 0)
{
cout << "成功提前结束输入!" << endl;
break;
}
p2->next = p1;
p2 = p1;
}
}
void tuichu()
{
cout << "感谢您的使用,成功退出通讯录!" << endl;
exit(0);
}
void caidan()
{
Face* W = new FACE;
while (1)
{
W->Face_1();
cout << "请选择您想进行的操作:" << endl;
cin >> x;
if (m == 0 && x[0] - 48 != 1)
{
cout << "链表为空!请您先进行联系人信息导入!" << endl;
system("pause");
continue;
}
switch (x[0] - 48)
{
case 1: //创建通讯录
tianjia();
xieru();
system("pause");
break;
case 2: //显示通讯录
xianshi();
system("pause");
break;
case 3: //删除联系人
shanchu();
system("pause");
break;
case 4: //修改已存在联系人个人信息
xiugai();
system("pause");
break;
case 5: //清空通讯录
qingkong();
system("pause");
break;
case 6: //查找联系人个人信息
chazhao();
system("pause");
break;
case 7: //退出通讯录
tuichu();
system("pause");
break;
default:
system("cocor 40");
cout << "请正确输入操作选项!" << endl;
system("pause");
}
}
}
int main()
{
system("color 3");
cout << "通讯录加在中......." << endl;
cout << "请稍等......" << endl;
system("pause");
system("cls");
cout << "加载成功!" << endl;
system("pause");
caidan();
return 0;
}
根据程序(系统)的运行结果,说明程序解决了哪些问题?还有哪些问题没有[很好地]解决或者处理得不够完善?
本程序在制作中解决了大范围修改、只能单个添加等问题,实现了一次多个添加,精确修改等
本程序在文件方面以及查找方面还存在一些问题。
介绍本课程设计实施过程中所取得的经验教训,展望下一步的工作。
在编写代码之前要有大致的框架,分布实现功能,要熟练掌握C++语言的应用。希望在日后的学习中继续努力深一步的学习,争取以后写的程序功能多一点,bug少一点,头发一点儿也不掉。
拜拜!!!