사람 이름은 string name,
나이는 int age로 저장하며,
public member로 선언된다.
class People은 class Person의 객체들을 저장한다.(힌트. vector에 저장하면 편하다)
method void addPerson(string _name, int _age)는 _name과 _age를 갖는 Person 객체를 만들어 저장한다.
method int getCount()는 저장된 Person 객체들의 수를 반환하며
method Person getPersonByName(string _name)은 이름 _name을 갖는 Person 객체를 반환한다.
method Person getOldestPerson (void)은 최고령자 Person 객체를 반환한다.
method int howManyUnderAge(int _age)는 인수 _age 미만의 (_age는 포함되지 않음) Person들의 명 수를 반환한다.
** 단, 모든 사람들의 이름과 나이는 다르다.
class Person과 class People을 정의하여
다음 main() 함수와 함께 동작할 수 있도록 하시오.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <iostream> #include <string> #include <vector> using namespace std; //--------------------------------------------- // // 이 곳에 Class People과 People를 정의하시오. // //--------------------------------------------- //----------이하 수정 금지 -------------------------- int main() { string name; int age = 20; People p; while (true) { getline(cin, name); cin >> age; cin.ignore(); if (age < 0) { break; } p.addPerson(name, age); } getline(cin, name); cout << p.getCount() << endl; Person _i = p.getPersonByName(name); cout << _i.name << " " << _i.age << endl; cout << p.getOldestPerson().name << endl; cout << p.howManyUnderAge(30) << endl; return 0; } |