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
#include <iostream>
#include <string>
using namespace std;
 
class Person {
    string name;
    string tel;
public:
    Person() {}
    string getName() { return name; }
    string getTel() { return tel; }
    void set(string name, string tel) { this->name = name; this->tel = tel; }
};
 
int main() {
    string name, tel;
    Person p[3];
    cout << "이름과 전화 번호를 입력해 주세요" << endl;
    for (int i = 0; i < 3; i++) {
        cout << "사람 " << i + 1 << ">> ";
        getline(cin, name, ' ');
        getline(cin, tel, '\n');
        p[i].set(name, tel);
    }
    cout << "모든 사람의 이름은 ";
    for (int i = 0; i < 3; i++) {
        cout << p[i].getName() << ' ';
    }
    cout << endl;
    cout << "전화번호 검색합니다. 이름을 입력하세요>>";
    cin >> name;
    for (int i = 0; i < 3; i++) {
        if (p[i].getName() == name) {
            cout << "전화 번호는 " << p[i].getTel() << endl;
            break;
        }
    }
}
cs

+ Recent posts