C++간이 주소록 구현

8278 단어 C++통신 록
본 논문 의 사례 는 여러분 에 게 C+간이 주소록 을 실현 하 는 구체 적 인 코드 를 공유 하 였 으 며,여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.

#include <iostream>
#include <string>
#define MAX 1000
using namespace std;

//          
struct Person 
{
 string m_Name;
 int m_Sex;  // 1、   2  
 int m_Age;
 string m_Phone;
 string m_Addr;
};

//          
struct Addressbooks
{
 struct Person personArray[MAX];
 int m_Size;
};


// 1、    
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;
}
// 2、     
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---- 
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"); // } } // 3、 void showPerson(Addressbooks * abs) { // 0 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"); } // 4、 , , // 1 2 int isExit(Addressbooks * abs, string name) { for (int i = 0; i < abs->m_Size; i++) { if (abs->personArray[i].m_Name == name) { return i; // , } } return -1; // , -1 } // 5、 void deletePerson(Addressbooks * abs) { cout << " :" << endl; string name; cin >> name; int ret = isExit(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; } else { cout << " " << endl; } system("pause"); system("cls"); } // 6、 void findPerson(Addressbooks * abs) { cout << " :" << endl; string name; cin >> name; int ret = isExit(abs, name); if (ret != -1) { cout << " :" << abs->personArray[ret].m_Name << "\t"; cout << " :" << abs->personArray[ret].m_Sex << "\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"); } // 7、 void modifyPerson(Addressbooks * abs) { cout << " :" << endl; string name; cin >> name; int ret = isExit(abs, name); if (ret != -1) { string name; cout << " :" << endl; cin >> name; abs->personArray[ret].m_Name = name; cout << " :" << endl; cout << "1--- \t2--- " << endl; int sex = 0; //cin >> sex; 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; } else { cout << " " << endl; } system("pause"); system("cls"); } // 8、 void cleanPerson(Addressbooks * abs) { abs->m_Size = 0; cout << " !!!" << endl; system("pause"); system("cls"); } int main() { // Addressbooks abs; // 0 abs.m_Size = 0; int select = 0; while (true) { // showMenu(); cin >> select; switch (select) { case 1: // 1、 addPerson(&abs); // break; case 2: // 2、 showPerson(&abs); break; case 3: // 3、 deletePerson(&abs); /* { cout << " :" << endl; string name; cin >> name; if (isExit(&abs, name) == -1) { cout << " " << endl; } else { cout << " " << endl; } }*/ break; case 4: // 4、 findPerson(&abs); break; case 5: // 5、 modifyPerson(&abs); break; case 6: // 6、 cleanPerson(&abs); break; case 0: // 0、 cout << " " << endl; system("pause"); return 0; break; default: break; } } system("pause"); return 0; }
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기