// BankingSystem_v_2_1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
const int NAME_LEN = 20;
class Account
{
int id;
int balance;
char* name;
public:
Account(){}
Account(int, char*, int);
Account(const Account& acc);
~Account();
int GetID(){ return id; }
int GetBalance(){ return balance; }
char* GetName(){ return name; }
void AddMoney(int val){ balance += val; }
void MinMoney(int val){ balance -= val; }
void ShowData();
};
Account* pArray[100];
int index = 0;
void PrintMenu();
void MakeAccount();
void Deposit();
void Withdraw();
void Inquire();
enum{MAKE = 1, DEPOSIT, WITHDRAW, INQUIRE, EXIT};
int _tmain(int argc, _TCHAR* argv[])
{
int choice;
while (1)
{
PrintMenu();
cout << "Choice NUM :"; cin >> choice;
switch (choice)
{
case MAKE:
MakeAccount();
break;
case DEPOSIT:
Deposit();
break;
case WITHDRAW:
Withdraw();
break;
case INQUIRE:
Inquire();
break;
case EXIT:
return 0;
default:
cout << "Illegal selection.." << endl;
}
}
return 0;
}
void PrintMenu()
{
cout << "=======MENU=====================" << endl;
cout << "1. Make account " << endl;
cout << "2. Deposit " << endl;
cout << "3. Withdraw " << endl;
cout << "4. Balance " << endl;
cout << "5. EXIT" << endl;
}
void MakeAccount()
{
int id;
char name[NAME_LEN];
int balance;
cout << "=======MakeAccount============== " << endl;
cout << "AccountID :"; cin >> id;
cout << "name :"; cin >> name;
cout << "balance :"; cin >> balance;
pArray[index++] = new Account(id, name, balance);
}
void Deposit()
{
int money;
int id;
cout << "AccountID :"; cin >> id;
cout << "money :"; cin >> money;
for (int i = 0; i <index; i ++)
{
if (pArray[i]->GetID() == id)
{
pArray[i]->AddMoney(money);
cout << "Deposit complete!!" << endl;
return;
}
}
cout << "It id wormgnumber !!" << endl;
}
void Withdraw()
{
int id;
int money;
cout << "AccountID :"; cin >> id;
cout << "money :"; cin >> money;
for (int i = 0; i < index; i ++)
{
if (pArray[i] -> GetID() == id)
{
if (pArray[i]->GetBalance() < money)
{
cout << "You have insufficient fund" << endl;
return;
}
pArray[i]->MinMoney(money);
cout << "Withdraw is complete !!" << endl;
return;
}
}
cout << "It id wormgnumber !!" << endl;
}
void Inquire()
{
for (int i = 0; i < index; i ++)
{
pArray[i]->ShowData();
}
}
void Account::ShowData()
{
cout << "AccountID :" << id << endl;
cout << "name :" << name << endl;
cout << "balance :" << balance << endl;
}
Account::Account(int _id, char* _name, int _balance)
{
id = _id;
name = new char[strlen(_name) +1];
strcpy(name, _name);
balance = _balance;
}
Account::Account(const Account& acc)
{
id = acc.id;
name = new char[strlen(acc.name) + 1];
strcpy(name, acc.name);
balance = acc.balance;
}
Account::~Account()
{
delete[] name;
}
'컴퓨터과학[1-2] > knou_C++' 카테고리의 다른 글
C++ - 이 페이자의 스크립트에서 오류가 발생하였읍니다. (0) | 2019.02.15 |
---|---|
C ++ 연습문제 풀이 4 -1 (0) | 2014.10.21 |
C ++ Structure & Destructure (0) | 2014.10.11 |
배열 포인터 활용 (0) | 2014.09.23 |
C ++연습문제 2-1 풀이 (0) | 2014.08.17 |
댓글