Answer to Question #282811 in C++ for levi

Question #282811

AUTOMATED TELLER MACHINE

Create a C++ program that will

  • Deposit cash amount in a bank account
  • Check available balance of the account
  • Withdraw cash amount from an account
  • Compute for the interest earned for balances greater than Php 10,000.00
  • Charges for having a balance below the required minimum

Maintaining balance is Php 5,000.00

Interest rate is 5%

Bank charge is 2%

PIN (Personal Identification Number) is required to do a bank transaction

The program gives the user an option to change PIN



1
Expert's answer
2021-12-26T09:41:16-0500
#include<iostream>
#include<string>

using namespace std;

class ATM
{
	double amount;
	string PIN;
public:
	ATM(double _amount, string _PIN):amount(_amount),PIN(_PIN){}
	bool checkPIN()
	{
		string _PIN;
		cout << "Please, enter your PIN: ";
		cin >> _PIN;
		if (_PIN == PIN)
			return true;
		else
			return false;
	}
	void DeposCash()
	{
		if (checkPIN())
		{
			cout << "\nPlease, enter a cash: ";
			cin >> amount;
		}
		else
			cout << "Incorrect PIN!";
	}
	void ShowBalance()
	{
		if (checkPIN())
		{
			cout << "\nYour balance: " << amount;
		}
		else
			cout << "Incorrect PIN!";
	}
	void Withdraw()
	{
		if (checkPIN())
		{
			int withdr;
			cout << "\nPlease, enter a cash to withdraw: ";
			cin>> withdr;
			if (withdr < 0)
				return;
			else
			{
				amount -= withdr;
			}
		}
		else
			cout << "Incorrect PIN!";
	}
	void ForTheInterest()
	{
		if (checkPIN())
		{
			double perc = 0;
			if (amount > 10000)
			{
				perc = (amount - 10000)*0.05;
			}
			cout << "\nYour interest for balance is " << perc;
		}
		else
			cout << "Incorrect PIN!";
	}
	void ChargesForBal()
	{
		if (checkPIN())
		{
			double perc = 0;
			if (amount < 5000)
			{
				perc = amount *0.02;
			}
			cout << "\nYour charges are " << perc;
		}
		else
			cout << "Incorrect PIN!\n";
	}
	void ChangePIN()
	{
		if (checkPIN())
		{
			string _PIN;
			cout << "Please, enter your new PIN: ";
			cin >> _PIN;
			PIN = _PIN;
			cout << "\nYou changed PIN on " << PIN;
		}
		else
			cout << "Incorrect PIN!\n";
	}
};


void Menu()
{
	cout << "\n******AUTOMATED TALLER MACHINE******\n";
	cout << "1 - Deposit cash amount in a bank account\n"
		<< "2 - Check available balance of the account\n"
		<< "3 - Withdraw cash amount from an account\n"
		<< "4 - Compute for the interest earned for balances\n"
		<< "5 - Charges for having a balance\n"
		<< "6 - Change PIN\n"
		<< "0 - Exit prohgram\n"
		<< "Your choice: ";
}

int main()
{
	ATM atm(0,"0000");
	string pin;
	cout << "******AUTOMATED TALLER MACHINE******\n";
	cout << "Please, enter a PIN (0000- default): ";
	cin >> pin;
	if (pin != "0000")
	{
		cout << "Incorrect PIN!\n";
		return -1;
	}	
	int choice;
	do
	{
		Menu();
		cin >> choice;
		switch (choice)
		{
			case 0: break;
			case 1:
			{
				atm.DeposCash();
				break;
			}
			case 2:
			{
				atm.ShowBalance();
				break;
			}
			case 3:
			{
				atm.Withdraw();
				break;
			}
			case 4:
			{
				atm.ForTheInterest();
				break;
			}
			case 5:
			{
				atm.ChargesForBal();
				break;
			}
			case 6:
			{
				atm.ChangePIN();
				break;
			}
		}
	} while (choice != 0);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog