21.3 ACCOUNT AND FINANCE

21.3.1 Bank account

Problem: Define a class to represent bank account. Include the following members:

Data members:

  1. Name of depositor.
  2. Account number.
  3. Type and account.
  4. Balance amount in the account.

Member functions:

  1. To assign initial values.
  2. To deposit an amount.
  3. To withdraw an amount after checking the balance.
  4. To display name and balance.

Write a main function to test the program.

Solution: See Program 21.6.

Program 21.6 Bank account

// bank3.cpp

#include<iostream.h>

#include<string.h>

class BankAccount

{ protected :

    char name[20] ;

    int accNumber ;

    int bal ;

  public:

    BankAccount(char *p,int i,int j) ;

    void deposit(int sum);

    int withdraw(int sum) ;

    void display();

};

int main() ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.