프로그램 구현 연습
프로그램명 : 은행계좌 관리 프로그램
기능
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 한사람의 계좌 정보만 출력된 것이다.
프로그램 구현
- #include <iostream>
- using namespace std;
- const int name_len = 20;
- void show_menu(void); // menu
- void make_bank(void); // 1. 계좌 개설
- void input_money(void); // 2. 입금
- void output_money(void); // 3. 출금
- void info_bank(void); // 4. 계좌 정보
- typedef struct {
- int accID;
- int balance;
- char cusName[name_len];
- }Accout;
- Accout accArr[100];
- int accNum = 0;
- int main() {
- int menu;
- while (1) {
- show_menu();
- cout << "choice Number : "; cin >> menu;
- if (menu == 5) {
- cout << "Program exit" << endl;
- break;
- }
- else if (menu == 1)
- make_bank();
- else if (menu == 2)
- input_money();
- else if (menu == 3)
- output_money();
- else if (menu == 4)
- info_bank();
- else
- cout << "Wrong Number" << endl;
- }
- return 0;
- }
- void show_menu(void) {
- cout << "---------MENU---------" << endl;
- cout << "1. Make Account" << endl;
- cout << "2. Deposit Money" << endl;
- cout << "3. Withdraw Money" << endl;
- cout << "4. Show all info" << endl;
- cout << "5. Exit program" << endl;
- }
- void make_bank(void) {
- int id;
- char name[name_len];
- int balance;
- cout << endl;
- cout << "----------------------" << endl;
- cout << "[ Make Account ]" << endl;
- cout << "Account ID : "; cin >> id;
- cout << "Name: "; cin >> name;
- cout << "input money : "; cin >> balance;
- cout << "----------------------" << endl;
- cout << endl;
- accArr[accNum].accID = id;
- accArr[accNum].balance = balance;
- strcpy(accArr[accNum].cusName, name);
- accNum++;
- }
- void input_money(void) {
- int money;
- int id;
- cout << endl;
- cout << "----------------------" << endl;
- cout << "[ Deposit Money ]" << endl;
- cout << "Account ID : "; cin >> id;
- cout << "Input money : "; cin >> money;
- cout << "----------------------" << endl;
- cout << endl;
- for (int i = 0; i < accNum; i++) {
- if (accArr[i].accID == id) {
- accArr[i].balance += money;
- cout << "Complete!!" << endl << endl;
- return;
- }
- }
- cout << "ID not found!!" << endl << endl;
- }
- void output_money(void) {
- int money;
- int id;
- cout << endl;
- cout << "----------------------" << endl;
- cout << "[ With draw Money ]" << endl;
- cout << "Account ID : "; cin >> id;
- cout << "Output Money : "; cin >> money;
- cout << "----------------------" << endl;
- cout << endl;
- for (int i = 0; i < accNum; i++) {
- if (accArr[i].accID == id) {
- if (accArr[i].balance < money) {
- cout << "you haven't enough money" << endl << endl;
- return;
- }
- accArr[i].balance -= money;
- cout << "Complete!!" << endl << endl;
- return;
- }
- }
- cout << "ID not found!!" << endl << endl;
- }
- void info_bank(void) {
- for (int i = 0; i < accNum; i++) {
- cout << endl;
- cout << "-----INFORMATION------" << endl;
- cout << "Account ID : " << accArr[i].accID << endl;
- cout << "Name : " << accArr[i].cusName << endl;
- cout << "Your money : " << accArr[i].balance << endl;
- cout << "----------------------" << endl;
- cout << endl;
- }
- }
'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 |