/*********************************************************************
 * Authors: B. Alex Bridges and Miriam Becker                        *
 * File: account.cpp                                                 *
 * Class: CPSC-451, Summer 1999                                      *
 * Project: Project 1 - Account Maintenance                          *
 * Description: This program will simulate the ATM machine at a      *
 *              local bank.                                          *
 * Contents: Methods for dealing with the accounts.                  *
 *********************************************************************/

/* INCLUDES */
// => PRE-DEFINED
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// => USER-DEFINED
//#include "account.h"
#include "main.h"
#include "database.h"


/* CONSTANTS */
const int iBaseNo = 10000;           // BASE ACCOUNT NUMBER

/* GLOBAL VARIABLES */
Main* MainAccountVar = new Main();  // MAIN VARIABLE


/* METHODS */
/*************************************************************************
 * Method: DepWith                                                       *
 * Purpose: Deposits or withdrawls the specified amount from the         *
 *          referenced account.                                          *
 * Input: --PARAMETERS--                                                 *
 *        => bDeposit = 1 is true and makes it a deposit.                *
 *                    = 0 is false and makes it a withdrawl.             *
 * Output: --RETURNS--                                                   *
 *        => none                                                        *
 *************************************************************************/
void Account::DepWith(int bDeposit)
{
  /* LOCAL VARIABLES */
  float fpAmount = 0; // SUPPLIED AMOUNT OF WITHDRAWL/DEPOSIT

    /* GET AMOUNT OF DEPOSIT AND WITHDRAWL*/
    // => DEPOSIT
    if(bDeposit == MainAccountVar->btrue)
    { 
      puts("Please enter the amount of your deposit:");
      scanf("%f",&fpAmount);
      puts("");

      if(MainAccountVar->bDebug)
        printf(" The deposit was '%f'.\n",fpAmount);

      fpBalance += fpAmount;
      puts("Deposit completed successfully.\n");
    } // if
    // => WITHDRAWL
    else
    { 
      puts("Please enter the amount of your withdrawl:");
      scanf("%f",&fpAmount);
      puts("");

      if(MainAccountVar->bDebug)
        printf(" The withdrawl was '%f'.\n\n",fpAmount);

      if(fpBalance >= fpAmount)
      {
        fpBalance -= fpAmount;
        puts("Withdrawl completed successfully.\n");
      } // if
      else if(fpBalance > 10)
      {
        fpBalance -= 10;
        puts("Insufficient funds to handle your request.");
        puts("A $10 overdraft fee was applied.\n");
      } // else if
      else
      {
        fpBalance = 0;
        puts("Insufficient funds to handle your request.");
        puts("The account was zeroed out to cover a $10 overdraft fee.\n");      
      } // else
    } // else

    if(MainAccountVar->bDebug)
    {
      printf(" Resulting Account:\n");
      printf(" - Name = '%s'\n",charAName);
      printf(" - Balance = '%f'\n",fpBalance);
      printf(" - Account Number = '%d'\n\n",iAccountNo);
    } // if
} // method DepWith

/*************************************************************************
 * Method: Inquiry                                                       *
 * Purpose: Prints the balance of the referenced account.                *
 * Input: --PARAMETERS--                                                 *
 *        => none                                                        *
 * Output: --RETURNS--                                                   *
 *        => none                                                        *
 *************************************************************************/
void Account::Inquiry(void)
{
  /* LOCAL VARIABLES */
  // NONE

    printf("The account number for %s was found and is now being referenced.\n\n",charAName);

     /* PRINT CURRENT BALANCE*/
    printf("The current balance is $%f\n\n",fpBalance);
} // method Inquiry

/* CONSTRUCTORS */
/*************************************************************************
 * Constructor: Account                                                  *
 * Purpose: Creates object which allows access to its methods and        *
 *          variables.                                                   *
 * Input: --PARAMETERS--                                                 *
 *        => pName    = Name on the account.                             *
 *        => fpAmount = Opening balance for the account.                 *
 *        => iOffset  = Offset from base for the account number.         *
 *************************************************************************/
Account::Account(char* pName, float fpAmount, int iOffset)
{
    strcpy(charAName,pName);
    fpBalance = fpAmount;
    iAccountNo = iBaseNo + iOffset;
} // constructor Account

/* DESTRUCTOR */
Account::~Account()
{
} // destructor Account

