In this assignment is to simulate an ATM machine. Program should able to do the following
operations:
A. Create accounts for the users. A user account is created using User ID and
Password. Every user has unique User ID and Password.
B. A user should able to login using his User ID and Password.
C. A user can quit the program.
D. Provision to Delete a User
Initially there are no users. There program should prompt for the following option:
1) New Account,
2) Login,
3) Quit and
4) Delete an Account
Depending upon the option selected necessary action to be taken. New Account option adds a
user account. When a user is added then the total number of users is increased by one. For
successful Login option user will be able to do the following:
a) Withdraw money,
b) Deposit money, and
c) Request balance,
#include<iostream>
#include<string>
using namespace std;
class Account{
private:
string ID;
string password;
float balance;
public:
Account(){}
Account(string ID,string password){
this->ID=ID;
this->password=password;
this->balance=0;
}
string getID(){
return this->ID;
}
string getPassword(){
return this->password;
}
float getBalance(){
return balance;
}
void setID(string ID){
this->ID=ID;
}
void setPassword(string password){
this->password=password;
}
void deposit(float amount){
if(amount>0){
this->balance+=amount;
}else{
cout<<"\nThe amount<=0!\n\n";
}
}
void withdraw(float amount){
if(amount>0){
if(this->balance>=amount){
this->balance-=amount;
}else{
cout<<"\nThe amount > balance!\n\n";
}
}else{
cout<<"\nThe amount<=0!\n\n";
}
}
};
int getIndexAccout(Account accounts[],int totalNumberUsers,string ID){
for(int i =0;i<totalNumberUsers;i++){
if(ID==accounts[i].getID()){
return i;
}
}
return -1;
}
int isLogin(Account accounts[],int totalNumberUsers,string ID,string password){
for(int i =0;i<totalNumberUsers;i++){
if(ID==accounts[i].getID() && password==accounts[i].getPassword()){
return i;
}
}
return -1;
}
int main (){
string ID;
string password;
float amount;
int ch=0;
Account accounts[100];
int totalNumberUsers=0;
int index;
while(ch!=3){
cout<<"1) New Account\n";
cout<<"2) Login\n";
cout<<"3) Quit\n";
cout<<"4) Delete an Account\n";
cout<<"Your choice: ";
cin>>ch;
cin.ignore();
if(ch==1){
cout<<"Enter the user ID: ";
getline(cin,ID);
cout<<"Enter the user password: ";
getline(cin,password);
accounts[totalNumberUsers]=Account(ID,password);
totalNumberUsers++;
}else if(ch==2){
if(totalNumberUsers>0){
cout<<"Enter the user ID: ";
getline(cin,ID);
cout<<"Enter the user password: ";
getline(cin,password);
index=isLogin(accounts,totalNumberUsers,ID,password);
if(index!=-1){
ch=-1;
while(ch!=4){
cout<<"1. Withdraw money\n";
cout<<"2. Deposit money\n";
cout<<"3. Request balance\n";
cout<<"4. Log out\n";
cout<<"Your choice: ";
cin>>ch;
if(ch==1){
cout<<"Enter amount to withdraw: ";
cin>>amount;
accounts[index].withdraw(amount);
}else if(ch==2){
cout<<"Enter amount to deposit: ";
cin>>amount;
accounts[index].deposit(amount);
}else if(ch==3){
cout<<"\nThe balance: "<<accounts[index].getBalance()<<"\n\n";
}else if(ch==4){
//log out
}else{
cout<<"\nWrong choice.\n\n";
}
}
}else{
cout<<"\nWrong ID or password.\n\n";
}
}else{
cout<<"\nNo accounts.\n\n";
}
}else if(ch==3){
//exit
}else if(ch==4){
if(totalNumberUsers>0){
cout<<"Enter the user ID to delete: ";
getline(cin,ID);
cout<<"Enter the user password to delete: ";
getline(cin,password);
index=isLogin(accounts,totalNumberUsers,ID,password);
if(index!=-1){
for(int i =index;i<totalNumberUsers-1;i++){
accounts[i]=accounts[i+1];
}
totalNumberUsers--;
cout<<"\nThe account has been deleted.\n\n";
}else{
cout<<"\nWrong ID or password.\n\n";
}
}else{
cout<<"\nNo accounts.\n\n";
}
}else{
cout<<"\nWrong choice.\n\n";
}
}
return 0;
}
Comments
Leave a comment