#include <iostream>
#include <string>
using namespace std;
const int MAX_phone = 20;
class phone
{
public:
phone() : m_count(0) { }
void Input()
{
if(m_count == MAX_phone)
{
cout << "더 이상 추가 할 수 없습니다." << endl;
return;
}
while(1)
{
string phone, name;
cout << "이름입력 : ";
cin >> name;
cout << "전화번호입력 : ";
cin >> phone;
m_name[m_count] = name;
m_phone[m_count] = phone;
m_count++;
if(m_count == MAX_phone)
{
cout << "더 이상 추가 할 수 없습니다." << endl;
break;
}
else
{
int sel;
cout << "1. 계속 2. 그만:";
cin >> sel;
if(sel == 2)
break;
}
}
}
void Delete()
{
if(m_count == 0)
{
cout << "등록된 전화번호가 없습니다." << endl;
return ;
}
string name;
cout << "삭제할 사람이름:";
cin >> name;
int sel;
cout << "1.삭제 2.취소:";
cin >> sel;
if(sel == 1)
{
for(int i = 0; i < m_count; i++)
{
if(m_name[i] == name)
{
for(int j = i; j < m_count-1; j++)
{
m_name[j] = m_name[j+1];
m_phone[j] = m_phone[j+1];
}
m_count--;
cout << "삭제되었습니다." << endl;
return;
}
}
cout << "해당되는 사람이 없습니다." << endl;
}
}
void Search()
{
if(m_count == 0)
{
cout << "등록된 전화번호가 없습니다." << endl;
return ;
}
while(1)
{
string name;
cout << "찾을 사람이름:";
cin >> name;
int count = 0;
for(int i = 0; i < m_count; i++)
{
if(m_name[i] == name)
{
cout << name << "의 전화번호=" << m_phone[i] << endl;
count++;
}
}
if(count)
cout << name << "은 " << count << "명 발견됨" << endl;
else
cout << "해당되는 사람이 없습니다." << endl;
int sel;
cout << "1. 계속 2. 그만:";
cin >> sel;
if(sel == 2)
break;
}
}
void Adjust()
{
if(m_count == 0)
{
cout << "등록된 전화번호가 없습니다." << endl;
return ;
}
string name;
cout << "변경할 사람이름:";
cin >> name;
int count = 0;
for(int i = 0; i < m_count; i++)
{
if(m_name[i] == name)
{
cout << "새로운전화번호:";
cin >> m_phone[i];
cout << "변경되었습니다." << endl;
return;
}
}
cout << "해당되는 사람이 없습니다" << endl;
}
private:
string m_phone[MAX_phone];
string m_name[MAX_phone];
int m_count;
};
void PrintMenu()
{
cout << "1. 입력" << endl;
cout << "2. 검색" << endl;
cout << "3. 삭제" << endl;
cout << "4. 수정" << endl;
cout << "5. 종료" << endl;
cout << "실행하고자 하는 작업의 번호를 입력하세요 : ";
}
int Menu()
{
PrintMenu();
int menu;
cin >> menu;
return menu;
}
void main()
{
phone j;
while(1)
{
switch(Menu())
{
case 1:
j.Input();
break;
case 2:
j.Search();
break;
case 3:
j.Delete();
break;
case 4:
j.Adjust();
break;
case 5:
return;
}
}
}
이 코드를 어떻게 나눠야 할까요?
뭐가 막힌다는건지 이해좀