프로그램 구현 연습


프로그램명 : 은행계좌 관리 프로그램


기능

1. 계좌개설

2. 입      금

3. 출      금

4. 전체 고객 잔액 조회


  • 통장의 계좌번호는 중복되지 아니한다 (중복검사 안하겠다는 뜻).
  • 입금 및 출금액은 무조건 0보다 크다 (오류 검사 안하겠다는 뜻).
  • 고객의 계좌정보는 계좌번호, 고객이름, 고객의 잔액, 세가지만 저장한다.
  • 둘 이상의 고객 정보 저장을 위해서 배열을 사용한다.
  • 계좌번호는 정수의 형태이다.

실행 예시

----------------Menu----------------

1.  계좌 개설

2. 입금

3. 출금

4. 계좌정보 전체 출력

5. 프로그램 종료

선택 : 1


[계좌 개설]

계좌 ID : 115

이    름 : secretpack

입금액  : 15000


위와 같이 계좌 개설이 진행된 다음에도 계속해서 메뉴가 출력되어 추가 메뉴 선택이 가능해진다.

다음은 앞서 입력한 정보를 대상으로 입금을 진행한 다음에 전체 정보를 출력하는 예이다.


----------------Menu----------------

1.  계좌 개설

2. 입금

3. 출금

4. 계좌정보 전체 출력

5. 프로그램 종료

선택 : 2


[입    금]

계좌 ID : 115

입금액  : 70

입금 완료


----------------Menu----------------

1.  계좌 개설

2. 입금

3. 출금

4. 계좌정보 전체 출력

5. 프로그램 종료

선택 : 4

계좌 ID : 115

이    름 : secretpack

잔    액 : 15070



메뉴에서 계좌정보 전체 출력을 선택하면 모든 계좌의 ID, 이름, 잔액정보가 출력되어야 한다.

위의 경우에는 저장된 계좌 정보가 하나이기 때문에 secretpack 한사람의 계좌 정보만 출력된 것이다.


프로그램 구현


  1. #include <iostream>  
  2. using namespace std;  
  3. const int name_len = 20;  
  4.   
  5. void show_menu(void); // menu  
  6. void make_bank(void); // 1. 계좌 개설  
  7. void input_money(void); // 2. 입금  
  8. void output_money(void); // 3. 출금  
  9. void info_bank(void); // 4. 계좌 정보  
  10.   
  11. typedef struct {  
  12.     int accID;  
  13.     int balance;  
  14.     char cusName[name_len];  
  15. }Accout;  
  16.   
  17. Accout accArr[100];  
  18. int accNum = 0;  
  19.   
  20. int main() {  
  21.     int menu;  
  22.   
  23.     while (1) {  
  24.   
  25.         show_menu();  
  26.         cout << "choice Number : "; cin >> menu;  
  27.   
  28.         if (menu == 5) {  
  29.             cout << "Program exit" << endl;  
  30.             break;  
  31.         }  
  32.   
  33.         else if (menu == 1)  
  34.             make_bank();  
  35.   
  36.         else if (menu == 2)  
  37.             input_money();  
  38.   
  39.         else if (menu == 3)  
  40.             output_money();  
  41.   
  42.         else if (menu == 4)  
  43.             info_bank();  
  44.   
  45.         else  
  46.             cout << "Wrong Number" << endl;  
  47.     }  
  48.     return 0;  
  49.   
  50. }  
  51.   
  52. void show_menu(void) {  
  53.     cout << "---------MENU---------" << endl;  
  54.     cout << "1. Make Account" << endl;  
  55.     cout << "2. Deposit Money" << endl;  
  56.     cout << "3. Withdraw Money" << endl;  
  57.     cout << "4. Show all info" << endl;  
  58.     cout << "5. Exit program" << endl;  
  59. }  
  60.   
  61. void make_bank(void) {  
  62.     int id;  
  63.     char name[name_len];  
  64.     int balance;  
  65.   
  66.     cout << endl;  
  67.     cout << "----------------------" << endl;  
  68.     cout << "[ Make Account ]" << endl;  
  69.     cout << "Account ID : "; cin >> id;  
  70.     cout << "Name: "; cin >> name;  
  71.     cout << "input money : "; cin >> balance;  
  72.     cout << "----------------------" << endl;  
  73.     cout << endl;  
  74.   
  75.     accArr[accNum].accID = id;  
  76.     accArr[accNum].balance = balance;  
  77.     strcpy(accArr[accNum].cusName, name);  
  78.     accNum++;  
  79. }  
  80.   
  81. void input_money(void) {  
  82.     int money;  
  83.     int id;  
  84.     cout << endl;  
  85.     cout << "----------------------" << endl;  
  86.     cout << "[ Deposit Money ]" << endl;  
  87.     cout << "Account ID : "; cin >> id;  
  88.     cout << "Input money : "; cin >> money;  
  89.     cout << "----------------------" << endl;  
  90.     cout << endl;  
  91.   
  92.     for (int i = 0; i < accNum; i++) {  
  93.         if (accArr[i].accID == id) {  
  94.             accArr[i].balance += money;  
  95.             cout << "Complete!!" << endl << endl;  
  96.             return;  
  97.         }  
  98.     }  
  99.     cout << "ID not found!!" << endl << endl;  
  100. }  
  101.   
  102. void output_money(void) {  
  103.     int money;  
  104.     int id;  
  105.     cout << endl;  
  106.     cout << "----------------------" << endl;  
  107.     cout << "[ With draw Money ]" << endl;  
  108.     cout << "Account ID : "; cin >> id;  
  109.     cout << "Output Money : "; cin >> money;  
  110.     cout << "----------------------" << endl;  
  111.     cout << endl;  
  112.   
  113.     for (int i = 0; i < accNum; i++) {  
  114.         if (accArr[i].accID == id) {  
  115.             if (accArr[i].balance < money) {  
  116.                 cout << "you haven't enough money" << endl << endl;  
  117.                 return;  
  118.             }  
  119.             accArr[i].balance -= money;  
  120.             cout << "Complete!!" << endl << endl;  
  121.             return;  
  122.         }  
  123.     }  
  124.     cout << "ID not found!!" << endl << endl;  
  125. }  
  126.   
  127. void info_bank(void) {  
  128.     for (int i = 0; i < accNum; i++) {  
  129.         cout << endl;  
  130.         cout << "-----INFORMATION------" << endl;  
  131.         cout << "Account ID : " << accArr[i].accID << endl;  
  132.         cout << "Name : " << accArr[i].cusName << endl;  
  133.         cout << "Your money  : " << accArr[i].balance << endl;  
  134.         cout << "----------------------" << endl;  
  135.         cout << endl;  
  136.     }  
  137. }  


'Language > C++' 카테고리의 다른 글

7. C++ 기본(7)  (0) 2016.12.13
6. C++ 기본(6)  (0) 2016.12.13
4. C++ 기본(4)  (0) 2016.12.11
3. C++ 기본(3)  (0) 2016.12.09
2. C++ 기본(2)  (0) 2016.12.09

+ Recent posts