#include<iostream>
using namespace std;

class Account
{
public:
  void open(string inName);
  void deposit(float money);
  float getBalance();
  void withdraw(float money);
  // New history function
  void printHistory();

private:
  string name;
  float balance;
  // New history variables
  float history[100];
  int num_transactions;
};


int main()
{
 Account acc1;

 // Open account
 acc1.open("Tina");

 // Print initial balance
 cout << acc1.getBalance() << endl;

 // Make new deposits and print new balance
 acc1.deposit(250);
 acc1.deposit(20.25);
 cout << acc1.getBalance() << endl;

 // Make withdrawals and deposits and print new balance
 acc1.withdraw(300);
 acc1.withdraw(50.50);
 acc1.withdraw(25);
 acc1.deposit(40);
 cout << acc1.getBalance() << endl;

 acc1.printHistory();

 return 0;
}


// Open account with (string) specified name, 0 balance,
// opening balance recorded in history
void Account::open(string inName)
{
 name=inName;
 balance=0;

 // New history statement
 history[0]=balance;
 num_transactions=1;
}


// Take (float) money from user and (if valid amount) deposit it
// into account
void Account::deposit(float money)
{
 if(money>=0) {
   balance = balance+money;

   // New history statements:
   history[num_transactions]=balance;
   num_transactions++;
 }
 else {
   cout << "Error! Negative deposit!\n";
 }
}


// Report current balance in account
float Account::getBalance()
{
 return balance;
}


// Take (float) money from user and (if valid amount) withdraw
// it from account
void Account::withdraw(float money)
{
 if(money>=0 && money <=balance)
 {
   balance -= money;

   // New history statements:
   history[num_transactions]=balance;
   num_transactions++;
 }
 else
   cout << "Invalid withdrawal amount!\n";
}


// Report recent history
void Account::printHistory()
{
 for(int i=num_transactions-1; i>(num_transactions-6)||i>0; i--)
   cout << "Balance " << i << ": " << history[i] << endl;
}