這是我到目前爲止的代碼,它編譯並運行良好,但我需要修改它的幫助。這是一個銀行應用程序,目前僅適用於一個帳戶。指向類實例C++的指針數組
它需要適應兩個新文件:bank.h和bank.cpp,main應該包含一個指向bank的指針,bank應該包含一個指向account的實例的指針數組。
因此新的接口將工作成才類似於:
帳戶> 1 12
1是帳戶#和12是被depositted的ammount的。
我真的需要幫助,以適應我的代碼做到這一點,我迷失在如何創建銀行指針數組帳戶的實例。任何幫助深表感謝。包含與共享變量和函數
class account{
private:
int balance;
public:
account();
~account();
int value;
int account_balance();
int deposit();
int withdraw();
int init();
};
//account.cpp實現文件
using namespace std;
#include <iostream>
#include "account.h"
account::account(){
}
account::~account(){
}
//balance overwrite function
int account::init(){
balance = value;
}
//balance function
int account::account_balance() {
return balance;
}
//deposit function
int account::deposit(){
balance += value;
}
//withdraw function
int account::withdraw(){
//error handling
if(value>balance){
cout << "Error! insufficient funds." << endl;
return 0;
}
balance -= value;
}
你能幫我在bank.h和bank.cpp中實現這個嗎 – Ianschramm
我在這裏向你展示了一些示例代碼。如果你有多個帳戶,你需要一些方法來識別它。或者給它一個名字或者一個id,比如一個銀行賬號。所以當你想存一些錢的時候,你必須指定id來使用正確的賬戶。 – Devolus
對不起,我應該更清楚。它應該有20個指數,每個指數都是一個帳戶。所以帳戶[0]是第一個帳戶。 – Ianschramm