C++주소록 관리 시스템 구현

본 논문 의 사례 는 C+주소록 관리 시스템 의 구체 적 인 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.

#include<iostream>
#include<string>
using namespace std;
#define MAX 1000
 
struct Person
{
 string m_Name;
 int m_Sex;
 int m_Age;
 string m_Phone;
 string m_Addr;
};
 
struct Addressbooks
{
 struct Person personArray[MAX];
 int m_Size;
};
 
void addPerson(Addressbooks * abs)
{
 if (abs->m_Size == MAX)
 {
 cout << "     ,    !" << endl;
 return;
 }
 else
 {
 string name;
 cout << "     :" << endl;
 cin >> name;
 abs->personArray[abs->m_Size].m_Name = name;
 
 cout << "     :" << endl;
 cout << "1 ---  " << endl;
 cout << "2 ---  " << endl;
 int sex = 0;
 
 while (true)
 {
 cin >> sex;
 if (sex == 1 || sex == 2)
 {
 abs->personArray[abs->m_Size].m_Sex = sex;
 break;
 }
 cout << "    ,     !" << endl;
 }
 
 cout << "     :" << endl;
 int age = 0;
 cin >> age;
 abs->personArray[abs->m_Size].m_Age = age;
 
 cout << "       :" << endl;
 string phone;
 cin >> phone;
 abs->personArray[abs->m_Size].m_Phone = phone;
 
 cout << "       :" << endl;
 string address;
 cin >> address;
 abs->personArray[abs->m_Size].m_Addr = address;
 
 abs->m_Size++;
 
 cout << "    " << endl;
 
 system("pause");
 system("cls");
 }
}
 
void showPerson(Addressbooks * abs)
{
 if (abs->m_Size == 0)
 {
 cout << "      " << endl;
 
 }
 else
 {
 for (int i = 0; i < abs->m_Size; i++)
 {
 cout << "  :" << abs->personArray[i].m_Name << "\t";
 cout << "  :" << (abs->personArray[i].m_Sex == 1 ? " ":" " ) << "\t";
 cout << "  :" << abs->personArray[i].m_Age << "\t";
 cout << "  :" << abs->personArray[i].m_Phone << "\t";
 cout << "  :" << abs->personArray[i].m_Addr << endl;
 
 }
 }
 system("pause");
 system("cls");
 
}
 
int isExist(Addressbooks * abs, string name)
{
 for (int i = 0; i < abs->m_Size; i++)
 {
 if (abs->personArray[i].m_Name == name)
 {
 return i;
 }
 }
 return -1; //   
}
 
//     
void deletePerson(Addressbooks * abs)
{
 cout << "          :" << endl;
 string name;
 cin >> name;
 
 int ret = isExist(abs, name);
 
 if (ret != -1)
 {
 for (int i = ret; i < abs->m_Size; i++)
 {
 abs->personArray[i] = abs->personArray[i + 1];
 }
 abs->m_Size--;
 cout << "    !" << endl;
 }
 system("pause");
 system("cls");
}
 
//     
void findPerson(Addressbooks * abs)
{
 cout << "          :" << endl;
 string name;
 cin >> name;
 
 int ret = isExist(abs, name);
 
 if (ret != -1)
 {
 cout << "  :" << abs->personArray[ret].m_Name << "\t";
 cout << "  :" << (abs->personArray[ret].m_Sex == 1 ? " " : " ") << "\t";
 cout << "  :" << abs->personArray[ret].m_Age << "\t";
 cout << "  :" << abs->personArray[ret].m_Phone << "\t";
 cout << "  :" << abs->personArray[ret].m_Addr << endl;
 }
 else
 {
 cout << "    " << endl;
 }
 system("pause");
 system("cls");
}
 
//     
void modifyPerson(Addressbooks * abs)
{
 cout << "          :" << endl;
 string name;
 cin >> name;
 
 int ret = isExist(abs, name);
 
 if (ret != -1)
 {
 string name;
 cout << "     :" << endl;
 cin >> name;
 abs->personArray[ret].m_Name = name;
 
 cout << "     :" << endl;
 cout << "1 ---  " << endl;
 cout << "2 ---  " << endl;
 int sex = 0;
 
 while (true)
 {
 cin >> sex;
 if (sex == 1 || sex == 2)
 {
 abs->personArray[ret].m_Sex = sex;
 break;
 }
 cout << "    ,     !" << endl;
 }
 
 cout << "     :" << endl;
 int age = 0;
 cin >> age;
 abs->personArray[ret].m_Age = age;
 
 cout << "       :" << endl;
 string phone;
 cin >> phone;
 abs->personArray[ret].m_Phone = phone;
 
 cout << "       :" << endl;
 string address;
 cin >> address;
 abs->personArray[ret].m_Addr = address;
 
 cout << "    " << endl;
 }
 else
 {
 cout << "    " << endl;
 }
 system("pause");
 system("cls");
}
 
//     
void cleanPerson(Addressbooks * abs)
{
 abs->m_Size = 0;
 cout << "      " << endl;
 
 system("pause");
 system("cls");
}
//    
void showMenu()
{
 cout << "*************************" << endl;
 cout << "***** 1、      *****" << endl;
 cout << "***** 2、      *****" << endl;
 cout << "***** 3、      *****" << endl;
 cout << "***** 4、      *****" << endl;
 cout << "***** 5、      *****" << endl;
 cout << "***** 6、      *****" << endl;
 cout << "***** 0、      *****" << endl;
 cout << "*************************" << endl;
 
}
 
int main() 
{
 Addressbooks abs;
 abs.m_Size = 0;
 int select = 0;
 
 while (true)
 {
 showMenu();
 
 cin >> select;
 switch (select)
 {
 case 1: //     
 addPerson(&abs);
 break;
 case 2: //     
 showPerson(&abs);
 break;
 case 3: //     
 /*{
 cout << "          :" << endl;
 string name;
 cin >> name;
 if (isExist(&abs, name) == -1)
 {
 cout << "    " << endl;
 }
 else
 {
 cout << "    " << endl;
 }
 }*/
 deletePerson(&abs);
 break;
 case 4: //     
 findPerson(&abs);
 break;
 case 5: //     
 modifyPerson(&abs);
 break;
 case 6: //     
 cleanPerson(&abs);
 break;
 case 0:
 cout << "      " << endl;
 system("pause");
 return 0;
 break;
 default:
 break;
 }
 }
 
 system("pause");
 return 0;
}
더 많은 학습 자 료 는 주제 인 에 주목 하 세 요.
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기