Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Account
- {
- public:
- //constructor initializes data member name with two parameter accountName and initial balance int for value
- Account(std::string accountName, int initialBalance)
- : name{ accountName } { // member initializer empty body
- //validate the initialBalance is greater than 0; if not;
- //date member balance keeps its default initial value of 0
- if (initialBalance > 0) {
- balance = initialBalance;
- }
- }
- //function that deposits (adds0 only a valide amount to the balance
- void deposit(int depositAmount) {
- cout << "\n\nEnter deposit amount for account " << getName() << "> ";
- cin >> depositAmount;
- if (depositAmount > 0) { // if the deposit amount is valid
- balance = balance + depositAmount;
- cout << "adding $" << depositAmount << " too account's balance";
- }
- else if(depositAmount < 0) {
- cout << "INVALID DEPOSIT" << endl;
- }
- }
- void withdrawl(int withdrawlAmount) {
- cout << "\nEnter a withdrawl amount for Account: " << getName() << "> ";
- cin >> withdrawlAmount;
- if (withdrawlAmount <= balance) { // if the deposit amount is valid
- balance = balance - withdrawlAmount;
- }
- else if(withdrawlAmount > balance) {
- cout << "Not Enough Funds" << endl;
- }
- }
- //function to return account balance
- int getBalance() const {
- return balance;
- }
- //function to set account name
- void setName(std::string accountName) {
- name = accountName;
- }
- //function to retrieve accounts name
- std::string getName() const {
- return name;
- }
- void displayAccount(){
- cout << "\n" << getName() << " ";
- cout << getBalance() << "\n" ;
- }
- private:
- std::string name; // account name data member
- int balance{ 0 };// date member with default initial value
- }; // end class Account
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement