PROGRAM 19
// FILE NAME: PROG19.CPP PROGRAMMER NAME: ANTHONY F. ORTIZ
// THIS PROGRAM DECLARES AN ATM AND BANK OBJECT AND CALLS MEMBER FUNCTIONS
// FROM BOTH.
#include "ouratm.h"
#include "ourbank.h"
#include "ourstuff.h"
#include
int main ()
{
atm moneymachine;
bank firstbank;
int customernumber;
double amount;
int found;
moneymachine.getnameandpin ();
firstbank.findcustomer (moneymachine, customernumber, found);
moneymachine.showbalance (firstbank.availablebalance (customernumber));
moneymachine.getwithdrawal (amount);
firstbank.recordwithdrawal (amount, customernumber);
moneymachine.showbalance (firstbank.availablebalance (customernumber));
return 0;
}
// I DIDN'T WRITE OURATM.H, OURATM.CPP, OURBANK.H, AND OURBANK.CPP.
// FILENAME: OURATM.H
// THIS PROGRAM DECLARES THE CLASS ATM.
#ifndef ouratm_h
#define ouratm_h
#include "ourstr.h"
class atm
{
public:
void atm :: getnameandpin ();
// PRE: THE USER ENTERS ANY TWO STRINGS AT THE PROMPT.
// POST: THE DATA MEMBERS OF THE ATM OBJECT ARE RESET.
void atm :: gettransaction (char &transaction) const;
// PRE: THE USER ENTERS ONE OF THESE LETTERS: W, D, B, OR Q.
// POST: A MENU OF ATM OPTIONS IS DISPLAYED AND TRANSACTION IS
// RETURNED AS ONE OF THESE FOUR CHARS 'W', 'D', 'B', OR 'Q'.
// THE UPPERCASE CHAR REPRESENTS ONE OF THESE TRANSACTIONS:
// W)ITHDRAW D)EPOSIT B)ALANCE Q)UIT.
void atm :: getwithdrawal (double &amount) const;
// PRE: THE USER ENTERS SOMETHING.
// POST: RETURNS A VALID NUMERIC INPUT IN AN INCREMENT OF 5.00
// AS THE AMOUNT A CUSTOMER WISHES TO WITHDRAW FROM AN ATM.
// IF THE CUSTOMER ENTERS AN INVALID INPUT SUCH AS A NEGATIVE
// NUMBER, AN INVALID NUMBER, OR A VALID NUMERIC INPUT THAT
// IS NOT AN INCREMENT OF 5.00, AMOUNT IS RETURNED AS 0.00.
void atm :: getdeposit (double &amount) const;
// PRE: THE USER ENTERS SOMETHING.
// POST: RETURNS ANY VALID NUMERIC INPUT AS THE AMOUNT OF
// MONEY THE CUSTOMER WISHES TO DEPOSIT AT AN ATM.
// IF THE CUSTOMER ENTERS AN INVALID INPUT SUCH AS A NEGATIVE
// NUMBER OR AN INVALID NUMBER, AMOUNT IS RETURNED AS 0.00.
void atm :: showbalance (double amount) const;
// POST: AMOUNT IS DISPLAYED ON THE ATM SCREEN WITH A
// HEADING AND A PAUSE FOR THE CUSTOMER TO READ IT.
void atm :: message (string amessage) const;
// POST: AMESSAGE IS DISPLAYED ON THE ATM SCREEN.
// A PAUSE OCCURS TO ALLOW CUSTOMER TO READ THE MESSAGE.
string atm :: pin () const;
// PRE: THE GETNAMEANDPIN FUNCTION HAS BEEN CALLED.
// POST: RETURNS THE CURRENT CUSTOMER PIN.
string atm :: name () const;
// PRE: THE GETNAMEANDPIN FUNCTION HAS BEEN CALLED.
// POST: RETURNS THE CURRENT CUSTOMER NAME.
void atm :: logo () const;
// POST: THE ATM LOGO IS DISPLAYED ON A CLEARED SCREEN.
private:
string username;
string userpin;
};
#include "ouratm.cpp"
#endif
// FILENAME: OURATM.CPP
// THIS PROGRAM CONTAINS THE IMPLEMENTATION OF THE CLASS ATM.
#include
#include
#include
#include "ourstuff.h"
#include "ourstr.h"
void atm :: getnameandpin ()
{
clearscreen ();
logo ();
cout << "\n\n\n";
cout.width (20);
cout << "ENTER NAME: ";
cin >> username;
username.toUpper ();
cout << "\n";
cout.width (20);
cout << "ENTER PIN: ";
cin >> userpin;
}
void atm :: gettransaction (char &transaction) const
{
clearscreen ();
cout << "\n\n";
cout << " ATM ----------------------------------------" << endl << endl;
cout.width (32);
cout << "WITHDRAW [W]" << endl;
cout.width (32);
cout << " DEPOSIT [D]" << endl;
cout.width (32);
cout << " BALANCE [B]" << endl;
cout.width (32);
cout << " QUIT [Q]" << endl << endl;
do
{
cout.width (30);
cout << "SELECT [W, D, B, Q]: ";
cin >> transaction;
transaction = toupper (transaction);
cin.ignore (80, '\n');
}
while (transaction != 'W' && transaction != 'D' && transaction != 'B' && transaction != 'Q');
}
void atm :: getwithdrawal (double &amount) const
{
clearscreen ();
cout << "\n\n";
cout << " ATM ----------------------------------------" << endl << endl;
cout.width (30);
cout << "ENTER AMOUNT TO WITHDRAW: ";
cin >> amount;
if (cin.good ())
{
cin.ignore (80, '\n');
if (amount < 0)
{
amount = 0.00;
message ("NEGATIVE WITHDRAWALS NOT ALLOWED");
}
else
{
long hundreds = long (floor (amount * 100 + 1.0e-3));
if ((hundreds % 500) != 0)
{
message ("MUST USE INCREMENTS OF 5.00");
amount = 0.00;
}
}
}
else
{
flush (cin);
amount = 0.00;
message ("INVALID CURRENCY INPUT");
}
}
void atm :: getdeposit (double &amount) const
{
clearscreen ();
cout << "\n\n";
cout << " ATM ----------------------------------------" << endl << endl;
cout.width (30);
cout << "ENTER AMOUNT TO DEPOSIT: ";
cin >> amount;
if (cin.good ())
{
cin.ignore (80, '\n');
if (amount < 0)
{
amount = 0.00;
message ("NEGATIVE DEPOSITS NOT ALLOWED");
}
}
else
{
amount = 0.00;
flush (cin);
message ("INVALID CURRENCY INPUT");
}
}
void atm :: showbalance (double amount) const
{
clearscreen ();
cout << "\n\n";
cout << " ATM ----------------------------------------" << endl << endl;
long int oldflags = decimals (cout, 2);
cout.width (30);
cout << "BALANCE: " << amount << endl;
cout.setf (oldflags);
causeapause ();
}
string atm :: name () const
{
return username;
}
string atm :: pin () const
{
return userpin;
}
void atm :: message (string amessage) const
{
clearscreen ();
cout << "\n\n";
cout << " ATM ----------------------------------------" << endl << endl;
cout.width (40);
cout << amessage << endl;
causeapause ();
}
void atm :: logo () const
{
cout << endl;
cout << " AA TTTTTTTTTT MM MM " << endl;
cout << " AAAA TT MMMM MMMM " << endl;
cout << " ======AUTOMATED TELLER MACHINE====== " << endl;
cout << " AAAAAAAA TT MM MM MM " << endl;
cout << " AA AA TT MM MM " << endl;
cout << "AA AA TT MM MM " << endl;
}
// FILENAME: OURBANK.H
// THIS PROGRAM DEFINES A CLASS NAMED BANK.
#ifndef ourbank_h
#define ourbank_h
#include "ouracct.h"
#include "ouratm.h"
class bank
{
public:
bank :: bank ();
// POST: ALL BANKACCOUNT OBJECTS HAVE BEEN INITIALIZED.
void bank :: findcustomer (atm moneymachine, int &customernumber, int &found) const;
// POST: IF THE ATM OBJECT HAS OBTAINED A VALID NAME AND PIN:
// 1. CUSTOMERNUMBER = THE INTEGER USED IN ALL BANK OPERATIONS.
// 2. FOUND = 1.
// IF THE ATM HAS OBTAINED AN INVALID BANK CUSTOMER:
// 1. CUSTOMERNUMBER = -1.
// 2. FOUND = 0.
void bank :: recordwithdrawal (double amount, int customernumber);
// POST: THE PROPER BANKACCOUNT OBJECT IS ADJUSTED
// TO REFLECT A WITHDRAWAL THE SIZE OF AMOUNT.
// WHEN CUSTOMERNUMBER DOES NOT REPRESENT A
// VALID CUSTOMER, NO WITHDRAWAL IS RECORDED.
void bank :: recorddeposit (double amount, int customernumber);
// POST: THE PROPER BANKACCOUNT OBJECT IS ADJUSTED
// TO REFLECT A DEPOSIT THE SIZE OF AMOUNT.
// WHEN CUSTOMERNUMBER DOES NOT REPRESENT A
// VALID CUSTOMER, NO DEPOSIT IS RECORDED.
double bank :: availablebalance (int customernumber) const;
// PRE: CUSTOMERNUMBER REPRESENTS A VALID CUSTOMER.
private:
bankaccount customer [20];
int numberofcustomers;
};
#include "ourbank.cpp"
#endif
// FILENAME: OURBANK.CPP
// THIS PROGRAM CONTAINS THE IMPLEMENTATION OF BANK.
#include "ouracct.h"
#include "ouratm.h"
bank :: bank ()
{
numberofcustomers = 16;
customer [0] = bankaccount ("CUSTO", "0000", 000.00);
customer [1] = bankaccount ("ORTIZ", "2871", 111.11);
customer [2] = bankaccount ("AUSTEN", "2222", 222.22);
customer [3] = bankaccount ("CHELSEA", "3333", 333.33);
customer [4] = bankaccount ("KIERAN", "4444", 444.44);
customer [5] = bankaccount ("CUST5", "5555", 555.55);
customer [6] = bankaccount ("CUST6", "6666", 666.66);
customer [7] = bankaccount ("CUST7", "7777", 777.77);
customer [8] = bankaccount ("CUST8", "8888", 888.88);
customer [9] = bankaccount ("CUST9", "9999", 999.99);
customer [10] = bankaccount ("CUST10", "1010", 1010.10);
customer [11] = bankaccount ("CUST11", "1111", 1111.11);
customer [12] = bankaccount ("CUST12", "1212", 1212.12);
customer [13] = bankaccount ("CUST13", "1313", 1313.13);
customer [14] = bankaccount ("CUST14", "1414", 1414.14);
customer [15] = bankaccount ("hall", "1234", 100.00);
}
void bank :: findcustomer (atm moneymachine, int &customernumber, int &found) const
{
bankaccount temp (moneymachine.name (), moneymachine.pin ());
found = 0;
customernumber = 0;
while ((!found) && (customernumber < numberofcustomers))
{
if (temp == customer [customernumber])
found = 1;
else
customernumber++;
}
if (!found)
customernumber = -1;
}
void bank :: recordwithdrawal (double amount, int customernumber)
{
if ((amount > 0) && (customernumber < numberofcustomers) && (amount <= customer [customernumber].balance ()))
customer [customernumber].withdraw (amount);
}
void bank :: recorddeposit (double amount, int customernumber)
{
if ((amount > 0) && (customernumber > -1) && (customernumber < numberofcustomers))
customer [customernumber].deposit (amount);
}
double bank :: availablebalance (int customernumber) const
{
return customer [customernumber].balance ();
}
// FILENAMES: OURSTUFF.H, OURSTUFF.CPP, OURACCT.H, OURACCT.CPP
// SEE PROGRAM 14.
// FILENAMES: OURSTR.H, OURSTR.CPP
// SEE PROGRAM 12.
// OUTFILE: PROG19.OUT
AA TTTTTTTTTT MM MM
AAAA TT MMMM MMMM
======AUTOMATED TELLER MACHINE======
AAAAAAAA TT MM MM MM
AA AA TT MM MM
AA AA TT MM MM
ENTER NAME: ORTIZ
ENTER PIN: 2871
ATM ----------------------------------------
BALANCE: 111.11
. . . PRESS ENTER TO CONTINUE . . .
ATM ----------------------------------------
ENTER AMOUNT TO WITHDRAW: 100.00
ATM ----------------------------------------
BALANCE: 11.11
. . . PRESS ENTER TO CONTINUE . . .
BACK TO COMP251 PAGE.