y0u_bat
[열혈C++] 단계별 OOP 프로젝트 1단계 본문
info.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | typedef struct bank { int no; int id; int money; char name[100]; struct bank *prev; struct bank *next; } Bank; typedef struct LIST { struct bank *head,*tail; } List; void init(List *list); void insert_id(List *list); void insert_money(List *list); void out_money(List *list); void print_info(List *list); int menu_select(); Bank *serach_id(List *list,int id); | cs |
func.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | #include <iostream> #include <stdlib.h> #include "info.h" using namespace std; int count_id = 0; void init(List *list) { list->head = NULL; list->tail = NULL; } int menu_select() { int select; cout << "-----Menu-----" << endl; cout << "1. 계좌개설" << endl; cout << "2. 입 금 " << endl; cout << "3. 출 금 " << endl; cout << "4. 계좌정보 출력" << endl; cout << "5. 프로그램 종료" << endl; cout << "선택: "; cin >> select; cout << "\n\n"; if(select < 1 && select > 5) { cout << "존재하지 않는 메뉴입니다.\n다시 입력 해주세요.\n" << endl; menu_select(); } return select; } void insert_id(List *list) { Bank *new_id = (Bank*)malloc(sizeof(Bank)); cout << "[계좌 개설]" << endl; cout << "계좌ID: "; cin >> new_id->id; cout << "이름: "; cin >> new_id->name; cout << "입금액: "; cin >> new_id->money; new_id->no = ++count_id; cout << "\n"; if(serach_id(list,new_id->id)) { cout << "존재하는 아이디입니다.\n\n" << endl; return ; } if(list->tail != NULL) { list->tail->next = new_id; new_id->prev = list->tail; list->tail = new_id; } else { list->tail = new_id; list->head = new_id; } } void insert_money(List *list) { Bank *insert_money; int input_id,money; cout << "[입 금]" << endl; cout << "계좌ID: "; cin >> input_id; cout << "입금액: "; cin >> money; insert_money = serach_id(list,input_id); if(insert_money) { insert_money->money += money; cout << "입금완료" << endl << endl; } else { cout << "존재하지 않는 계좌입니다.\n" << endl; return ; } } void out_money(List *list) { Bank *out_money; int input_id,money; cout << "[출 금]" << endl; cout << "계좌ID: "; cin >> input_id; cout << "출금액: "; cin >> money; out_money = serach_id(list,input_id); if(out_money) { if(out_money->money < money) { cout << "[+] 현재잔액: " << out_money->money << " 원" << endl; cout << "잔액이 부족합니다\n" << endl; return; } out_money->money -= money; cout << "출금완료\n" << endl; } else { cout << "존재하지 않는 계좌입니다.\n" << endl; return ; } } void print_info(List *list) { Bank *info = list->head; if(info == NULL) { cout << "등록된 계좌가 존재하지 않습니다.\n" << endl; return ; } cout << "----------아이유은행 계좌정보----------\n" << endl; while(info !=NULL) { cout << "Num: " << info->no << endl; cout << "계좌ID: " << info->id << endl; cout << "이름: " << info->name << endl; cout << "잔액: " << info->money << endl << endl; info = info->next; } cout << "------아이유은행 계좌정보 출력완료------\n" << endl; } Bank *serach_id(List *list,int id) { Bank *serach = list->head; if(serach == NULL) { cout << "등록된 계좌가 존재하지 않습니다.\n" << endl; return 0; } while(serach != NULL) { if(serach->id == id) return serach; serach = serach->next; } return 0; } | cs |
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include "info.h" int main(int argc,char *argv[]) { int select; List list; init(&list); while(1) { select = menu_select(); switch(select) { case 1: insert_id(&list); break; case 2: insert_money(&list); break; case 3: out_money(&list); break; case 4: print_info(&list); break; case 5: exit(0); break; } } return 0; } | cs |
'프로그래밍 > C++' 카테고리의 다른 글
C++ Language Study 1st (0) | 2016.07.09 |
---|
Comments