/*********************************************************************
 * Authors: B. Alex Bridges and Miriam Becker                        *
 * File: main.cpp                                                    *
 * Class: CPSC-451, Summer 1999                                      *
 * Project: Project 1 - Account Maintenance                          *
 * Description: This program will simulate the ATM machine at a      *
 *              local bank.                                          *
 * Contents: main function which drives program and other generic    *
 *           methods.                                                *
 *********************************************************************/

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


/* CONSTANTS */
// NONE

/* GLOBAL VARIABLES */
// NONE

/*************************************************************************
 * Method: main                                                          *
 * Purpose: Drives program.                                              *
 * Input: --COMMAND-LINE ARGUMENTS--                                     *
 *        1. Run Count = The max. number of valid, main menu runs.       *
 * Output: --EXIT VALUES--                                               *
 *         => COMPLETED SUCCESSFULLY = +1                                *
 *         => FATAL ERROR/EXCEPTION  = -1                                *
 *************************************************************************/
int main(int argc, char *argv[]) // SETS UP COMMAND-LINE ARGUMENTS
{
  /* LOCAL VARIABLES */
  Main* MainVar = new Main();     // MAIN VARIABLE
  Menus* MenusVar = new Menus();  // MENUS VARIABLE
  int i;                          // LOOP COUNT

  /* HEADER */
  MainVar->ClearScreen();

  puts("B. Alex Bridges and Miriam Becker");
  puts("CPSC-451, Summmer 1999");
  puts("Project 1: Account Maintenance\n");

  /* CHECKING FOR REQUIRED ARGUMENTS */
  if(argc < 2)
  {
    puts("\aERROR: The following command-line arguments must be included:");
    puts(" => 1.  Run Count = The max. number of valid, main menu runs.\n");
    exit(-1); // ERROR
  } // if
  else if(MainVar->bDebug)
  {
    printf(" The following command-line arguments were included:\n");
    printf("  => 0.  Program Name = '%s'\n",argv[0]);
    printf("  => 1.  Run Count    = '%s'\n\n",argv[1]);
  } // else if

  for(i = 1; i <= atoi(argv[1]); i++)
  {
    MenusVar->PrintMenus();
    if(MainVar->bDebug)
      printf(" argv[1] = '%s' vs. i = '%d'\n\n",argv[1],i);
  } // if

  return(1);  // COMPLETED SUCCESSFULLY
} // method main

/* METHODS */
/*************************************************************************
 * Method: ClearScreen                                                   *
 * Purpose: Makes a system call to clear the screen.                     *
 * Input: --PARAMETERS--                                                 *
 *        => none                                                        *
 * Output: --RETURNS--                                                   *
 *        => none                                                        *
 *************************************************************************/
void Main::ClearScreen(void)
{
  if(bUnixTarget)
    system("clear");
  else
    system("cls");
} // method ClearScreen

/*************************************************************************
 * Method: PressContinueKey                                              *
 * Purpose: Pauses the program until the continue key is pressed.        *
 * Input: --PARAMETERS--                                                 *
 *        => none                                                        *
 * Output: --RETURNS--                                                   *
 *        => none                                                        *
 *************************************************************************/
void Main::PressContinueKey(void)
{
  /* LOCAL VARIABLE */
  char cArrRead[30]; // CHARACTERS READ

  puts("Type 'yes' when you are ready to continue . . . ");
	do {
    fflush(stdin);
    gets(cArrRead);
  } while( strcmp(cArrRead,"yes") != 0 );
  puts("");
} // method PressContinueKey

/* CONSTRUCTORS */
/*************************************************************************
 * Constructor: Main                                                     *
 * Purpose: Creates object which allows access to its methods and        *
 *          variables.                                                   *
 * Input: --PARAMETERS--                                                 *
 *        => none                                                        *
 *************************************************************************/
Main::Main()
{
  /* TRUE, FALSE VALUES */
  btrue = 1;
  bfalse = 0;

  /* RUNTIME OPTIONS */
  bDebug = bfalse;
  bUnixTarget = btrue;
} // constructor Main

