Hi 各位大佬们好,我是初来乍到的agoni酱,现在是某大学电子信息工程的一位大一新生,由于我的大一上课程中有“C语言程序设计”,我通过自我学习再加上老师的引导,现在是处于C语言过渡到C++的过程,截至昨天学习到了class(类),暂时跟随黑马程序员C++课程学习(虽然老师跟我说不用看课程直接看C++之父的书但我直接去看真的有点难啊qwq还是英文版),这里算是我学习的一个小天地啦,请大家多多关照!!!谢谢大家!
这次的程序设计题目来源于黑马程序员C++课程的第一次程序设计(共四次)
基于数据结构链表实现通讯录管理系统,可实现添加,显示,删除,查找,修改,清空联系人等操作。
因为我处于C语言到C++即将过渡完成的时间节点,所以我采用的是链表完成这个此程序设计,里面涉及到大量指针的应用。由于链表特性,占用内存空间少,运用大量自定义函数,结构清晰,并且有完善的反馈机制,可以对联系人姓名进行重名检测,也可以检测通讯录是否为空,避免无效操作,而且有较完善的提示体系,可以轻松完成操作。
此程序完全由本人制作,并且仅在CSDN平台发布,虽然我是个小菜鸡,但也是不能商用的哦嘿嘿
/*
开发者:CSDN agoni酱
开发时间:2023年1月2日中午 完成时间:2023年1月2日晚上八点左右
最后发布时间:2023年1月3日11:24:54 开发环境:Visual Studio 2022 开发语言:C++
基本功能:基于数据结构链表实现通讯录管理系统,可实现添加,显示,删除,查找,修改,清空联系人等操作
功能特性:由于链表特性,占用内存空间少,运用大量自定义函数,结构清晰,并且有完善的反馈机制
*/
/*
当前版本:V 1.0
更新日志:暂无
*/
#include
using namespace std;
struct people {
string name;
string gender;
string age;
string phone;
string address;
people* next;
};
void showmenu();
void error();
int addpeople(people* p);
int judge(const int number);
void showpeople(people* p);
void printfpeople(people* p);
void change(people*p, int admin_in, people* p0);
void deletepeople(people* p);
void deleteallpeople(people* p);
people* search(people* p, string name);
people* before;
int main() {
int admin_in,number=0;
string name;
people* p0 = new people,*p;
p0->next = NULL;
showmenu();
while (1) {
cout << "system:请输入操作指令:";
cin >> admin_in;
switch (admin_in) {
case (1):
if (judge(number))
number += addpeople(p0);
break;
case (2):
showpeople(p0);
break;
case (3):
if (p0->next == NULL) {
cout << "system:通讯录为空!!!无法删除!" << endl; break;
}
cout << "system:请输入您想删除的名字:";
cin >> name;
if ((p = search(p0, name)) == NULL) {
cout << "system:无法查找到您想删除的联系人" << endl;
}
else {
printfpeople(p);
cout << "system:你确定删除\"" << p->name << "\"吗?确认请输入1,其它视为取消删除:";
cin >> admin_in;
if (admin_in != 1) {
cout << "system:取消删除!!!" << endl;
}
else {
deletepeople(p);
}
}
break;
case (4):
if (p0->next == NULL) {
cout << "system:通讯录为空!!!无需清空!" << endl; break;
}
cout << "system:请输入您想查找的名字:";
cin >> name;
if ((p = search(p0, name)) == NULL) {
cout << "system:无法查找到您所查找的名字" << endl;
}
else {
printfpeople(p);
cout << "system:查找成功!!!" << endl;
}
break;
case (5):
if (p0->next == NULL) {
cout << "system:通讯录为空!!!无法修改!" << endl; break;
}
cout << "system:请输入您想修改的名字:";
cin >> name;
if ((p = search(p0, name)) == NULL) {
cout << "system:无法查找到您想修改的联系人!" << endl;
}
else {
printfpeople(p);
last:
cout << "system:请输入您想修改的项目:1 姓名 2 性别 3 年龄 4 号码 5 地址:";
cin >> admin_in;
if (admin_in > 5 || admin_in <1) {
error();
goto last;
}
else {
change(p, admin_in,p0);
}
}
break;
case (6):
if (p0->next == NULL) {
cout << "system:通讯录为空!!!无需清空!" << endl; break;
}
cout << "system:你确定要清空通讯录吗?确认请输入1,其它视为取消清空:";
cin >> admin_in;
if (admin_in != 1) {
cout << "system:取消清空!!!" << endl;
}
else {
deleteallpeople(p0->next);
p0->next = NULL;
}
break;
case (7):
showmenu();
break;
case (0):
cout << "system:感谢使用,下次再会" << endl;
return 0;
default:
error();
break;
}
}
return 0;
}
void showmenu() {
cout << "****************************" << endl;
cout << "** 欢迎使用通讯录管理系统 **" << endl;
cout << "******* 1 添加联系人 *******" << endl;
cout << "******* 2 显示联系人 *******" << endl;
cout << "******* 3 删除联系人 *******" << endl;
cout << "******* 4 查找联系人 *******" << endl;
cout << "******* 5 修改联系人 *******" << endl;
cout << "******* 6 清空联系人 *******" << endl;
cout << "******* 7 显示主菜单 *******" << endl;
cout << "******* 0 退出通讯录 *******" << endl;
cout << "**** 制作:CSDN agoni酱 ****" << endl;
cout << "****************************" << endl;
}
void error() {
cout << "system:输入错误,请看清规则后重新输入!" << endl;
}
int judge(const int number) {
if (number >= 1000) {
cout << "system:最多记录1000人!!!" << endl;
return 0;
}
return 1;
}
int addpeople(people* p) {
people* new_p = new people,*p0;
last:
p0 = p;
cout << "system:请输入该联系人的姓名:";
cin >> new_p->name;
while (p0->next != NULL && p0->name != new_p->name) {
p0 = p0->next;
}
if (p0->name == new_p->name) {
cout << "system:输入姓名重复!!!请重新输入!" << endl;
goto last;
}
p0->next = new_p;
cout << "system:请输入\"" << new_p->name << "\"的性别:";
cin >> new_p->gender;
cout << "system:请输入\"" << new_p->name << "\"的年龄:";
cin >> new_p->age;
cout << "system:请输入\"" << new_p->name << "\"的号码:";
cin >> new_p->phone;
cout << "system:请输入\"" << new_p->name << "\"的地址:";
cin >> new_p->address;
cout << "system:添加联系人\"" << new_p->name << "\"成功!!!" << endl;
new_p->next = NULL;
return 1;
}
void showpeople(people* p) {
if (p->next == NULL) {
cout << "system:通讯录为空!!!" << endl;
}else while ((p = p->next) != NULL)
printfpeople(p);
}
people* search(people* p , string name) {
while (p!= NULL && p->name != name) {
before = p;
p = p->next;
}
if (p == NULL)
return NULL;
return p;
}
void printfpeople(people* p) {
cout << "system:姓名:" << p->name << " 性别:" << p->gender << " 年龄:" << p->age << " 号码:" << p->phone << " 地址:" << p->address << endl;
}
void change(people* p, int admin_in , people* p0) {
string in;
people* new_p;
last:
new_p = p0;
cout << "system:修改为:";
cin >> in;
switch (admin_in) {
case(1):
while (new_p->next != NULL && new_p->name != in) {
new_p = new_p->next;
}
if (new_p->name == in) {
cout << "system:输入姓名重复!!!请重新输入!" << endl;
goto last;
}
new_p->name = in;
p = new_p;
break;
case(2):
p->gender = in;
break;
case(3):
p->age = in;
break;
case(4):
p->phone = in;
break;
case(5):
p->address = in;
break;
}
cout << "system:修改成功!!!更正为:" << endl ;
printfpeople(p);
}
void deletepeople(people* p) {
before->next = p->next;
delete(p);
cout << "system:删除成功!!!" << endl;
}
void deleteallpeople(people* p) {
while (p != NULL) {
before = p;
p = p->next;
delete (before);
}
cout << "system:清空成功!!!" << endl;
}
// THE END
这是我第一次发布文章啦,如有不妥麻烦您能够提出来!!!如果您对代码有建议可以私信我哦,感谢大家的支持,感谢观看,我们,很快再见!