c++ programming only please Write a program to simulate the operation of a cashp
ID: 3533733 • Letter: C
Question
c++ programming only please
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 functions indicated 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
int main()
{
int password;
for (int i=0;i<3;i++)
{cout <<"enter password: ";
cin>>password;
/* loop through 3 attempts at password */
if (password==123456) {
cout<<"korek!!! ";
break; }
else
cout<<"Please try again! ";
if (i == 2) return 0; // if failed 3 times, end program
} /* end password loop */
double balance = 10000;
double withdraw, deposit;
int option;
bool finished = false; // if user selects option 4, 'quit', finished = true, otherwise finished = false
cout<<" ";
cout<<" ***MOGOL*** ";
cout<<"*** Automated Teller Machine***"<<endl;
while (!finished) { // repeat until user selects quit
cout<<"Choose a Transaction: ";
cout<<" ";
cout<<"[1] Inquire Balance "
<<"[2] Withdraw "
<<"[3] Deposit "
<<"[4] Quit "
<<" "
<<"Enter Option:";
cin>>option;
switch(option)
{
case 1:
cout<<" [[[BALANCE INQUIRY]]] ";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<" Your current balance is $"<<balance<<endl;
break;
case 2:
cout<<" [[[WITHDRAW]]] ";
cout<<"Enter amount: $";
cin>>withdraw;
balance = balance - withdraw;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"You withdrew $"<<withdraw<<endl;
cout<<"Your remaining balance is $"<<balance<<endl;
continue;
case 3:
cout<<" [[[DEPOSIT]]] ";
cout<<"Enter amount: $";
cin>>deposit;
balance = balance + deposit;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"You deposited $"<<deposit<<endl;
cout<<"Your new balance is $"<<balance<<endl;
continue;
case 4:
finished = true; // user has selected quit
cout<<" ***[[[EXIT MODE]]]*** ";
break;
default:
cout<<" That is an invalid option ";
}
}
return 0;
}//
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.