龙空技术网

基于C++的通讯录管理系统设计(初版)

逗比小憨憨 2255

前言:

此时你们对“c语言课程设计电话簿管理系统报告”大概比较注意,我们都需要了解一些“c语言课程设计电话簿管理系统报告”的相关资讯。那么小编同时在网络上搜集了一些有关“c语言课程设计电话簿管理系统报告””的相关内容,希望大家能喜欢,大家快快来了解一下吧!

基于C++的通讯录管理系统设计(初版)

要求:

1,具有添加联系人功能

2,具有删除联系人功能

3,具有修改联系人功能

4,具有查找联系人功能

5,具有清空所有联系人功能

注意:此次设计主要是为了让大家巩固一下C语言相关知识点(如:结构体,指针的使用),同时也熟悉C++基础语法,为今后的单片机开发或嵌入式开发打下更好的软件编程基础。因此编写的程序并不涉及文件操作等知识点。

此次设计在B站(UP主:逗比小憨憨)最近直播讲解过。

以下是源码:(还需自己进一步完善和调试,基本功能已实现)

#include "Address_Book_Management_System.h"//display menu functionvoid Show_Menu(void){  cout << "******  1,添加联系人  ******" << endl;  cout << "******  2,显示联系人  ******" << endl;  cout << "******  3,删除联系人  ******" << endl;  cout << "******  4,查找联系人  ******" << endl;  cout << "******  5,修改联系人  ******" << endl;  cout << "******  6,清空联系人  ******" << endl;  cout << "******  7,退出通讯录  ******" << endl;}//添加联系人int Add_Person(struct AddressList *addperson){  if (addperson->size == MAX)  {    cout << "通讯录已满 无法添加" << endl;    return -1;  }  else  {    //添加联系人    string name;    cout << "请输入欲添加联系人的名字:" << endl;    cin >> name;    addperson->person_arr[addperson->size].name = name;    cout << "请输入欲添加联系人的性别:" << endl;    cout << "6 ---- 男" << endl;    cout << "9 ---- 女" << endl;    int gender;    for(;;)    {      cout << "请输入欲添加联系人的性别:" << endl;      cin >> gender;      if((gender == 6) || (gender == 9))      {        addperson->person_arr[addperson->size].gender = gender;        break;      }      else      {        cout << "输入有误,请重新输入!!!" << endl;      }    }    int age;    for(;;)    {      cout << "请输入欲添加联系人的年龄:" << endl;      cin >> age;      if((age >= 1) && (age <= 150))      {        addperson->person_arr[addperson->size].age = age;        break;      }      else      {        cout << "输入有误,请重新输入!!!" << endl;      }    }    string phone_num;    for(;;)    {      cout << "请输入欲添加联系人的联系电话:" << endl;      cin >> phone_num;      if( phone_num.length() == 11)      {        addperson->person_arr[addperson->size].phone_num = phone_num;        break;      }      else      {        cout << "输入有误,请重新输入!!!" << endl;      }    }    string addr;    cout << "请输入欲添加联系人的地址:" << endl;    cin >> addr;    addperson->person_arr[addperson->size].addr = addr;  }    cout << "<添加联系人成功>" << endl;  /*cout << "测试" << endl;  cout << "您添加的信息为:" << endl;  cout << addperson->person_arr[addperson->size].name << addperson->person_arr[addperson->size].gender     << addperson->person_arr[addperson->size].age  << addperson->person_arr[addperson->size].phone_num     <<addperson->person_arr[addperson->size].addr  << endl;*/  addperson->size ++;//名单+1  system("pause");  system("cls");//清屏  return 0;}//显示通讯录int Dispaly_Person(const struct AddressList *addperson){  if(addperson->size == 0)  {    cout << "当前通讯录为空" << endl;  }  else  {    for(int i = 0; i < addperson->size; i ++)    {      cout << "通讯录名单人员" << i+1 << endl;      cout << "姓名:" << addperson->person_arr[i].name << '\t';      cout << "性别:" << (addperson->person_arr[i].gender == 6 ? "男": "女") << '\t';      cout << "年龄:" << addperson->person_arr[i].age << '\t';      cout << "电话:" << addperson->person_arr[i].phone_num << '\t';      cout << "地址:" << addperson->person_arr[i].addr << endl;    }  }  system("pause");  system("cls");//清屏  return 0;}//main menu functionint Main_Menu(void){  struct AddressList addresslist;  addresslist.size = 0;  int select = 7;//select show menu    while(1)  {    Show_Menu();    cout << "请选择功能:" << endl;    cin >> select;    switch(select)    {    case 1:      Add_Person(&addresslist);      break;            //1,添加联系人    case 2:      Dispaly_Person(&addresslist);      break;            //2,显示联系人    case 3:      Del_Person(&addresslist);      break;            //3,删除联系人    case 4:      LookUp_Menu(&addresslist);      break;            //4,查找联系人    case 5:      Modify_Person(&addresslist);      break;            //5,修改联系人    case 6:      Clean_AddressList(&addresslist);      break;            //6,清空联系人    case 7:      cout << "通讯录管理系统已退出" << endl;      return 0;//7,退出通讯录    default:break;//非法操作    }  }}/*  函数名:根据人名 检测联系人  描述:      如果存在联系人,则返回具体位置      否则,则返回-1  注意:关于通讯录中同名的情况,这里不加考虑*/int Check_Person_Name(const struct AddressList *addperson ,string name){  int i = 0;  int flag = MAX + 1;  for(i; i < addperson->size; i ++)  {    if(name == addperson->person_arr[i].name)    {      flag = i;      break;//测试      //return i;      }  }    //测试  if (i <= addperson->size)  {    cout << "通讯录名单人员" <<endl;    cout << "姓名:" << addperson->person_arr[flag].name << '\t';    cout << "性别:" << (addperson->person_arr[flag].gender == 6 ? "男": "女") << '\t';    cout << "年龄:" << addperson->person_arr[flag].age << '\t';    cout << "电话:" << addperson->person_arr[flag].phone_num << '\t';    cout << "地址:" << addperson->person_arr[flag].addr << endl;    return flag;//没查到  }  else  {    return -1;  }}//删除联系人void Del_Person(struct AddressList *addperson){  int ret = -1;  cout << "进入删除联系人功能,谨慎操作!!!" << endl;  cout << "请输入您要删除的联系人的姓名:" << endl;  string name;  cin >> name;  ret = Check_Person_Name(addperson,name);  if(ret == -1)  {    cout << "查无此人" << endl;  }  else//查到  {    for(int i = ret; i < addperson->size; i++)    {      addperson->person_arr[i] = addperson->person_arr[i + 1] ;    }    addperson->size --;    cout << "删除成功" << endl;  }  system("pause");  system("cls");//清屏}int Check_Person_Age(const struct AddressList *addperson ,int age){  return 0;}int Check_Person_Gender(const struct AddressList *addperson ,int gender){  return 0;}int Check_Person_Phone_num(const struct AddressList *addperson ,string phone_num){  return 0;}int Check_Person_Addr(const struct AddressList *addperson ,string addr){  return 0;}//查找联系人小菜单int LookUp_Menu(const struct AddressList *addperson){  int select = 0;  while(true)  {    cout << "******  1,按名字查找    ******" << endl;    cout << "******  2,按性别查找    ******" << endl;    cout << "******  3,按年龄查找    ******" << endl;    cout << "******  4,按电话查找    ******" << endl;    cout << "******  5,按地址查找    ******" << endl;    cout << "******  6,退出查找功能  ******" << endl;      cout << "请选择功能:" << endl;    cin >> select;    switch(select)    {    case 1:      {        string name;        cout << "请输入待查找联系人的名字:" <<endl;        cin >> name;        if(Check_Person_Name(addperson,name));//not modify        break;          }    case 2://not modify      {        int  gender;        cout << "请输入待查找联系人的性别:" <<endl;        cin >> gender;        Check_Person_Gender(addperson,gender);        break;      }    case 3:      {        int  age;        cout << "请输入待查找联系人的年龄:" <<endl;        cin >> age;        Check_Person_Age(addperson,age);        break;      }    case 4:      {        string  phone_num;        cout << "请输入待查找联系人的电话:" <<endl;        cin >> phone_num;        Check_Person_Phone_num(addperson,phone_num);        break;      }    case 5:      {        string  addr;        cout << "请输入待查找联系人的地址:" <<endl;        cin >> addr;        Check_Person_Addr(addperson,addr);        break;      }    case 6:      {        cout << "退出查找功能" << endl;        system("pause");        system("cls");//清屏        return 0;//7,退出通讯录      }    default:break;//非法操作    }    select = 0;    system("pause");    system("cls");//清屏  }  system("pause");  system("cls");//清屏  return 0;}//修改联系人信息,根据姓名进行修改void Modify_Person(struct AddressList *addperson ){  int ret;  struct Person temp;  string name;  cout << "进入通讯录修改模式" << endl;  cout << "输入欲修改信息的名字:"<< endl;  cin >> name;  ret = Check_Person_Name(addperson,name);  if(ret == -1)  {    cout << "查无此人,无法进行信息修改!!!" << endl;    return ;  }  else  {    cout << "通讯录中查到此人" << endl;    cout << "请输入修改相关信息:"<< endl;    cout << "请输入修改后的姓名:"<< endl;    //string name;    cin >> temp.name;    //addperson->person_arr[ret].name = name;    cout << "请输入修改后的性别:"<< endl;    //int gender;    cin >> temp.gender;    //addperson->person_arr[ret].gender = gender;    cout << "请输入修改后的年龄:"<< endl;    //int age;    cin >> temp.age;    //addperson->person_arr[ret].age = age;    cout << "请输入修改后的电话:"<< endl;    //string phone_num;    cin >> temp.phone_num;    //addperson->person_arr[ret].phone_num = phone_num;    cout << "请输入修改后的地址:"<< endl;    //string addr;    cin >> temp.addr;    //addperson->person_arr[ret].addr = addr;    cout << "修改后的信息如下:" << endl;    cout << "姓名:"   << temp.name << '\t'       << "性别:"   << temp.gender<< '\t'         << "年龄:"   << (temp.age == 6 ?"男":"女")<< '\t'         << "电话号码:" << temp.phone_num<< '\t'       << "地址:"     <<temp.addr  << endl;    cout << "是否确认修改" << endl;    int enter = 0;    cout << "1,确认修改" << endl;    cout << "其它键取消"  << endl;    cin >> enter;    if(enter == 1)    {      addperson->person_arr[ret] = temp;        cout << "修改成功" << endl;    }    else    {      cout << "取消修改" << endl;    }      }  system("pause");  system("cls");//清屏  }//清空通讯录void Clean_AddressList(struct AddressList *addperson){  int method = 0;  cout << "请选择清空方式:" << endl;  cout << "1,物理清空" << endl;  cout << "2,逻辑清空" << endl;  cin >> method;  if(method == 1)  {    //物理清空    cout << "此功能暂时无法使用" << endl;  }  else if(method == 2)  {    addperson->size = 0;//逻辑清空    cout << "通讯录已清空" << endl;  }  else    cout << "输入有误" << endl;  system("pause");  system("cls");//清屏}

#ifndef __Address_Book_Management_System_H#define __Address_Book_Management_System_H#include <iostream>#include <string>using namespace std;struct Person{  string name;       //姓名  int gender;        //性别  int age;           //年龄  string phone_num;  //电话号码  string addr;       //住址};#define MAX 100   //通讯录中最大的数量struct AddressList {  struct Person person_arr[MAX];//通讯录名单  int size;//通讯录当前记录的个数};void Show_Menu(void);int Add_Person(struct AddressList *addperson);int Dispaly_Person(const struct AddressList *addperson);int Main_Menu(void);int Check_Person_Name(const struct AddressList *addperson ,string name);void Del_Person(struct AddressList *addperson);int Check_Person_Age(const struct AddressList *addperson ,int age);int Check_Person_Gender(const struct AddressList *addperson ,int gender);int Check_Person_Phone_num(const struct AddressList *addperson ,string phone_num);int Check_Person_Addr(const struct AddressList *addperson ,string addr);int LookUp_Menu(const struct AddressList *addperson);void Modify_Person(struct AddressList *addperson);void Clean_AddressList(struct AddressList *addperson);#endif
#include "Address_Book_Management_System.h"int main(){  Main_Menu();  system("pause");  return 0;}

更多精彩内容:

微信公众号 或 今日头条号 或 B站 搜索并关注 “逗比小憨憨”

标签: #c语言课程设计电话簿管理系统报告