// File: account.cpp
// Implementation file for class for bank account

#include <iostream>     // ostream
#include "account.h"    // BankAccount class definition
using namespace std;

// Function: Default constructor
// Initializes the account balance to $0.00 and the interest 
// rate to 0.0%.
BankAccount::BankAccount()
{
    myBalance = 0.0;
    myRate = 0.0;
}  // end Default constructor

// Function: Explicit value constructor
// Initializes the account balance to initialBalance and
// initializes the interest rate to initialRate.
BankAccount::BankAccount(double initialBalance,   // RECEIVED: initial balance
                         double initialRate)      // RECEIVED: initial rate
{
    myBalance = initialBalance;
    myRate = initialRate;
}  // end Esplicit value constructor

// Function: GetBalance
// Returns the current account balance.
double BankAccount::GetBalance( ) const
{
    return myBalance;
}  // end GetBalance

// Function: GetRate
// Returns the current account interest rate as a percent.
double BankAccount::GetRate( ) const
{
    return myRate;
}  // end GetRate

// Function: Update
// Computes and adds one year of simple interest to the account balance.
void BankAccount::Update( )
{
    myBalance = myBalance + myRate*myBalance;
}  // end Update


// Function: Write
// Assumes if outs is a file output stream, then outs has already been 
// connected to a file.
// Writes account balance and interest rate to the stream outs.
void BankAccount::Write(ostream& outs) const  // REC'D/PASSED BACK: output stream
{
    // Formatting
    outs.setf(ios::fixed);
    outs.setf(ios::showpoint);
    outs.precision(2);

    // Write out data
    outs << "Account balance $" << myBalance << endl;
    outs << "Interest rate " << (myRate*100) << "%" << endl;
}  // end Write
