Monday, 28 January 2013

Wirite a C/C++ program to define a class to represent a Bank Account.

This program for Turbo c++, write and compile/run it...
Define a class to represent a Bank Account. Include the following members:

A. Data Members:
     (i) Name of the Depositor.
     (ii) Account Number.
     (iii) Type of Account.
     (iv) Balance Amount.

B. Members Function:
     (i) To deposit an amount.
     (ii) To display Name and Balance.


#include<iostream.h>
#include<conio.h>

class BankAccount{
   char name[10], type[10];
   int ac;
   double bal;

   Public:

   void deposit(){
   cout<<"Name of Depositor:";
   cin>>name;
   cout<<"Account Number:";
   cin>>ac;
   cout<<"Enter Account Type:";
   cin>>type;
   cout<<"Balance:";
   cin>>bal;
  }

  void display(){
  cout<<"\nName :"<<name<<" Balance Rs. "<<bal<<"/-";
  }

};

void main(){
  BankAccount a[100];
  int i,n;
  clrscr();
  cout<<"List Length:";
  cin>>n;
  for(i=0; i<n; i++){
    a[i].deposit();
  }

  for(i=0; i<n; i++){

    a[i].display();
  }
  getch();
}

Output:
List Length:3

Name of Depositor: Asif
Account Number: 101
Enter Account Type: Savings
Balance: 2000

Name of Depositor: Sufia
Account Number: 102
Enter Account Type: Savings
Balance: 5000

Name of Depositor: Jayanta
Account Number: 103
Enter Account Type: Current
Balance: 1500


Name : Asif   Balance Rs.2000/-
Name : Sufia   Balance Rs.5000/-
Name : Jayanta   Balance Rs.1500/-

Thanks for watching...
Comment it...

2 comments: