You are on page 1of 19

ASSIGNMENT#03

ALI HAIDER
404674
Q#1: Write a code in C++ to make an ATM machine. Use classes to
design your ATM software. Use operator overloading concept to
transfer money from one account to another account. Your code
should print the following output with the corresponding functionality.

1. Press 1 to create account


2. Press 2 to check balance
3. Press 3 to withdraw money
4. Press 4 to transfer money
5. Press 5 to deposit money
6. Press 6 to check daily transactions
7. Press 7 to change your password
8. Press 8 to create passcode
9. Press 9 to pay utility bills
10. Press 10 to exit

#include<iostream>

#include<unistd.h>

using namespace std;

class atm

private:

int pin;

char name[50];

int balance;
public:

};

void display_menu()

cout<<"|Press 1 To Create Bank Account"<<endl;

cout<<"|Press 2 For Deposit Money"<<endl;

cout<<"|Press 3 For Check Balance"<<endl;

cout<<"|Press 4 For Withdraw Money"<<endl;

cout<<"|Press 5 For Transfer Money"<<endl;

cout<<"|Press 6 To Create Passcode"<<endl;

cout<<"|Press 7 To Change Password"<<endl;

cout<<"|Press 8 To Pay Electricity Bill"<<endl;

cout<<"|Press 9 To Pay Gas Bill"<<endl;

cout<<"|Press 10 For Reviewing Transaction"<<endl;

cout<<"|Press 11 For Help"<<endl;

cout<<"|Press 12 To Exit"<<endl;

int main()

atm a;

int s,d,f,g,h1,h2,h3,h4,h5,h6,w,r=0;

int h7,y,x1,x2,x3,x4,h9,h8,h10,q,i,h11,h12;
char c[100],x;

char e[100],h[100];

int xx;

system("color 3c");

std::cout<<" [WELCOME TO USMAN-E-GHANI


BANK]" <<endl;

jump:

display_menu();

cin>>s;

switch(s)

case 1:

system("cls");

cout<<"Which Account You want to Create?"<<endl;

cout<<"Current Or Saving Account"<<endl;

cin.getline(c,100,'.');

system("cls");

cout<<"Enter Your Name:"<<endl;

cin.getline(e,100,'.');

system("cls");

cout<<"Enter Your CNIC number:"<<endl;

cin>>f;

system("cls");
cout<<"Enter Your Phone Number:"<<endl;

cin>>g;

system("cls");

cout<<"Enter Your Address:"<<endl;

cin.getline(h,100,'.');

system("cls");

jump3:

cout<<"Create Your Password(It Should consist of Nummerics)"<<endl;

cin>>h1;

cout<<"Re-Enter Your New Password:"<<endl;

cin>>h2;

if(h1!=h2)

system("cls");

cout<<" [Your Previous Password Doesn't Matter With


Old One]"<<endl;

goto jump3;

else if(h1==h2)

system("cls");

cout<<"Your Password is created:"<<endl;

sleep(3);
}

jump8:

cout<<"|Enter Your New 4 number pin|"<<endl;

cin>>h3;

cout<<"|Re-Enter Your 4 Number Pin|"<<endl;

cin>>h4;

if(h3!=h4)

system("cls");

cout<<"Your Previous Password Doesn't Matter With Old One:"<<endl;

goto jump8;

else if(h3==h4)

cout<<"Congratulation You've successfully made the Account:"<<endl;

sleep(3);

cout<<"[Press 'H' To Continue]"<<endl;

cin>>x;

system("cls");

goto jump;

case 2:

system("cls");

cout<<"Deposit Some Money To Your Account:"<<endl;

cin>>h5;
xx++;

system("cls");

system("color 2b");

std::cout<<"Your Account Balance is:"<<h5<<endl;

sleep(3);

goto jump;

case 3:

system("cls");

system("color 5a");

std::cout<<"current Balance is:"<<h5<<endl;

sleep(3);

xx++;

goto jump;

case 4:

jump1:

cout<<"Enter the amount you want to withdraw:"<<endl;

cin>>h6;

if(h6>h5)

system("cls");

cout<<"The Amount You Enter Is greater Than Your


Balance:"<<endl;

goto jump1;
}

system("cls");

h5=h5-h6;

system("color 5e");

std::cout<<"The Remaining Balance after withdraw is:"<<h5<<endl;

xx++;

sleep(3);

goto jump;

case 5:

system("cls");

jump2:

cout<<"Enter The Receiver Account Number:"<<endl;

cin>>w;

cout<<"Enter The Money You want To Transfer:"<<endl;

cin>>h7;

if(h7>h5)

system("cls");

cout<<"The Amount You Enter Is greater Than Your


Balance:"<<endl;

goto jump2;

system("cls");
h5=h5-h7;

system("Color 6f");

std::cout<<"The Remaining Balance after Transfer is:"<<h5<<endl;

xx++;

sleep(3);

goto jump;

case 6:

system("cls");

jump4:

cout<<" <Create Passcode>"<<endl;

cout<<" {This Passcode is useful in Case Your Forget Your Pin or


Password}"<<endl;

cout<<" ***Comfort of Customer is our First


Priority***"<<endl;

cout<<"Type The New Passcode(Nummerics Only):"<<endl;

cin>>x1;

cout<<"Re-Type The Passcode(Nummerics Only):"<<endl;

cin>>x2;

if(x1!=x2)

system("cls");

cout<<"Your Previous Passcode Doesn't Matter With Old


One"<<endl;

goto jump4;
}

else if(x1==x2)

system("cls");

system("color 3c");

std::cout<<"Your Passcode is created"<<endl;

sleep(3);

goto jump;

case 7:

system("cls");

jump5:

cout<<" {Change Your Password} "<<endl;

cout<<"Enter Your Old Password"<<endl;

cin>>h8;

if(h8!=h2)

system("cls");

cout<<"The Password You Enter Is Wrong"<<endl;

goto jump5;

jump7:

system("cls");
cout<<"Enter New Password"<<endl;

cin>>x3;

cout<<"Again Enter New Password"<<endl;

cin>>x4;

if(x3!=x4)

system("cls");

system("color 2a");

std::cout<<"The Password You Entered Did Not Match To Each


Other"<<endl;

goto jump7;

system("cls");

cout<<"Your Password is changed"<<endl;

sleep(3);

goto jump;

case 8:

system("cls");

jump9:

cout<<" You can Also Pay your Electricity Bills Now


"<<endl;

cout<<"Enter The Amount Of Your Bill:"<<endl;

cin>>h10;

if(h10>h5)
{

system("cls");

system("color d9");

std::cout<<"The Amount You Enter Is greater Than Your Balance"<<endl;

goto jump9;

system("cls");

h5=h5-h10;

cout<<"The Remaining Balance after Paying Bill is:"<<h5<<endl;

cout<<"Your Electricity Bill Is Paid Successfully"<<endl;

xx++;

sleep(3);

goto jump;

case 9:

system("cls");

jump10:

cout<<" You can Also Pay your Gas Bills Now "<<endl;

cout<<"Enter The Amount Of Your Bill:"<<endl;

cin>>h11;

if(h11>h5)

system("cls");

cout<<"The Amount You Enter Is greater Than Your Balance"<<endl;


xx++;

goto jump10;

system("cls");

h5=h5-h11;

system("color 2b");

std::cout<<"The Remaining Balance after Paying Bill is:"<<h5<<endl;

std::cout<<"Your Gas Bill Is Paid Successfully"<<endl;

std::cout<<"Thanks For Using Our Banking"<<endl;

goto jump;

case 10:

cout<<"You have done "<<xx<<" Transactions"<<endl;

case 11:

system("color 2b");

std::cout<<"Our Dedicated Helplines:" <<endl;

std::cout<<"Please dial below mentioned helplines as per your need.UGB


Retail Helpline: 111-825-888."<<endl;

cout<<"UGB Omni (Branchless banking) Helpline: 111-825-777. UGB


Priority Helpline: 0800-55825."<<endl;

cout<<"UGB Remittance Helpline: 111-825-666"<<endl;

sleep(5);

goto jump;

case 12:

system("cls");
system("color 5e");

std::cout<<"Thanks For Using Our Banking"<<endl;

break;

return 0;

Q#2: Can we overload these operators: ! , ^, %, && , [ ] ,||, =*, += ? If


yes, then write a code in C++ to overload them.

//operatoroverloading
#include<iostream>
using namespace std;
class dig
{
private:
int val;
int val1;
public:
dig()
{
val=0;
}
void input()
{
cout<<"Enter 1 Digit:"<<endl;
cin>>val;
}
void display()
{
cout<<"Answer is:"<<val<<endl;
}
bool operator != (dig b1)
{
if(val==b1.val)
{
return false;
}
else
{
return true;
}
}
dig operator ^ (dig b)
{
dig c;
int i=0;
int total=1;
for(int i=0;i<b.val;i++)
{
total=val*total;
}
c.val=total;
return c;
}
dig operator %(dig b)
{
dig c;
c.val=val%b.val;
return c;
}
dig operator +=(dig b)
{
val=val+b.val;
dig c;
c.val=val;
return c;
}
dig operator *=(dig b)
{
val=val*b.val;
dig c;
c.val=val;
return c;
}
bool operator &&(dig c)
{
if(val%2==0 && c.val%2==0)
{
return true;
}
else
{
return false;
}
}
bool operator || (dig c)
{
if(val%2==0 || c.val%2==0)
{
return true;
}
else
{
return false;
}
}

};
class ar
{
private:
int g[1];
public:
ar operator [](int c)
{
ar t;
cout<<"Enter a Value:"<<endl;
cin>>t.g[c];
return t;
}
void disply()
{
for(int i=0;i<1;i++)
{
cout<<g[i];
}
}

};
int main()
{
dig b,b1,c,d,e,f;
b.input();
b1.input();
cout<<endl;
cout<<"!="<<endl;
if(b!=b1)
{
system("color 2b");
std::cout<<"Values are not Equal."<<endl;
}
else
{
cout<<"Values are Equal."<<endl;
}
system("color 5e");
std::cout<<endl;
cout<<"^"<<endl;
c=b^b1;
c.display();
cout<<endl;
cout<<"%"<<endl;
d=b%b1;
d.display();
cout<<endl;
cout<<"+="<<endl;
b+=b1;
b.display();
cout<<endl;
cout<<"*="<<endl;
b*=b1;
b.display();
cout<<endl;
cout<<endl;
cout<<"&&"<<endl;
if(b&&b1)
{
cout<<"Divisible by 2."<<endl;
}
else
{
cout<<"Not Divisible by 2."<<endl;
}
cout<<endl;
cout<<endl;
cout<<"||"<<endl;
if(b||b1)
{
cout<<"One Value Divisible by 2."<<endl;
}
else
{
cout<<"Not Divisible by 2."<<endl;
}
cout<<endl;
cout<<"[]"<<endl;
ar y;
y=y[0];
y.disply();
cout<<endl;
system("pause");
return 0;
}

You might also like