#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>

using namespace std;

class Account {
private:
    string id;
    int balance;
    string name;

public:
    Account() : id(""), balance(0), name("") {}
    Account(const string& id, const string& name) : id(id), balance(0), name(name) {}

    Account(const Account& copy) : id(copy.id), balance(copy.balance), name(copy.name) {}

    string getId() const { return id; }

    void deposit(int amount) {
        balance += amount;
    }

    void withdraw(int amount) {
        balance -= amount;
    }

    void showInfo() const {
        cout << "계좌번호: " << id
            << ", 이름: " << name
            << ", 잔액: " << balance << "원" << endl;
    }
};

Account accounts[100];
int idcnt = 0;

int findAccountIndex(const string& id) {
    for (int i = 0; i < idcnt; ++i) {
        if (accounts[i].getId() == id)
            return i;
    }
    return -1;
}

void MakeAccount() {
    string id;
    string name;

    cout << "계좌번호 입력: ";
    cin >> id;

    cin.ignore();
    cout << "이름 입력: ";
    getline(cin, name);

    accounts[idcnt++] = Account(id, name);
    cout << "계좌 개설 완료." << endl;
}

void Deposit() {
    string id;
    int money;
    cout << "입금할 계좌번호 입력: ";
    cin >> id;

    int index = findAccountIndex(id);
    if (index != -1) {
        cout << "입금액 입력: ";
        cin >> money;
        accounts[index].deposit(money);
        cout << "입금 완료." << endl;
    }
    else {
        cout << "계좌를 찾을 수 없습니다." << endl;
    }
}

void Withdraw() {
    string id;
    int money;
    cout << "출금할 계좌번호 입력: ";
    cin >> id;

    int index = findAccountIndex(id);
    if (index != -1) {
        cout << "출금액 입력: ";
        cin >> money;
        accounts[index].withdraw(money);
        cout << "출금 완료." << endl;
    }
    else {
        cout << "계좌를 찾을 수 없습니다." << endl;
    }
}

void ShowAllBalances() {
    cout << "n--- 전체 고객 잔액 조회 ---" << endl;
    for (int i = 0; i < idcnt; ++i) {
        accounts[i].showInfo();
    }
}

int main() {
    int num;
    while (true) {
        cout << "n--------------------------" << endl;
        cout << "1. 계좌개설" << endl;
        cout << "2. 입금" << endl;
        cout << "3. 출금" << endl;
        cout << "4. 전체고객 잔액조회" << endl;
        cout << "0. 종료" << endl;
        cout << "--------------------------" << endl;
        cout << "메뉴 선택: ";
        cin >> num;

        if (cin.fail()) {
            cin.clear();
            cin.ignore(1000, 'n');
            cout << "잘못된 입력입니다. 숫자를 입력하세요." << endl;
            continue;
        }

        switch (num) {
        case 1: MakeAccount(); break;
        case 2: Deposit(); break;
        case 3: Withdraw(); break;
        case 4: ShowAllBalances(); break;
        case 0:
            cout << "프로그램을 종료합니다." << endl;
            return 0;
        default:
            cout << "잘못된 메뉴입니다." << endl;
        }
    }
}