Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. class Account
  2. {
  3. public:
  4.     //constructor initializes data member name with two parameter accountName and initial balance int for value
  5.     Account(std::string accountName, int initialBalance)
  6.         : name{ accountName } { // member initializer empty body
  7.  
  8.         //validate the initialBalance is greater than 0; if not;
  9.         //date member balance keeps its default initial value of 0
  10.         if (initialBalance > 0) {
  11.             balance = initialBalance;
  12.         }
  13.  
  14.     }
  15.     //function that deposits (adds0 only a valide amount to the balance
  16.     void deposit(int depositAmount) {
  17.        
  18.         cout << "\n\nEnter deposit amount for account " << getName() << "> ";
  19.         cin >> depositAmount;
  20.         if (depositAmount > 0) { // if the deposit amount is valid
  21.             balance = balance + depositAmount;
  22.             cout << "adding  $" << depositAmount << " too account's balance";
  23.         }
  24.         else if(depositAmount < 0) {
  25.             cout << "INVALID DEPOSIT" << endl;
  26.         }
  27.  
  28.     }
  29.    
  30.     void withdrawl(int withdrawlAmount) {
  31.        
  32.         cout << "\nEnter a withdrawl amount for Account: " << getName() << "> ";
  33.         cin >> withdrawlAmount;
  34.         if (withdrawlAmount <= balance) { // if the deposit amount is valid
  35.             balance = balance - withdrawlAmount;
  36.            
  37.         }
  38.         else if(withdrawlAmount > balance) {
  39.             cout << "Not Enough Funds" << endl;
  40.         }
  41.    
  42.     }
  43.     //function to return account balance
  44.     int getBalance() const {
  45.         return balance;
  46.     }
  47.     //function to set account name
  48.     void setName(std::string accountName) {
  49.         name = accountName;
  50.     }
  51.     //function to retrieve accounts name
  52.    
  53.     std::string getName() const {
  54.         return name;
  55.     }
  56.     void displayAccount(){
  57.         cout << "\n" << getName() << " ";
  58.         cout << getBalance() << "\n" ;
  59.        
  60.    
  61.     }
  62. private:
  63.     std::string name; // account name data member
  64.     int balance{ 0 };// date member with default initial value
  65.    
  66.    
  67.    
  68. }; // end class Account
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement