Hi, I'm a first year college CS major. We've started OOP and I've just been asked to create a class for a bank account. I'm pretty solid at the idea of a class, but the actual format of using the member functions inside main have got my head spinning. I need a little help with this problem:
Write a C++ program in which you define and test the
class BankAccount. This class shall have as data members:
balance (double), an account number (string) and account
type (1-savings, 2-checking). The class shall allow the
following actions (member functions): debit (reduces the
account’s balance by the provided positive amount), credit
(increases the account’s balance by the provided positive
amount) and printAccountInfo (prints account number, type
and balance on the screen). The class BankAccount shall
also define the following constructors:
Default constructor which sets the initial balance to
zero, the type of the account to checking and the account
number to "000001"
Copy Constructor, and
Overloaded constructor for initializing all the data
members of the class.
Here is my code so far, I think the actual definition of the class is correct, but I'm confused on how to implement it in main:
class BankAccount
{
private:
double balance ;
char accountNumber ;
bool accountType ;
double amountS ;
public:
void defaultCTOR(){
balance = 0 ;
accountType = true ;
accountNumber = 0000001;}
void debit(double balance, BankAccount amount){
balance = balance - amount.amountS ;}
void credit(double balance,double amount){
balance = balance + amount ;}
void printAccountInfo(){
cout << accountNumber << endl ;
if (accountType == true)
{
cout << "Checking" <<endl ;
}
else
{
cout << "Savings" <<endl ;
}
cout << accountType << endl ;
cout << balance << endl ;}
};
int main()
{
double amountS ;
/* declare and test instances of the class BankAccount */
BankAccount amount ;
amount.defaultCTOR();
cout << "Enter the amount you wish to credit to your account: " ;
cin >> amountS ;
amount.debit(0,amount) ;
amount.printAccountInfo();
return 0;
}