//This program uses the procedural approach //to demonstrate the BankAccount problem. //Author: A. Guercio - Feb.18, 2008 #include #include using namespace std; //list of the functions used //open creates an account and returns the number of the account int open(double amount); //it adds the amount to deposit to the balance and returns the new balance double deposit(double abalance, double amount); //it subtracts the amount to withdraw to the balance and returns the new balance double withdraw(double abalance, double amount); //it computes the interest of the account and returns the new balance double compute_interest(double abalance, const double ARATE); //it adds the current balance to the interest matured double update(double abalance, double ainterest); //here starts the main int main() {int account, double balance, double interest; const double RATE = 0.05; cout << "How much money to you want to start the account with? " << endl; cout << "Insert the amount here: $"; cin >> balance; //create an account and add some money in it account = open(balance); cout << "The number of the account just created is " << account << endl; cout << "and has " << balance << " dollars in it." << endl; //deposit money in the account balance = deposit(balance, 1000); cout << "The account has " << balance << " dollars in it now." << endl; //withdraw money from the account balance = withdraw(balance, 300); cout << "The account has " << balance << " dollars in it now." << endl; //compute the interest you the account interest = compute_interest(balance, RATE); cout << "The interest on your account is " << interest << endl; //update the balance with the interest balance = update(balance, interest); cout << "The account has " << balance << " dollars in it now." << endl; return 0; } // end of main //The functions inmplementation starts here. int open(double abalance) //generate a random number for the new account {if (abalance > 0) return rand(); else return 0;} double deposit(double abalance, double amount) //deposit the amount {return (abalance + amount); } double withdraw(double abalance, double amount) //withdraw the amount {return (abalance - amount); } double compute_interest(double abalance, const double ARATE) //compute the interest {return (abalance * ARATE); } double update(double abalance, double ainterest) //update the balance with the interest {abalance = abalance + ainterest; return abalance; }