Pages

Thursday, July 11, 2013

Banking System in Classes In C++

/*
QUESTION:
AIM: Define a class to represent a bank account .Include the following members:

Data Members:

a Name of the depositor

b Account number

c Type of account

d Balance amount in the account




Member Functions:


a To assign initial values

b To deposit an amount

c To withdraw an amount after checking the balance

d To display name and balance

CODE:
*/


 #include<iostream>
using namespace std;
class Bank{
private:
 char name[20];
 char type_ac[20];
 int ac_no;
 long int balance;
public:
 Bank(){
  for(int i=0;i<20;i++){
   name[i]= ' ';
   type_ac[i] = '\0';
  }
  ac_no =0;
  balance = 0;
 }
 void bank_funct(char *n,char *t_a,int a_n ,int bal){
  strcpy(name,n);
  strcpy(type_ac,t_a);
  ac_no = a_n;
  balance = bal;
 }
 void deposit_amount(int bal){
  balance = bal;
 
 
 }

 void withdraw(int bal){
  if(bal > balance)
   cout<<"\nYou don have enough balance";
  else{
   cout<<"\nAmount Withdrawn is"<<bal<<endl;
   balance -=bal;
  
  }
 
 }
 void display(){
  cout<<"\nName is: "<<name;
  cout<<"\nBalance is: "<<balance<<endl;
 
 
 }

};


int main(){
 Bank obj1;
 char opt = ' ';
 char name[20];
 char account_type[20];
 int account_No;
 int balance;

 while(1){
 cout<<"\nEnter 'a' To assign initial values";

 cout<<"\nEnter 'b' To deposit an amount";

 cout<<"\nEnter 'c' To withdraw an amount";

 cout<<"\nEnter 'd' To display name and balance"<<endl<<endl;
 cin>>opt;

 switch(opt){
 case 'a':
  {cout<<"\nEnter name: ";
   cin>>name;
   cout<<"\nEnter Account type: ";
   cin>>account_type;
   cout<<"\nEnter Account number: ";
   cin>>account_No;
   cout<<"\nEnter balance: ";
   cin>>balance;
         obj1.bank_funct(name,account_type,account_No,balance);

  }
  break;
 case 'b':
   
        cout<<"Enter amount you wan to deposit";
  int balance1;
  cin>>balance1;
  obj1.deposit_amount(balance1);
  break;
 case 'c':
  cout<<"\nEnter amount to be withdrawn: ";
  int bal;
  cin>>bal;
  obj1.withdraw(bal);

  break;
 case 'd':
  obj1.display();
  break;
 default:
 
  break;
 }

 }
 return 0;
}
 

No comments:

Post a Comment