atm
Thu Jun 24 2021 13:17:59 GMT+0000 (Coordinated Universal Time)
Saved by @abdul_hanan
#include<iostream>
#include<string>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
using namespace std;
class Card //Declare card class
{
public:
friend ATM;//Declare friends
Card::Card(string Name, int Account)//Constructor
{
name = Name;
account = Account;
}
protected:
string name;//Cardholder's Name
int account;//account number
};
class BankCard:public Card {
public:
friend ATM;//Friend class ATM. Enable ATM class to access private members of bank card class
BankCard(string Name, int Account, string Password, float Money)
:Card(Name,Account)
{
password = Password;
money = Money;
}; //Constructor
private:
string password;//password
float money;//total amount
};
class ATM//ATM type, which simulates the main system of the self-service teller machine
{
public:
void Information();//
int check_password(int Account, string Password);//Verify account password function
void transfer_money();//Transfer function
void check_remain_money();//Query balance function
void deposit();//Save money function
void drawing();//Withdraw money function
void change_password();//Modify password function
ATM(string Name, int Account, string Password, float Money)
{
name = Name;
account = Account;
password = Password;
money = Money;
}
private:
string password;//password
float money;//total amount
string name;//Cardholder's Name
int account;//account number
};
void ATM::Information()
{
cout<<"your name:"<<name<<endl;
cout<<"Your account: " << account << endl;
system("pause");//Output press any key to continue
system("cls");//Clear screen function
}
void ATM::deposit() //Save money function
{
float e_money;//Define the variable to store the amount to be deposited
cout << "Please enter the amount you want to deposit" << endl;
cin >> e_money;
money += e_money;//Change the total amount
cout << "Your balance is" << money << "yuan" << endl;
system("pause");//Output press any key to continue
system("cls");//Clear screen function
}
void ATM::drawing() //Withdraw money function
{
float e_money;//Define the variable to store the amount to be taken
cout << "Please enter the amount you want to withdraw" << endl;
cin >> e_money;
if (e_money > money)//If the withdrawal is more than the total amount
cout << "Insufficient account balance" << endl;
else //If the withdrawal is less than the total amount
{
money -= e_money;
cout << "Your balance is" << money << "yuan" << endl;
}
system("pause");//Output press any key to continue
system("cls");//Clear screen function
}
void ATM::change_password() // //Modify password function
{
string new_password1, new_password2, pwd;
cout << "Please enter the original password: ";
cin >> pwd;
cout << endl;
if (pwd == password)
{
cout << "Please enter a new password: ";
cin >> new_password1;
cout << endl;
cout << endl;
while (new_password1 == password)
{
cout << "The same as the old password, please enter a new password: ";
cin >> new_password1;
cout << endl;
}
cout << "Please enter the new password again: ";
cin >> new_password2;
cout << endl;
while (new_password1 != new_password2)
{
cout << "Different from the first input, please input again: ";
cin >> new_password2;
cout << endl;
}
password = new_password2;
cout << "password has been updated! " << endl;
cout << endl;
}
else if (pwd != password)
{
do {
cout << "Wrong password, please re-enter: ";
cin >> pwd;
} while (pwd != password);
change_password();
}
system("pause");//Output press any key to continue
system("cls");//Clear screen function
}
void ATM::transfer_money() //Transfer function
{
float Transfer_money = 0.0;//Define the variable to store the amount to be transferred
cout << "Please enter the amount to be transferred" << endl;
cin >> Transfer_money;
if (Transfer_money > money)//If the transfer amount is greater than the total amount
cout << "Insufficient account balance" << endl;
else //The transfer amount is less than the total amount
{
money -= Transfer_money;
cout << "The operation was successful, your balance is" << money << "yuan" << endl;
}
system("pause");//Output press any key to continue
system("cls"); //Clear screen function
}
void ATM::check_remain_money() { //Check balances
cout << "Your balance is" << money << endl;
system("pause");//Output press any key to continue
system("cls");//Clear screen function
}
int ATM::check_password(int Account, string Password) //Verify account password function
{
int i = 0;
cout << "Please enter your account and password" << endl;
for (i = 0; i < 3; i++)
{ //Cannot exceed three attempts
cout << "account number:";
cin >> Account;
cout << "password:";
cin>>Password;
if ((Account ==account)&&(Password == password))
{
cout << "Login to China Minsheng Bank successfully!" << endl
<< "welcome!" << endl;
return 1;
}
else
{
cout << "Incorrect account or password, please re-enter" << endl;
if (i >= 2)
{
cout << "You have tried more than three times and have been frozen" << endl;
system("pause");//Output press any key to continue
}
}
}
return 0;
}
int main()
{
ATM atm("Zhao Si",198754, "311817", 1314);
//Define the ATM class object atm, call the constructor to assign values to the private members
int account;
string password;
int j = 0;
int flag = 0;
flag = atm.check_password(account, password);
while (flag)
{
cout << "Please choose your needs: 1. Information query 2. Deposit money 3. Withdraw money 4. Change password 5. Transfer 6. Check balance 7. Exit" << endl;
cin >> j;
switch (j)
{
case 1:{atm.Information();break;}
case 2:{atm.deposit(); break;}
case 3:{atm.drawing(); break;}
case 4:{atm.change_password(); break;}
case 5:{atm.transfer_money(); break;}
case 6:{atm.check_remain_money();break;}
case 7:{break;}
default:break;
}
if (j==6)break;
if(j != 1 && j != 2 && j != 3 && j != 4 &&j != 5&&j!=6){
cout<<"Please enter the correct command!"<<endl;
system("pause");
system("cls");
}
}
return 0;
}



Comments