C++通信録の基本機能を実現【コード】+【説明】


C++版動的通信録
きほんきのう
1.連絡先を追加する;2.連絡先を削除する;3.連絡先を探す;4.連絡先の修正・;5.連絡先を印刷する;6.連絡先を空にする.0.通信録を終了する
コードは次のとおりです.
#define _CRT_SECURE_NO_WARNINGS 1
#include 
#include 
#define MAX 1000//         
using namespace std;

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 shouMenu()
{
     
	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;
	cout << "             " << endl;

}

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;
		}
		int age;
		cout << "     :" << endl;
		cin >> age;
		abs->personArray[abs->m_Size].m_Age = age;
		string phone;
		cout << "     :" << endl;
		cin >> phone;
		abs->personArray[abs->m_Size].m_Phone = phone;
		string addr;
		cout << "     :" << endl;
		cin >> addr;
		abs->personArray[abs->m_Size].m_Addr = addr;
		cout << "    !" << endl;
		abs->m_Size++;
		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 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
}

void deletePerson(Addressbooks * abs)// 
{
     
	cout << "             " << endl;
	string name;
	cin >> name;
	//ret==-1    
	//ret!=-1   
	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");
}

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 == 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 = isExit(abs, name);
	if (ret != -1)
	   {
     
		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;
		}
		int age;
		cout << "     :" << endl;
		cin >> age;
		abs->personArray[ret].m_Age = age;
		string phone;
		cout << "     :" << endl;
		cin >> phone;
		abs->personArray[ret].m_Phone = phone;
		string addr;
		cout << "     :" << endl;
		cin >> addr;
		abs->personArray[ret].m_Addr = addr;
		cout << "    !" << endl;
	   }
	else
	  {
     
		cout << "       " << endl;
	  }
	system("pause");
	system("cls");
}

void cleanPerson(Addressbooks * abs)
{
     
	abs->m_Size = 0;
	cout << "       !" << endl;
	system("pause");
	system("cls");
}

int main()
{
     
	Addressbooks abs;//          
	abs.m_Size = 0;//            
	int select = 0;
	while (true)
	{
     
		shouMenu();
	cin >> select;
	switch (select)
	{
     
	case 1:// 
		addPerson(&abs);
		break;
	case 2:// 
		deletePerson(&abs);
		break;
	case 3:// 
		findPerson(&abs);
		break;
	case 4:// 
		modifyPerson(&abs);
		break;
	case 5://  
		showPerson(&abs);
		break;
	case 6://  
		cleanPerson(&abs);
		break;
	case 0://  
		cout << "      " << endl;
		system("pause");
		return 0;
		break;
	default:
		break;

	}
	}
	system("pause");
	return 0;
}

基本機能を満たすC++アドレス帳が実現しますので、興味のある方はぜひ試してみてください!皆さんのコメントを歓迎します.