so this is my first semester taking c++ and I am stuck with this assignment.
I am stuck in the deactivate account and setting account in the format
"xxxxx-xxxxx" (please see below)
Assingment:
Write a class definition for a BankAccount class that contains the following members:
• Member variables
o account ID (of the form xxxxx-xxxxx, where x is a digit)
o account holder name (e.g. John Joe)
o account balance
• Member methods
o Initialize(ID, name, balance): sets the account ID to a given ID, the
account holder name to the given string, and account balance to a
given number
o SetHolderName(name): sets the account holder name to the given name
o IncreaseBalance(amount): increases balance by the given amount
o DecreaseBalance(amount): if the given amount is no more than the
balance, remove it from the balance and return true; otherwise,
return false
o Deactivate: deactivates the account by setting the account ID to
00000-00000, holder name to the empty string, and balance to 0
o IsActive: returns true if the account is active and false otherwise
(an account is inactive if the account ID is 00000-00000 and the
holder name is the empty string
o Print: displays the state of the account (values of the member
variables in an organized format)
o GetID: gets the account ID
o GetHolderName: gets the account holder name
o GetBalance: gets the account balance
This is the code I have so far:
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
|
#include <iostream>
using namespace std;
class BankAccount {
public:
int accId;
string HolderName;
float Balance;
void setHolderName (string n) {
HolderName=n;
}
void setaccId ( int x ) {
accId=x;
}
void setBalance ( float b) {
Balance = b;
}
string getHolderName () {
return HolderName;
}
float getBalance () {
return Balance;
}
int getaccId () {
return accId;
}
void IncreaseBalance ( float amount) {
Balance += amount;
}
void DecreaseBalance ( float amount)
{
char pause;
if (Balance<= amount)
{
cout<< '\n' << "balance cannot be decreased by this amount because" << accId << "does not have enough funds\n";
cout<< '\n' << "Press enter to continue" << endl;
cin.get(pause);
return;
}
Balance -= amount;
return ;
}
};
int main ()
{}
|
Any help would be greatly appreciated