Pseudo Code
여기서 To-do
뽑을 돈 입력 받기
#include <iostream> #include <string> using namespace std; class Account; class Bank; class ATM; class World; //---------Account--------- class Account { private: string name; // 계좌 주 이름 double account_num; // 계좌번호 int password; // 비밀번호 int balance; // 잔액 string bank; // 계좌 은행 public: Account(string bank_name, string user_name, double account_number, int user_password, int available_funds); string getBankName(); double getAccountNum(); int getPassword(); int getBalance(); void setBalance(int update_balance); // user_name : Account1, bank_name : Kakao, use_name :David, // account_number : 111-111-111111, available_funds (초기 잔액) : 5000 }; //---------------Account implementation Account::Account(string bank_name, string user_name, double account_number, int user_password, int available_funds) { this->bank = bank_name; this->name = user_name; this->account_num = account_number; this->password = user_password; this->balance = available_funds; cout << "[Account Constructor] Account ID: " << this->account_num << endl; } string Account::getBankName() { return this->bank; } double Account::getAccountNum() { return this->account_num; } int Account::getPassword() { return this->password; } int Account::getBalance() { return this->balance; } void Account::setBalance(int update_balance) { this->balance = update_balance; } //---------Bank--------- class Bank { private: string bank_name; Account* account_list[10]; // 모든 account의 리스트 int num_of_accounts; public: static ATM* atm_list[10]; // 모든 ATM 리스트 static int num_of_atm; // atm_list indexing 하기 위한 변수 static Bank* bank_list[10]; // 모든 bank의 list -> atm에서 사용하기 위함 static int num_of_bank; // bank_list indexing 하기 위한 변수 Bank(const string); void addATM(ATM* atm); // atm_list에 ATM을 추가하는 함수 void setAccount(Account*); // 계좌 추가 void getAccount(); // 관리하는 계좌들 출력 void setDeposit(Account*, int); // deposit 결과 계좌에 반영 bool verifyPassword(Account* account, int pw); // pw가 account 비번 맞는지 확인 Account* findAccount(double ID); string getBankName(); // bank name return Bank* getAllBank(); void printAllAccounts(); }; //---------------Bank implementation int Bank::num_of_atm = 0; // Initialize static variables int Bank::num_of_bank = 0; // Initialize static variables Bank* Bank::bank_list[10]; // Assuming a maximum of 10 banks ATM* Bank::atm_list[10]; // Assuming a maximum of 10 ATMs Bank::Bank(const string name) { this->bank_name = name; bank_list[num_of_bank] = this; // bank_list stack에 생성 num_of_bank++; cout << "[Bank Constructor] Bank name: " << this->bank_name << endl; } void Bank::addATM(ATM* atm) { // atm 추가, atm constructor에서 알아서 돌아감 atm_list[num_of_atm] = atm; // atm_list stack에 생성 num_of_atm++; } void Bank::setAccount(Account* account) { // 우리가 직접 치기 -> 자동으로 하기 account_list[num_of_accounts] = account; num_of_accounts++; } Bank* Bank::getAllBank() { return *bank_list; } void Bank::getAccount() { return; } void Bank::setDeposit(Account* account, int money) {} bool Bank::verifyPassword(Account* account, int pw) { if (account->getPassword() == pw) { return true; } return false; } Account* Bank::findAccount(double ID) { for (int i = 0; i < num_of_accounts; i++) { if (account_list[i]->getAccountNum() == ID) { return account_list[i]; } } return nullptr; } string Bank::getBankName() { return this->bank_name; } void Bank::printAllAccounts() { cout << "num of accounts: " << num_of_accounts << endl; for (int i = 0; i < num_of_accounts; i++) { cout << i << ". account number: " << account_list[i]->getAccountNum() << endl; } } //---------ATM--------- class ATM { private: int serial_type; // single bank 이면 1, multi bank 이면 2 Bank* serial_primary_bank; // primary bank의 ptr int serial_lang_type; // unilingual 이면 1, bilingual 이면 2 int count = 0; // authoriaztion 할 때 시도 횟수 세는 변수 -> withdraw 할 때로 바꿔야 할 듯,,, int num_of_1000; int num_of_5000; int num_of_10000; int num_of_50000; public: // Bank *bank_list[10]; int serial_num; // serial number Bank* current_bank; // 현재 사용중인 bank Account* current_acc; // 현재 사용중인 account double account_list[10]; // account list int available_cash; // ATM에 남은 돈 ATM(Bank* primary_bank, int serial_number, string type, string language, int initial_1000, int initial_5000, int initial_10000, int initial_50000); // multi bank ATM constructor void addBank(); bool authorization(double account_num); void deposit(); // 여기까지 구현함!! void withdrawal(); bool withdrawal_fee(); void StartSession(Bank** bank_list); bool authorization(); void EndSession(); }; //---------------ATM implementaion // Constructor ATM::ATM(Bank* primary_bank, int serial_number, string type, string language, int initial_1000, int initial_5000, int initial_10000, int initial_50000) { // primary bank setting serial_primary_bank = primary_bank; // atm의 bank serial_primary_bank->addATM( this); // Bank class의 static atm_list에 해당 ATM 추가 // serial number setting serial_num = serial_number; // bank type setting if (type == "Single Bank") { serial_type = 1; } else if (type == "Multi Bank") { serial_type = 2; } else { cout << "[Error] Please enter \"Single Bank\" or \"Multi Bank.\"" << endl; } // language type setting if (language == "Unilingual") { serial_lang_type = 1; } else if (language == "Bilingual") { serial_lang_type = 2; } else { cout << "[ERROR] Please enter \"Unillingual\" or \"Bilingual\"" << endl; } // initial cash setting this->num_of_1000 = initial_1000; // 지폐 갯수 this->num_of_5000 = initial_5000; // 지폐 갯수 this->num_of_10000 = initial_10000; // 지폐 갯수 this->num_of_50000 = initial_50000; // 지폐 갯수 cout << "[ATM Constructor] ATM serial number: " << this->serial_num << endl; cout << "serial type: " << serial_type << endl; cout << "serial lang: " << serial_lang_type << endl; } void ATM::addBank() {} // StartSession void ATM::StartSession(Bank** bank_list) { // bank list를 파라미터로 받아옴 // bank list에 item 어떻게 담아 넣을지 모르겠음 double account_num; // 계좌번호 // string bank_name; // 이 계좌의 은행이 어디인지 확인하는 변수 cout << "Insert card: "; cin >> account_num; // 계좌번호 입력받음 for (int i = 0; i < 10; i++) { // bank_list가 10개라서 이케함, len 따로 구해도 됨 this->current_acc = bank_list[i]->findAccount(account_num); if (current_acc != nullptr) { // 찾으면 break current_bank = bank_list[i]; break; } } if (this->authorization() == false) { cout << "Authorization failed" << endl; this->EndSession(); } int action = 0; try { while (action != 4) { // 이거 count로 하면 안될듯,,, cout << "Choose transaction" << endl; cout << "1.Deposit\t 2.Withdrawal\t3.Transfer\t4.Exit : "; cin >> action; cout << endl; if (action == 1) { //deposit(); count++; } else if (action == 2) { withdrawal(); count++; } else if (action == 3) { //transfer(); count++; } else if (action == 4) { break; } else { cout << "[ERROR] Please enter 1~4" << endl; } } } catch (int e) { return; } } // stop void ATM::EndSession() { throw 1; } // 3. User Authorization bool ATM::authorization() { cout << "Authorization Started" << endl; int password; // REQ3.1 카드가 atm 기기의 타입에 맞는 유효한 카드인지 확인함 // REQ3.2 유효하지 않으면 -> display error message(ex.”Invalid Card”) if ((this->serial_type == 1) && (current_acc->getBankName() != serial_primary_bank->getBankName())) { // ATM이 single bank ATM이면서 입력받은 계좌의 은행이 primary bank가 아닐 때 cout << "[ERROR] Invalid Card: the ATM is a single bank atm, and the card's bank is not the primary bank" << endl; return false; } // REQ3.3 사용자가 비밀번호를 입력하게하여 맞는지 확인 ( bank로 정보 넘겨서 확인받음 ) R // EQ3.4 비밀번호 틀렸으면 -> display error message cout << "Insert password: "; cin >> password; cout << endl; int count = 0; while ((current_bank->verifyPassword(current_acc, password)) != true) { cout << "[ERROR] Incorrect Password" << ends; count++; // REQ3.5 연속으로 3번 틀리면 session 끝나야함 if (count == 3) { cout << "Incorect Password 3 times in a row..." << endl; return false; // 여기선 비밀번호 틀림... -> end session } // 비밀번호 입력 횟수 3번 미만이면 다시 비밀번호 입력받음 cout << "Insert password: "; cin >> password; cout << endl; } return true; // 여기선 비밀번호 맞음... } /* // 4. Deposit void ATM::deposit() { int deposit_type; // 1 for cash deposit, 2 for check deposit int deposit_amount; // deposit 장수 int total_deposit; // deposit 총액 int cash_limit = 30; int deposit_1000; int deposit_5000; int deposit_10000; int deposit_50000; // REQ4.1 현금/수표 입력받음 cout << "What are you depositing?"; cout << "1.cash deposit\t2.check deposit\t3. Exit" << endl; cin >> deposit_type; cout << endl; // cash deposit 선택함 if (deposit_type == 1) { cout << "Insert the amount of cash you want to deposit." << endl; cin >> deposit_1000; cin >> deposit_5000; cin >> deposit_10000; cin >> deposit_50000; deposit_amount = deposit_1000 + deposit_5000 + deposit_10000 + deposit_50000; total_deposit = deposit_1000 * 1000 + deposit_5000 * 5000 + deposit_10000 * 10000 + deposit_50000 * 50000; // REQ4.2 개수 제한 넘으면 display error message if (deposit_amount > cash_limit) { cout << "[ERROR] " << endl; return; // !!! 에러 발생하면 바로 반환되는가, 아니면 while loop 이용해서 다시 입력받는가.. } // REQ4.4 이체 수수료 부과될 수 있음 if (non - primary bank deposit임) { total_deposit += 1000; } // REQ4.3 현금/수표 accept됨 -> 은행 계좌에 거래 결과 반영 // 계좌 잔액에 총 예금액 더해주는 Bank 클래스 함수 bank->setDeposit(this->current_acc, total_deposit); // REQ4.5 현금 -> ATM 기기의 available cash 늘어남 num_of_1000 += deposit_1000; num_of_5000 += deposit_5000; num_of_10000 += deposit_10000; num_of_50000 += deposit_50000; } // check deposit 선택함 else if (deposit_type == 2) { cout << "Insert the amount of check you want to deposit." << endl; cin >> deposit_amount; // 정확히 얼마짜리 수표가 몇장 들어왔는지도 입력되어야함… cin >> total_deposit; // 일단 임시로 총 금액 입력받는걸 가정 // REQ4.2 개수 제한 넘으면 display error message if (deposit_amount > check_limit) { cout << "[ERROR] " << endl; return // !!! } // REQ4.4 이체 수수료 부과될 수 있음 if (non - primary bank deposit임) { total_deposit += 1000; } // REQ4.3 현금/수표 accept됨 -> 은행 계좌에 거래 결과 반영 // 계좌 잔액에 총 예금액 더해주는 Bank 클래스 함수 bank->setDeposit(this->current_acc, total_deposit); // REQ4.6 수표 -> available cash 변화x } // 예외사항… else { cout << "[ERROR] " << endl; } } */ //5. Withdrawal void ATM::withdrawal() { // check는 withdrawal 불가능 int withdrawal_amount; // deposit 장수 int total_withdrawal; // deposit 총액 int cash_limit = 30; int denominationOfBills; // 지폐 종류 int sumOfWithdrawal = 0; int withdrawal_1000 = 0; int withdrawal_5000 = 0; int withdrawal_10000 = 0; int withdrawal_50000 = 0; int fund; // 각 session 당 withdrawal 횟수는 3회까지 if (count != 3) { // REQ5.1 An ATM shall ask a user to enter the amount of fund to withdra cout << "Insert the amount of cash you want to withdrawal." << endl; cout << "What denomination of bills would you like to withdraw? (1,000 won, 5,000 won, 10,000 won, 50,000 won)" << endl; cout << "please input 1000, 5000, 10000, 500000...: "; cin >> denominationOfBills; cout << endl; if (denominationOfBills == 1000){ cout << "How many bills of would you like to withdraw?" << endl; cout << "please input 1000, 2000, 3000...: "; cin >> sumOfWithdrawal; cout << endl; withdrawal_1000 = sumOfWithdrawal/1000; } else if (denominationOfBills == 5000){ cout << "How many bills of would you like to withdraw?" << endl; cout << "please input 5000, 10000, 15000...: "; cin >> sumOfWithdrawal; cout << endl; withdrawal_5000 = sumOfWithdrawal/5000; } else if (denominationOfBills == 10000){ cout << "How many bills of would you like to withdraw?" << endl; cout << "please input 10000, 20000, 30000...: "; cin >> sumOfWithdrawal; cout << endl; withdrawal_10000 = sumOfWithdrawal/10000; } else if (denominationOfBills == 50000){ cout << "How many bills of would you like to withdraw?" << endl; cout << "please input 50000, 100000, 150000...: "; cin >> sumOfWithdrawal; cout << endl; withdrawal_1000 = sumOfWithdrawal/1000; } // REQ5.2 An ATM shall display an appropriate error message if there is insufficient fund in the // account or insufficient cash in the ATM. if (num_of_1000 < withdrawal_1000 || num_of_5000 < withdrawal_5000 || num_of_10000 < withdrawal_10000 || num_of_50000 < withdrawal_50000) { cout << "[Error] There is not enough money in the ATM" << endl; cout << endl; } // ATM에 돈이 충분하지 않다면 Error 출력 else if (current_acc->getBalance() < sumOfWithdrawal) { cout << "[Error] There is not enough money in your account" << endl; cout << endl; } // REQ 5.7 The maximum amount of cash withdrawal per transaction is KRW 500,000. else if (500000 < sumOfWithdrawal) { cout << "[Error] Withdrawals over 500,000 won are not allowed" << endl; cout << endl; } // REQ5.3 Once the withdrawal is successful, the transaction must be reflected to the bank account // as well(i.e., the same amount of fund must be deducted from the corresponding bank account). // REQ5.5 The cash withdrawal lower available cash in the ATM that can be used by other users. else { // REQ5.4 Some withdrawal fee may be charged(See REQ in System Setup). if (withdrawal_fee() == true) { // 수수료 낼 수 있으면 // ATM에서 돈 빼기 num_of_1000 = num_of_1000 - withdrawal_1000; num_of_5000 = num_of_5000 - withdrawal_5000; num_of_10000 = num_of_10000 - withdrawal_10000; num_of_50000 = num_of_50000 - withdrawal_50000; // 계좌에서 돈 빼기 current_acc->setBalance(current_acc->getBalance() - sumOfWithdrawal); // 계좌/ATM에 남은 금액 출력 cout << "Success!" << endl; cout << endl; cout << "The remaining balance in your " << current_bank->getBankName() << " account is "; cout << current_acc->getBalance() << " won" << endl; cout << endl; cout << "The remaining 1000 in ATM : " << num_of_1000*1000 << endl; cout << "The remaining 5000 in ATM : " << num_of_5000*5000 << endl; cout << "The remaining 10000 in ATM : " << num_of_10000*10000 << endl; cout << "The remaining 50000 in ATM : " << num_of_50000*50000 << endl; cout << endl; } else { // 너 수수료 낼 돈 없어,, cout << "[Error] There is not enough money in your account" << endl; cout << endl; } } } else { cout << "[Error] If you want more withdrawal, Please restart session" << endl; cout << endl; } } bool ATM::withdrawal_fee() { // Withdrawal fee for a primary bank: KRW 1,000; the fee is paid from the withdrawal account. if (current_bank == serial_primary_bank) { if (current_acc->getBalance() < 1000) { // 수수료가 통장에 없는 경우 return false; } else { current_acc->setBalance(current_acc->getBalance() - 1000); // 1000원 수수료 // ATM에 수수료 추가 num_of_1000 = num_of_1000 + 1; return true; } } else { if (current_acc->getBalance() < 2000) { return false; } else { current_acc->setBalance(current_acc->getBalance() - 2000); // 2000원 수수료 // ATM에 수수료 추가 num_of_1000 = num_of_1000 + 2; return true; } } } //---------main--------- int main() { cout << "Start making Banks" << endl; Bank* kakao = new Bank("Kakao"); Bank* daegu = new Bank("Daegu"); cout << endl; cout << "Start making Accounts" << endl; Account* a1 = new Account("Kakao", "David", 111111111111, 1004, 5000); kakao->setAccount(a1); Account* a2 = new Account("Daegu", "Jane", 222222222222, 1234, 5000); daegu->setAccount(a2); Account* a3 = new Account("Kakao", "Kate", 333333333333, 2435, 5000); kakao->setAccount(a3); cout << endl; cout << "Start making ATMS" << endl; ATM* atm1 = new ATM(kakao, 111111, "Single Bank", "Unilingual", 5, 0, 0, 5); ATM* atm2 = new ATM(daegu, 222222, "Multi Bank", "Bilingual", 0, 1, 0, 0); ATM* atm3 = new ATM(daegu, 333333, "Multi Bank", "Bilingual", 0, 1, 0, 0); cout << endl; kakao->printAllAccounts(); cout << endl; daegu->printAllAccounts(); cout << endl; cout << "num of banks: " << Bank::num_of_bank << endl; for (int i = 0; i < Bank::num_of_bank; i++) { cout << "Bank #" << i << " : " << Bank::bank_list[i]->getBankName() << endl; } cout << endl; cout << "num of ATMs: " << Bank::num_of_atm << endl; for (int i = 0; i < Bank::num_of_atm; i++) { cout << "ATM #" << i << " : " << Bank::atm_list[i]->serial_num << endl; } cout << endl; atm1->StartSession(Bank::bank_list); return 0; }
#include <iostream> using namespace std; class Bank; class ATM; class Account; class Bank { public: }; class ATM { public: static ATM_verify; single 이면 0 / multi 이면 1 ATM(string primary_bank); // Single bank ATM constructor ATM(); // multi bank ATM constructor ATM* ATM_list[5]; // ATM obj 담을 수 있는 list -> 5개로 제한, 제한 안하면 이게 가능함??! int remaining_cash; // ATM에 남은 돈 void Withdrawal_process(Account* Account_obj); void Withdrawal_fee(Account* Account_obj); void PrintATMAll(); }; class Account { public: Account* Account_list[5]; // Account_obj 담을 수 있는 list -> 5개로 제한, 제한 안하면 이게 가능함??! int remaining_fund; // 계좌에 남은 돈 void Withdrawal(ATM* ATM_obj); void PrintAccountAll(); }; //------------------------------------------------------------------------ ATM void ATM::Withdrawal_process(Account* Account_obj) { int fund; cout << "Enter the amount of fund to withdraw" << endl; // REQ5.1 : cout cin >> fund; if (fund > 500000) { // 장수 // REQ5.7 : error message cout << "error message" << endl; } else { if (fund > remaining_cash or fund > Account_obj->remaining_fund) { // REQ5.2 : error message cout << "error massge" << endl; } else { // REQ5.3 : 성공 상황 cout << "Success!" << endl; // 돈 주기 remaining_cash = remaining_cash - fund; // cash - fund : REQ5.5 Account_obj->remaining_fund = Account_obj->remaining_fund - fund; // account - fund } } } void Withdrawal_fee(Account* Account_obj) { if single ATM 이라면{ Account_obj->remaining_fund - 1000; } else { if account와 ATM이 같은 은행꺼라면{ Account_obj->remaining_fund - 1000; } else { Account_obj->remaining_fund - 2000; } } } void ATM::PrintATMAll() { ATM_list[i]에 있는 것들 출력.. } //------------------------------------------------------------------------ Account void Account::Withdrawal(ATM* ATM_obj) { static int Witdrawal_counter = 0; Witdrawal_counter++; if (Witdrawal_counter == 3) { // 3번 되면 종료 cout << "you need to start again" << endl; } else { if single ATM 이라면{ if account와 ATM이 같은 은행꺼라면 { ATM_obj->Withdrawal_process(this); // ATM의 출금 프로세스 실행 ATM_obj->Withdrawal_fee(this); } else { cout << "error message"; } } else { ATM_obj->Withdrawal_process(this); // ATM의 출금 프로세스 실행 ATM_obj->Withdrawal_fee(this); } if Witdrawal 더 원하면{ Withdrawal(ATM * ATM_obj); } } } void Account::PrintAccountAll() { Account_list[i]에 있는 것들 출력.. } //------------------------------------------------------------------------ Main
![[Notion] :](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2Fc0389671-d63b-4c5d-a65d-5113fb1666a2%2Faf276f8d-c43c-4190-a784-11927a8f1c86%2F%25EB%2585%25B8%25EC%2585%2598_%25EC%2595%2584%25EC%259D%25B4%25EC%25BD%2598.png?table=block&id=244dd211-78d0-4c22-8c35-2efb01da5258&cache=v2)