Define a class to represent a bank account using c++ coding(with and without scope resolution)

  1. Define a class to represent a bank account. Include the following members:Data members : Name of the depositor, Account number, Type of account,Balance amount in the account Member functions: To assign initial values, To deposit an amount ,To withdraw an amount after checking the balance,To display name and balance. Write a main function to test the program.




coding:

#include<iostream>
#include<iomanip>
using namespace std;
class bank
{
char nameofdepositer[50];
int ANO;
char actype[30];
int balance amount;
public:
void intialvalue(void);
void withdraw(void);
void deposite(void);
void display(void);
};

void bank :: intialvalue(void)
{
cout<<"Enter Name";
cin>>nameofdepositer;
cout<<"Enter A/c no";
cin>>ANO;
cout<<"Enter A/c Type";
cin>>actype;
cout<<"Enter Opening Balance:-";
cin>>balance amount;
}

void bank :: withdraw(void)
{
int withdraw;
cout<<"your balance is:"<<balance amount;
cout<<"enter the withdraw amount";
cin>>withdraw;
balance amount=balance amount-withdraw;
cout<<"your current balance is:"<<balance amount;
}

void bank :: deposite(void)
{
int deposite=0;
    cin>>deposite;
    deposite=deposite+balance amount;
    cout<<"Deposit Balance ="<<deposite;
    balance amount=deposite;
}

void bank :: display(void)
{
cout<<"DETAILS";
cout<<"name"<<nameofdepositer;
cout<<"A/c. No."<<ANO;
cout<<"A/c Type"<<actype;
cout<<"Balance"<<balance amount;
}

int main()
{
bank b;
b.intialvalue();
b.withdraw();
b.deposite();
b.display();
return 0;
}

output:

👉WITHOUT SCOPE RESOLUTION:


coding:                                      

#include<iostream>                                     
using namespace std;
class bank
{
char nameofdepositer[50];
int ANO;
char actype[30];
int balanceamount;
public:
void intialvalue()
{
char nameofdepositer[50];
int ANO;
char actype[30];
int balanceamount=0;
cout<<"Enter Name";
cin>>nameofdepositer;
cout<<"Enter A/c no";
cin>>ANO;
cout<<"Enter A/c Type";
cin>>actype;
}
void deposite()
{
int deposite;

 int balanceamount;
 cout<<"enter the deposite";
   cin>>deposite;
    balanceamount=balanceamount+deposite;
    cout<<"Deposit Balance ="<<balanceamount;
}
void withdraw()
{
 int withdraw;

 int balanceamount;
 cout<<"enter the balanceamount is "<<balanceamount;
 cout<<"enter the withdraw amount";
 cin>>withdraw;
 balanceamount=balanceamount-withdraw;
 cout<<"your current balance is:"<<balanceamount;
}
void display()
{
char nameofdepositer[100];
int ANO;
char actype[130];
int balanceamount;
cout<<"DETAILS";
cout<<"name"<<nameofdepositer;
cout<<"A/c. No."<<ANO;
cout<<"A/c Type"<<actype;
cout<<"Balance"<<balanceamount;
}
};
int main()
{
 bank b;
 b.intialvalue();
 b.deposite();
 b.withdraw();
  b.display();
 return 0; 
}

output: 


1 comment:

Copyright © 2013 free coding