In: Computer Science
Simulate an ATM machine. Create ten accounts in an array with id 0, 1, . . . , 9, and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money, and 4 for exiting the main menu. Once you exit, the system will prompt for an id again. Thus, once the system starts, it will not stop. In the main, check the id, and if the id is correct, call/involke the class for ATM.
BELOW IS THE CODE IN C++:
# include <iostream>
using namespace std;
class ATM
{
float balance;
public:
int id;
void set_all(int i,float money)
{
id = i;
balance = money;
}
void check_balance()
{
cout<<"\n\t ACCOUNT BALANCE : "<<balance;
}
void deposit_money(float money)
{
if(money >= 0)
{
balance += money;
}
else if(money < 0)
{
cout<<"\n\t Depositing money can't be negative!!";
}
else
{
cout<<"\n\t Wrong Input!!PLEASE ENTER MONEY IN NUMBERS";
}
}
void money_withdraw(float money)
{
if((money > 0) && (money <= balance))
{
balance -= money;
}
else
{
cout<<"\n\t Money can't be withdraw!! PLEASE ENTER A VALID AMOUNT";
}
}
};
int main()
{
ATM ar[10];
for(int i = 0 ; i < 10 ; i++)
{
ar[i].set_all(i,100);
}
int num;
cout<<"_____________________WELCOME TO THE ATM_________________________";
while(true)
{
cout<<"\n Enter your account id : ";
cin>>num;
if((num >= 0) && (num<=9))
{
int flag = 1;
while(flag == 1)
{
int n;
float money;
cout<<"\n MENU FOR ACCOUNT ID = "<<ar[num].id;
cout<<"\n Enter 1 for viewing the current balance";
cout<<"\n Enter 2 for withdrawing money";
cout<<"\n Enter 3 for depositing money";
cout<<"\n Enter 4 for returning to mainmenu";
cout<<"\n\t OPTION:";
cin>>n;
switch(n)
{
case 1:
ar[num].check_balance();
break;
case 2:
cout<<"\n How much Money : ";
cin>>money;
ar[num].money_withdraw(money);
break;
case 3:
cout<<"\n How much Money : ";
cin>>money;
ar[num].deposit_money(money);
break;
case 4:
flag = 0;
break;
default:
cout<<"\n\t Please Chose correct option!!";
break;
}
}
}
else
{
cout<<"\n\t Please enter valid Account ID !!";
}
}
}
OUTPUT:
DON'T FORGET TO GIVE A LIKE