This is what I have CS 241: Object Oriented Programming using C++ Fall 2018 Home
ID: 3747594 • Letter: T
Question
This is what I have
CS 241: Object Oriented Programming using C++ Fall 2018 Homework # 2 1. Modify the ATM simulation program you did in homework 1 to use methods (functions). So, in addition to the main method, your application should have the following methods: . authenticatelser nnd validates it against the actinformation, the method This method reads the Account Number and the PIN entered by the user and validates it against the actual account number and PIN. If the entered information matches the account information, the method ends and returns true otherwise it displays a message that the information entered does not match the account information then gives the user another chance to enter the account number and PIN. The user is given a total of 3 chances to enter the correct account number and PIN. If the user fails to enter the correct information after 3 trials, the method ends and returns false showMenu: This method is called from the main method and displays the menu options then waits for the user to make a selection. Once the selection is made by the user, the method ends and returns the choice of the user to the main method. This method does not take any parameters yiew Balance: This mthod is called by the main method after the menu has been displayed and the user selected option 1 from the menu. It does not take any parameters and does not return anything. It only displays a message saying "You selected View Balance" withdrawCash: This method is called by the main method after the menu has been displayed and the user selected option 2 from the menu. It does not take any parameters and does not return anything. It only displays a message saying "You selected Withdraw Cash" e e depositCash: This method is called by the main method after the menu has been displayed and the user selected option 3 from the menu. It does not take any parameters and does not return anything. It only displays a message saying "You selected Deposit Cash" 2. Assume that: The account number is 12345 The PIN is 54321 Hint: declare the above as global variables so that they can be seen by all the methods in the program.Explanation / Answer
//ATM Simulation program
#include<iostream.h>
#include<conio.h>
#include<stdlib.h> //for exit(1)
int showMenu();
int authenticateUser();
void viewBalance();
void withdrawCash();
void depositCash();
int account_number=12345, pin=54321;
void main()
{
int choice,auser;
clrscr();
auser=authenticateUser();
if(auser==1)
{
menu:
choice=showMenu();
switch(choice)
{
case 1: viewBalance();
break;
case 2: withdrawCash();
break;
case 3: depositCash();
break;
case 4: exit(1);
default:
cout<<” Invalid selection, please try again..!”;
break;
}
goto menu;
}
getch();
}
int showMenu()
{
int choice;
cout<<” Menu”;
cout<<” 1. viewBalance”;
cout<” 2. withdrawCash”;
cout<<”n3. depositCash”;
cout<<” 4. Exit”;
cout<<” enter the choice:”;
cin>>choice;
return(choice);
}
int authenticateUser()
{
int acc_no, p, i=1;
enter:
cout<<” Enter the Account number:”;
cin>>acc_no;
cout<<” Enter the PIN number:”;
cin>>p;
if(acc_no==account_number && p==pin)
{
return 1;
}
else
{
if(i<3)
{
cout<<” the information entered is not match, Once again try ”;
i++;
goto enter;
}
else
{
cout<<” You tried 3 trials, but not correct. So system ends now”;
return(0);
}
}
}
void viewBalance()
{
cout<<” You selected View Balance”;
}
void withdrawCash()
{
cout<<” You selected Withdraw Cash”;
}
void depositCash()
{
cout<<” You selected Deposit Cash”;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.