Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to simulate the operation of a cashpoint machine. For simplicity

ID: 3533678 • Letter: W

Question

Write a program to simulate the operation of a cashpoint machine. For simplicity,

assume that the bank has only 3 clients, whose data will be stored in an array of

objects of type:

class Client

{

public:

Client(); // constructor

void setAccountNumber(int);

int getAccountNumber();

void setPIN(int);

int getPIN();

float get_balance();

void make_deposit(float);

bool withdraw_cash(float); // No funds? return false.

private:

int accountNumber;

int pin;

float balance;

};

Implement class Client by writing all of the functionsindicated above. The class

constructor must initialize the state of new instances, at the very least, set the initial

balance to zero.

Write function bool withdraw_cash(float),so that it returns true if the operation can be

done (i.e., there are sufficient funds in the account). If so, reduce the balance

accordingly. If the operation is not possible, just return false. The other functions

should be self-explanatory.

Each client object will be defined manually in your program. For example:

// Create clients

Client clientDB[3];

// Set initial values for each client like this:

clientDB[0].setAccountNumber(1);

clientDB[0].setPIN(123);

clientDB[0].make_deposit(1000.0);

// Set also values for second and third client

//

//

Explanation / Answer

resendez is BOSS!!!

#include "stdafx.h"
#include <iostream>

using namespace std; class Client { public: Client(); // constructor void setAccountNumber(int); int getAccountNumber(); void setPIN(int); int getPIN(); float get_balance(); void make_deposit(float); bool withdraw_cash(float); // No funds? return false. private: int AccountNumber; int pin; float balance; };

Client :: Client() { AccountNumber = pin = 0; balance=0; }

void Client :: setAccountNumber(int a) { AccountNumber= a;
} int Client :: getAccountNumber() { cout << AccountNumber << endl; return AccountNumber; } void Client:: setPIN(int p) { pin=p; } int Client :: getPIN() { cout << pin << endl; return pin; } void Client :: make_deposit(float d) { balance=balance + d; }
float Client :: get_balance() { return balance; }

bool Client :: withdraw_cash(float cash) // check to see if withdraw is possible {    if ( (balance - cash )> 0) { balance = balance - cash; return true; } else { cout << "ERROR: insufficent funds " << endl; return false; } }
int main() { int accNum, pin, opeNum ; float d, cash; // Create clients Client clientDB[3];
// Initial values for each client (1,2,3): clientDB[0].setAccountNumber(1); clientDB[0].setPIN(123); clientDB[0].make_deposit(1000.0);

clientDB[1].setAccountNumber(2); clientDB[1].setPIN(456); clientDB[1].make_deposit(1500.0);
clientDB[2].setAccountNumber(3); clientDB[2].setPIN(789); clientDB[2].make_deposit(2000.0);
do { cout << "Enter account number: "; // ask for account cin >> accNum; cout << "Enter PIN: "; //ask for pin cin >> pin;
if (accNum==1 && pin==123 || accNum==2 && pin==456 || accNum==3 && pin==789 ) // check for valid account number and pin
{ cout << "Select an operation: 1. Show balance 2. Make a deposit 3. Withdraw cash 4. Exit "; cin >> opeNum; }
else { cout<< "ERROR : please check your account number and/or pin " << endl << endl; }
switch (opeNum) // select operation { case 1: // Show balance if (accNum==1 && pin==123) { cout << "Your balance is: " << clientDB[0].get_balance() << endl << endl;break; // execute "Show balance account 1" } if ( accNum == 2 && pin==456 ) { cout << "Your balance is: " << clientDB[1].get_balance() << endl << endl;break; // execute "Show balance account 2" } if ( accNum == 3 && pin==789) { cout << "Your balance is: " << clientDB[2].get_balance() << endl << endl;break; // execute "Show balance account 3" }


case 2: // execute "Make a deposit" if (accNum==1 && pin==123) { cout << "Enter deposit amount: " ; cin >> d; cout << "Starting balance:" << clientDB[0].get_balance() << endl;; // Balance before deposit account1 clientDB[0].make_deposit(d); cout << "Ammount of deposit:" << d << endl; // ammount of deposit cout << "Your current balance is:" << clientDB[0].get_balance() << endl << endl;break; // Balance after deposit account1 } if (accNum==2 && pin==456) { cout << "Enter deposit amount: " ; cin >> d; cout << "Starting balance:" << clientDB[1].get_balance() << endl; // Balance before deposit account 2 clientDB[1].make_deposit(d); cout << "Ammount of deposit:" << d << endl; // ammount of deposit cout << "Your current balance is:" << clientDB[1].get_balance() << endl << endl;break;// Balance after deposit account2 } if (accNum==3 && pin==789) { cout << "Enter deposit amount: " ; cin >> d; cout << "Starting balance:" << clientDB[2].get_balance() << endl; // Balance before deposit account3 clientDB[2].make_deposit(d); cout << "Ammount of deposit:" << d << endl; // ammount of deposit cout << "Your current balance is:" << clientDB[2].get_balance() << endl << endl;break;// Balance after deposit account3 } case 3: // execute "Withdraw Cash" if (accNum==1 && pin==123) { cout << "Enter amount you wish to withdraw: "; // Amount cash to withdraw cin>> cash; clientDB[0].withdraw_cash(cash); cout << "Your current balance is:" << clientDB[0].get_balance() << endl << endl; break; // Balance after withdraw account1 } if (accNum==2 && pin==456) { cout << "Enter amount you wish to withdraw: "; // Amount cash to withdraw cin>> cash; clientDB[1].withdraw_cash(cash); cout << "Your current balance is:" << clientDB[1].get_balance() << endl << endl; break; // Balance after withdraw account2 } if (accNum==3 && pin==789) { cout << "Enter amount you wish to withdraw: "; // Amount cash to withdraw cin>> cash; clientDB[1].withdraw_cash(cash); cout << "Your current balance is:" << clientDB[1].get_balance() << endl << endl; break; // Balance after withdraw account3 } case 4: cout<< endl; break ; // exit program }
} while (accNum>0);


return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote