Image

Programs - C++ - Class and Object

Program:


#include"iostream.h"
#include"conio.h"
#include<string.h>
class bank
 {

protected:
  char name[20],addr[20],type;
  int actno;
public:
  void read()
  
{
   cout<<"enter actno,name,addr,type[s/c]\n";
   cin>>actno>>name>>addr>>type;
  }
  };
class amount:public bank
  {
  private:
  float bal;
  public:
  void balance()
  
{
   char oper;
   float amt;
   cout<<"balance,operator[d/w]&amount";
   cin>>bal>>oper>>amt;
   if(oper=='d')
   {
   bal=bal+amt;
   }
   if(oper=='w')
   {
   if(type=='s')
   {
    if(bal-amt>=1000)
    {
    bal=bal-amt;
    cout<<"amt withdrawl";
    }
    else
    {
    cout<<"amt NOT withdrawl";
    }
   }
   else
   {
    if(bal-amt>=2000)
    {
    bal=bal-amt;
    cout<<"AMT WITHDRAWL";
    }
    else
    {
    cout<<"AMT not WITHDRAWL";
    }
   }/*else end*/
   }/*oper==w*/
  }/*void balance*/
   void display()
  
{
   cout<<actno<<name<<addr<<type<<bal;
   }

  };
void main()
{
  amount a;
  a.read();
  a.balance();
  a.display();
  getch();
  }