4. Create a class Account with two overloaded constructors. The first constructor is used for initializing the name of account holder, the account number and the initial amount in the account. The second constructor is used for initializing the name of account holder, account number, address, the type of account and the current balance. The Account class is having methods Deposit(), Withdraw() and GetBalance(). Make necessary assumptions for data members and return types of methods. Create objects of Account class and use them.
1
Expert's answer
2013-01-23T09:55:13-0500
#include <iostream> #include <string> using namespace std; class Account{ string accountHolder; int accountNumber; int initialAmount; string typeOfAccount; string address; int currentBalance; public: Account(string name, int num, int init){ accountHolder = name; accountNumber = num; initialAmount = init; } Account(string name, int num, string type, string _address, int current){ accountHolder = name; accountNumber = num; typeOfAccount = type; address = _address; currentBalance = current; } void Deposit(int d){ if (typeOfAccount == "deposit") currentBalance+=d; else cout<<"Error, your account don't supports this type of opperation\nYou need to create 'deposit' account\n";
} int withDraw(int sum){ if (currentBalance >= sum){ currentBalance-=sum; return sum; }else cout<<"Your account don't have this amount of money\n"; } int GetBalance(){ return currentBalance; }
}; int main(){ Account acc("Anton",123,"deposit","sechenova6",1000); acc.Deposit(10);
Comments
Leave a comment