//사람들의 first last 이름을 입력하는 코드를 작성하라.
//아래 코드와 주석을 이해하고 필요한 내용을 코딩함.
#include <iostream>
#include <string>
using namespace std;
class Name {
string first, last;
public:
string get_first() { return first; }
string get_last() { return last; }
void set_name(string f, string l); //first last 이름 적용
};
class PersonManager {
Name* p;
int nofp; //Name의 수, p의 크기
public:
PersonManager(int n); //생성자에서 p를 n크기로 동적 메모리 할당
// 생성자에서 n개의 Name을 입력 받아 p 배열에 입력
void show(); //모든 first last 이름 출력
int serarch(string str); // str과 같은 first 또는 last 이름의 수를 반환
~PersonManager();//메모리 반환 및 "delete [] p;" 출력
};
int main() {
int n;
cout << "Enter number of people." << endl;
cin >> n;
PersonManager people(n);
people.show();
cout << "Enter search name." << endl;
string str;
cin >> str;
cout << people.serarch(str) << endl;
return 0;
}
출력결과 예시로는
//(출력)Enter number of people.
//(입력)3
//(출력)Enter 3 first and last names.
//(입력)Mike Tyson
//(입력)Tyson Fury
//(입력)Ernie Shaver
//(출력)Mike Tyson
//(출력)Tyson Fury
//(출력)Fatal Fury
//(출력)Enter search name.
//(입력)Tyson
//(출력)2
//(출력)delete [] p;
이렇게 나오게 하고싶은데 클래스 선언부와 main 함수 사이에있는 클래스 구현부를 어떻게해야될지 모르겠습니다.