|
2025-04-28 20:47
조회: 329
추천: 5
과제용 클릭ㄴ#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; } } }
|
로스트아크 인벤 자유 게시판 게시판
인벤 전광판
[렘키드나] 한국에서 가장 이미지 좋은 게임이 무엇인지 아시나요?
[백염] 커뮤도 글쓰는놈들 눈에 익을정도로 ㅈ망해버렸네 ㅋ
로아 인벤 전광판 시작!!
[전국절제협회] 소멸의 왕, 절제가 하늘에 서겠다.





