File main.cpp
#include"Account.h"
#include"ATM.h"
#include<vector>
int main()
{
int ms=-1,ms2=-1;
ATM atm;
int LuaChon,LuaChon2;
vector<Account> ListAccount;
do{
cout<<"\n1. Nhap Du Lieu Cho Account";
cout<<"\n2. Nhap Du Lieu Cho ATM";
cout<<"\n3. Vao ATM\n";
cout<<"Nhap lua chon: ";
cin>>LuaChon;
if(LuaChon==1){
Account* x=new Account;
x->input();
ListAccount.push_back(*x);
}else if(LuaChon==2){
atm.NhapTienVao();
}
}while(LuaChon!=3);
cout<<"\n--------------Danh sach---------------\n";
for(int i=0;i<ListAccount.size();i++){
cout<<endl;
ListAccount[i].output();
}
cout<<endl;
long matk=0;
while(1){
cout<<"Nhap Ma TK: ";
cin>>matk;
for(int i=0;i<ListAccount.size();i++){
if(ListAccount[i].matk()==matk){
ms=i;
cout<<"Login Success!";
}
}
if(ms!=-1){
break;
}
cout<<"Ma Tai Khoan Khong Hop Le !";
}
do{
cout<<"\n\n\n======================Chao ban!"<<ListAccount[ms].matk()<<"======================\n";
cout<<"\n1. Rut Tien";
cout<<"\n2. Chuyen Tien";
cout<<"\n3. Van Tin TK";
cout<<"\n0. Ket Thuc Giao Dich!";
cout<<"\nLua Chon: ";
LuaChon2=0;
cin>>LuaChon2;
if(LuaChon2==1){
atm.RutTien(ListAccount[ms]);
}else if(LuaChon2==2){
while(1){
cout<<"\nNhap ma TK can chuyen khoan: ";
cin>>matk;
for(int i=0;i<ListAccount.size();i++){
if(ListAccount[i].matk()==matk){
ms2=i;
}
}
if(ms2!=-1){
break;
}
cout<<"\nTK ban chuyen khoan chua dung !";
}
cout<<"Nhap so Tien can chuyen: ";
long m;
cin>>m;
atm.ChuyenKhoan(ListAccount[ms],ListAccount[ms2],m);
cout<<"Chuyen Khoan Thanh Cong!";
}else if(LuaChon2==3){
cout<<"\nThong Tin Tai Khoan!\n";
atm.KiemTraSoDu(ListAccount[ms]);
}
}while(LuaChon2!=0);
system("pause");
}
file ATM.h
#include<iostream>
#include"Account.h"
using namespace std;
class ATM{
private:
int SoTien;
public:
void NhapTienVao();
unsigned long TienConlai();
void RutTien(Account x);
void ChuyenKhoan(Account,Account,long);
void KiemTraSoDu(Account x);
};
void ATM::NhapTienVao(){
unsigned long m;
cout<<"Nhap so tien ATM co the chua: ";
cin>>SoTien;
}
unsigned long ATM::TienConlai(){
return SoTien;
}
void ATM::RutTien(Account x){
cout<<"Nhap So Tien Muon Rut: ";
unsigned long m;
cin>>m;
cout<<x.sodu();
if(x.sodu()<m){
cout<<"Ban Khong Con Du Tien De Rut! ";
}
else{
x.ruttien(m);
SoTien-=m;
cout<<"OKie,Ban da rut"<<m<<" , moi ban nhan tien va The ";
}
}
void ATM::ChuyenKhoan(Account a,Account b,long SoTienNhan){
if(a.sodu()<SoTienNhan){
cout<<"Ban Khong Con Du Tien De Chuyen Khoan! ";
}else{
a.chuyentien(SoTienNhan);
b.nhantien(SoTienNhan);
}
}
void ATM::KiemTraSoDu(Account x){
x.output();
}
file Account.h
#pragma once
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class Account
{
private:
long SoTaiKhoan,SoDu;
string TenChuTK;
int TheLoai;
public:
void input();
void output();
string setHoTen();
long sodu();
long matk();
void ruttien(unsigned long m);
void nhantien(unsigned long m);
void chuyentien(unsigned long m);
};
void Account::input()
{
cout<<"Nhap So TK: ";
cin>>SoTaiKhoan;
fflush(stdin);
cout<<"Nhap Ho Ten: ";
getline(cin,TenChuTK);
cout<<"Nhap So Du: ";
cin>>SoDu;
cout<<"Loai The: ";
cin>>TheLoai;
cout<<endl;
}
void Account::output()
{
cout<<setw(8)<<left<<SoTaiKhoan<<setw(20)<<left<<TenChuTK<<setw(20)<<SoDu<<setw(5)<<TheLoai;
}
void Account::ruttien(unsigned long m){
this->SoDu-=m;
}
void Account::nhantien(unsigned long m){
this->SoDu+=m;
}
void Account::chuyentien(unsigned long m){
this->SoDu-=m;
}
long Account::sodu(){
return SoDu;
}
long Account::matk(){
return SoTaiKhoan;
}
string Account::setHoTen(){
return TenChuTK;
}
Giúp e với tại sao mỗi lần e rút tiền mà nó không trừ vậy! Thanks