《数据结构课程设计》
课程题目 | 个人通讯录管理系统 |
课程编号 | j1620102 |
学生姓名 | 陈彦书 |
学生学号 | 201311671102 |
所在专业 | 信息管理与信息系统 |
所在班级 | 1131 |
任课老师 | 易学明 |
实习时间 | 16-17周 |
设计成绩 |
|
老师评语 |
|
目录
一. 问题描述 3
二. 问题分析 3-4
三. 逻辑结构和存储结构设计 4-5
四. 算法设计 5
五. 时间复杂度和空间复杂度分析 5
六. 源代码 6-14
七. 程序运行结果 14-22
八. 心得 22
一、问题描述
李刚是一爱折腾的人,当然爱折腾的人均有梦想,他想当中国的盖次呢。可不,现在个人好友信息多了,复杂了,他想制作一个个人通讯录的制作管理软件。 刚好这个学期学了数据结构课,所以他准备使用数据结构知识来实现了。并考虑使用双向链表作数据结构。并制定了初步要求:
(1)每个好友信息包含姓名、性别、住址、邮编、几岁、电话、QQ、微信帐号、生日等。
(2)作为一个完整的系统,应具有友好的界面和较强的容错能力。
二、问题分析
通讯录的制作,体现了实现数据的输入、输出、插入、删除、查询的功能。程序的基本功能为:建立通讯者信息,包含姓名、性别、住址、邮编、年龄、电话、QQ、微信帐号、生日和添加新的通讯者信息;按姓名查询某个通讯者的信息;按姓名删除某个通讯者的信息;输出显示通讯录的所有信息。
根据题目要求及结合问题实际,我决定使用双链表来完成这次试验。双链表是在单链表的每个节点中再设置一个指向其前驱节点的指针域。双链表是一种对称结构,对于储存通讯录来说比较方便。
(1)内容:
1、通讯录内容包括:姓名、性别、住址、邮编、年龄、电话、QQ、微信帐号、生日
(2)功能描述
1、新建:用户可以输入以上所有内容,建立一个新的通信记录。
2、删除:把旧的联系人进行删除释放储存空间。
3、查询:最重要的功能,具有姓名查询的具体功能。
4、修改:用户可以及时更改错误或过期信息。
0、退出:退出系统
三、逻辑结构和存储结构设计
从题目的要求中,我们可以看到题目要求我使用双链表来完成这次的课程设计,因此,这次的逻辑结构为线性表。线性表是一种最基本最简单的数据结构,数据元素之间仅具有单一的前驱和后驱关系。
由于这次的题目是构造一个通信录,需要插入和删除,查询和修改等功能,因此顺序表是静态存储分配并不适合,因此在这里选取链表来克服顺序表的缺点。
链表是用一组任意的存储单元存放线性表的元素,其中,双链表是在单链表的每个结点中再设置一个指向其前驱结点的指针域。在链表中实现插入和删除操作,无需移动结点,在将工作指针指向合适的位置后,仅需修改节点之间的链接关系,所以在通信录这次的题目中使用双链表比较合理。
四、算法设计
五、时间复杂度和空间复杂度分析
和单链表类似,双链表一般也由头指针唯一确定,增加头结点也能使双链表的某些操作变得方便。这时,由书本上可知,按值查找:与输入实例有关,平均时间复杂度均为O(n),双链表上的插入和删除时间复杂度均为O (1)。空间复杂度为O(n)。
六、源代码
#define PERSON_H
#include <string>
using std::string;
struct Person
{
string Name;
string Number;
string Sex;
string Age;
string Birthday;
string Address;
string Code;
string Qnum;
string Wnum;
Person *pre, *next;
Person(string, string, string, string, string, string, string, string, string);
Person(string, string, string, string, string, string, string, string, string, bool);
};
#endif
public:
Phone_System();
void Build();
void Watch();
void Search_Cut();
void Search_Alter();
private:
Person* Scan();
Person* Search();
void Cut(Person*);
void Alter(Person*);
Person *First;
Person *Rear;
};
#endif
#include "Phone_System.h"
#include <iostream>
using namespace std;
void main()
{
Phone_System ps;
unsigned choice = 0;
while (true)
{
system("cls");
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\t\t\t\t1:新建\t\t\t\t" << endl;
cout << "\t\t\t\t2:删除\t\t\t\t" << endl;
cout << "\t\t\t\t3:查询\t\t\t\t" << endl;
cout << "\t\t\t\t4:修改\t\t\t\t"<< endl;
cout << "\t\t\t\t0:退出\t\t\t\t" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\t\t\t 请输入你的选择:" << ends;
cin >> choice;
switch (choice)
{
case 0:exit(-1); break;
case 1:ps.Build(); break;
case 2:ps.Search_Cut(); break;
case 3:ps.Watch(); break;
case 4:ps.Search_Alter(); break;
default:
cout << "非法输入!" << endl;
system("pause");
break;
}
}
}
#include "Person.h"
#include <iostream>
using namespace std;
Person::Person
(string name, string number, string sex, string age, string birthday, string address, string code, string qnum, string wnum ) :
Name(name), Number(number), Sex(sex), Age(age), Birthday(birthday), Address(address), Code(code), Qnum(qnum), Wnum(wnum), pre(nullptr), next(nullptr)
{
system("cls");
cout << "新建成功" << endl;
cout << "姓名:" << Name << endl;
cout << "号码:" << Number << endl;
cout << "性别:" << Sex <<endl;
cout << "年龄:" << Age << endl;
cout << "生日:" << Birthday << endl;
cout << "地址:" << Address << endl;
cout << "邮编:" << Code << endl;
cout << "Q Q :" << Qnum << endl;
cout << "微信:" << Wnum << endl;
system("pause");
}
Person::Person
(string name, string number, string sex,string age,string birthday,string address,string code,string qnum,string wnum, bool) :
Name(name), Number(number), Sex(sex), Age(age), Birthday(birthday), Address(address), Code(code), Qnum(qnum), Wnum(wnum), pre(nullptr), next(nullptr){}
#include "Phone_System.h"
#include <iostream>
#include "Person.h"
using namespace std;
Phone_System::Phone_System() :
First(nullptr), Rear(nullptr)
{
First = new Person("#", "#", "#", "#", "#", "#", "#", "#", "#", true);
Rear = new Person("#", "#", "#", "#", "#", "#", "#", "#", "#", true);
First->next = Rear;
Rear->pre = First;
system("cls");
cout << "\n"<< endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\t\t\t欢迎使用个人通讯录管理系统!\t\t\t"<< endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
cout << "\n" << endl;
system("pause");
system("cls");
}
Person* Phone_System::Scan()
{
system("cls");
string name;
cout << "请输入姓名:" << ends;
cin >> name;
string number;
cout << "请输入电话号码:" << ends;
cin >> number;
unsigned sex = 0;
string sexual;
while (sex != 1 && sex != 2)
{
cout << "请输入性别(1.女 2.男):" << ends;
cin >> sex;
if (sex == 1)
sexual = "女";
else
if (sex == 2)
sexual = "男";
else
cout << "输入错误!请按序号输入" << endl;
system("pause");
}
string age;
cout << "请输入年龄:" << ends;
cin >> age;
string birthday;
cout << "请输入生日:" << ends;
cin >> birthday;
string address;
cout << "请输入地址:" << ends;
cin >> address;
string code;
cout << "请输入邮编:" << ends;
cin >> code;
string qnum;
cout << "请输入Q Q :" << ends;
cin >> qnum;
string wnum;
cout << "请输入微信:" << ends;
cin >> wnum;
Person *a = new Person(name, number, sexual, age, birthday, address, code, qnum, wnum);
return a;
}
void Phone_System::Build()
{
Person *p = nullptr;
while (true)
{
system("cls");
cout << "是否继续录入:Y/N" << endl;
char chosse = 'Y';
cin >> chosse;
if (chosse == 'n' || chosse == 'N')
break;
p = Scan();
p->next = First->next;
First->next = p;
p->next->pre = p;
p->pre = First;
}
}
Person* Phone_System::Search()
{
cout << "1.名字搜索" << endl;
cout << "2.号码搜索" << endl;
cout << "请输入查询方式:" << ends;
unsigned choice = 0;
cin >> choice;
Person *p = nullptr;
system("cls");
if (choice == 1)
{
string name;
cout << "请输入姓名:" << ends;
cin >> name;
p = First->next;
while (p != nullptr&&p->Name != name)
p = p->next;
if (p == nullptr)
{
cout << "无该用户!" << endl;
system("pause");
}
}
else
if (choice == 2)
{
string number;
cout << "请输入账号:" << ends;
cin >> number;
p = First->next;
while (p != nullptr&&p->Number != number)
p = p->next;
if (p == nullptr)
{
cout << "无该用户!" << endl;
system("pause");
}
}
else
{
system("cls");
cout << "查询失败!" << endl;
system("pause");
}
return p;
}
void Phone_System::Watch()
{
system("cls");
cout << "请按照提示进行查询操作" << endl;
Person *p = Search();
if (p != nullptr)
{
system("cls");
cout << "账户信息:" << endl;
cout << "姓名:" << p->Name << endl;
cout << "号码:" << p->Number << endl;
cout << "性别:" << p->Sex << endl;
cout << "年龄:" << p->Age << endl;
cout << "生日:" << p->Birthday << endl;
cout << "地址:" << p->Address << endl;
cout << "邮编:" << p->Code << endl;
cout << "Q Q :" << p->Qnum << endl;
cout << "微信:" << p->Wnum << endl;
system("pause");
}
}
void Phone_System::Cut(Person *a)
{
a->next->pre = a->pre;
a->pre->next = a->next;
delete a;
cout << "删除成功!" << endl;
system("pause");
}
void Phone_System::Search_Cut()
{
system("cls");
cout << "请按照提示进行删除前的查询操作" << endl;
Person *p = Search();
if (p != nullptr)
Cut(p);
else
{
system("cls");
cout << "删除失败!" << endl;
system("pause");
}
}
void Phone_System::Alter(Person *p)
{
cout << "1:姓名" << endl;
cout << "2:号码" << endl;
cout << "3:性别" << endl;
cout << "4:年龄" << endl;
cout << "5:生日" << endl;
cout << "6:地址" << endl;
cout << "7:邮编" << endl;
cout << "8:Q Q " << endl;
cout << "9:微信" << endl;
cout << "请选择要修改的项:" << ends;
unsigned choice;
cin >> choice;
unsigned sex = 0;
switch (choice)
{
case 1:
cout << "请输入:" << ends;
cin >> p->Name; break;
case 2:
cout << "请输入:" << ends;
cin >> p->Number; break;
case 3:
while (sex != 1 && sex != 2)
{
cout << "请选择性别:1:女,2:男" << ends;
cin >> sex;
if (sex == 1)
p->Sex = "女";
else
if (sex == 1)
p->Sex = "男";
else
cout << "输入错误!请按序号输入" << endl;
system("pause");
}break;
case 4:
cout << "请输入:" << ends;
cin >> p->Age; break;
case 5:
cout << "请输入:" << ends;
cin >> p->Birthday; break;
case 6:
cout << "请输入:" << ends;
cin >> p->Address; break;
case 7:
cout << "请输入:" << ends;
cin >> p->Code; break;
case 8:
cout << "请输入:" << ends;
cin >> p->Qnum; break;
case 9:
cout << "请输入:" << ends;
cin >> p->Wnum; break;
default:cout << "非法操作" << endl;
}
}
void Phone_System::Search_Alter()
{
system("cls");
cout << "请按照提示进行修改前的查询操作" << endl;
Person *p = Search();
if (p != nullptr)
Alter(p);
else
{
system("cls");
cout << "修改失败!" << endl;
system("pause");
}
}
七、程序运行结果
1.界面
2.主功能表
3.新建
4.删除
5.查询
6.修改
7.退出
八、心得
经过这个学期的学习,使我对于数据结构从陌生到逐渐熟悉,初步入门。回忆起本次课程设计,可算感触良多。对于这次的课程设计,因为我对于数据结构的知识并不能算掌握的十分牢靠,所以一开始的时候深感无从下手。可是经过查阅大量的资料,参考了网上的通讯录系统,向同学学习,总算完成了这次的课程设计。
经过这次的课程设计,我发现了自己在数据结构还存在许多薄弱环节,尤其是在实际进行实践的时候,发现了自己过去有存在理解错误的地方。本次课程设计结束后,我也打算再次加强自己对数据结构的学习,更深入地了解,同时加强自己在编程语言这方面的能力。