Saturday, 18 February 2017

Class of bank account with A/C holder data

In this program we will create class of bank and enter A/C holder data and information about account also withdraw or deposit money by asking user.
The code is given below.


//Code Starts

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

using namespace std;

struct coustomer{
         
          char name[50],address[100],cnic[13],mon[10],actype[100];
          int age,bal,acno,dep,draw,rem,ammount,x,day,year;
         
};

class bank{
          private:
          char account,achold[100];
          int deposite,withdraw;
          coustomer c;
         
          public:
                   
            char setachold();
            char  setaccount();
            int  setdeposite();
      int  setdate();
            int  setwithdraw();
           
           
                      char*         getachold();
                      char getaccount();
                      int  getdeposite();
                      int  getwithdraw();
                     
                      void display();
         
};

int main()
{
          bank b;

          b.display();
         
          getch();
         
}



char bank::setachold()
{
         
          cout<<"Enter Account holder name : ";
          cin.getline(c.name,50);
         
          cout<<"Enter "<<c.name<<"'s' age  : ";
          cin>>c.age;
                   
          cout<<"Enter "<<c.name<<"'s address : ";
          cin>>c.address;
         
          cout<<"Enter "<<c.name<<"'s' CNIC : ";
          cin>>c.cnic;
}

int bank::setdate()
{
          cout<<"Please enter date in following format dd/mm/yy"<<endl;
          cout<<"Enter Day : ";
          cin>>c.day;
         
          cout<<"Enter month : ";
          cin>>c.mon;
         
          cout<<"Enter year : ";
          cin>>c.year;
         
}
char bank::setaccount()
{
          cout<<"Enter "<<c.name<<"'s account type : ";
          cin>>c.actype;
         
          cout<<"Enter "<<c.name<<"'s account number : ";
          cin>>c.acno;
         
          cout<<"Enter "<<c.name<<"'s balance in "<<c.actype<<" account : ";
          cin>>c.bal;
}

int bank::setdeposite()
{

          cout<<"How many amount you want to deposite in "<<c.acno<<" : ";
          cin>>c.dep;
         
          c.rem=c.bal+c.dep;
         
          cout<<c.name<<"'s new balance after depositing "<<c.dep<<" RS in account no :"<<c.acno<<" === "<<c.rem<<endl;
}

int bank::setwithdraw()
{
          cout<<"How many amount you want to withdarw from "<<c.acno<<" : ";
          cin>>c.draw;
          if(c.draw>c.bal)
                    {
                              cout<<"You don't have sufficient ammount to withdraw";
                    }
else{

          c.ammount=c.rem-c.draw;
         
          cout<<c.name<<"'s new balance after withdraw of  "<<c.draw<<" RS from account no :"<<c.acno<<" === "<<c.draw<<endl;;
}

}


char* bank::getachold()
{
          return achold;
}

char bank::getaccount()
{
          return account;
}

int bank::getdeposite()
{
          return deposite;
}

int bank::getwithdraw()
{
          return withdraw;
}



void bank::display()
{
    bank b;

          b.setachold();
          b.setdate();
          b.setaccount();

         
abc:   cout<<"For deposite press 1 and for withdraw Press 2 ";
          cin>>c.x;
         
          if(c.x==1)
          {
                    b.setdeposite();
          }
         
          else if(c.x==2)
          {
                    b.setwithdraw();
         
          }
          else{
                    cout<<"Invalid Entry please re-enter"<<endl;
                    goto abc;
          }
          cout<<" "<<endl;
         


}

//Code Ends

OUTPUT:

Share:

Class of bank management with password

In this program we will create a class of bank management system to access the system user needs to enter password then the result of deposit and withdraw will be shown at the end.
The code is given below.

//Code starts
#include<iostream>
#include<conio.h>
using namespace std;

class account{
         
          private:
              int bal,dep,withdraw,acno;
              char name[100];
             
              public:
                   
                    int setbal();
                    int setdep();
                    int setwithdraw();
                    int setacno();
                    char setname();
                   
                    int getbal();
                    int getdep();
                    int getwithdraw();
                    int getacno();
                    char* getname();
                   
                    void display();
                   
};

char account::setname()
{
          cout<<"Enter your name : "<<endl;
          cin>>name;
}

int account::setacno()
{
          cout<<"Enter your Account Number: "<<endl;
          cin>>acno;
}

int account::setbal()
{
          cout<<"Enter Your Account Balance: "<<endl;
          cin>>bal;
}

int account::setdep()
{
          cout<<"Enter Amount to be deposite : "<<endl;
          cin>>dep;
}

int account::setwithdraw()
{
          cout<<"Enter Ammount to be withdraw :"<<endl;
          cin>>withdraw;
}

char* account::getname()
{
          return name;
}

int account::getacno()
{
          return acno;
}

int account::getbal()
{
          return bal;
}

int account::getdep()
{
          return dep;
}

int account::getwithdraw()
{
          return withdraw;
}

void account::display()
{
          cout<<"Name : "<<getname()<<endl;
          cout<<"A/C No :  "<<getacno()<<endl;
          cout<<"Balance : "<<getbal()<<" RS "<<endl;
          cout<<"Deposte : "<<getdep()<<" RS "<<endl;
          cout<<"Withdraw :  "<<getwithdraw()<<" RS "<<endl;
}

int main()
{    
       int pass,a,b;
      
         
          account a1;
abc:   cout<<"Enter Password: "<<endl;
                    cout<<"Hint: 12345"<<endl;
                    cin>>pass;
         
          if(pass==12345)
{

cout<<"Welcome to Bank Management System: "<<endl;

}
else{
          cout<<"Re-enter Password:  "<<endl;
          goto abc;
}

          a1.setname();
          a1.setacno();
          a1.setbal();
          a1.setdep();
          a=a1.getbal()+a1.getdep();
          cout<<"Amount after deposite : "<<a<<" RS."<<endl;
         
def:    a1.setwithdraw();
                   
          if(a1.getwithdraw()>a)
          {
                    cout<<"Enter amount less than "<<a<<" RS. "<<endl;
                    goto def;
          }
          else{
                    b=a-a1.getwithdraw();
                              cout<<"Amount after withdraw : "<<b<<" RS."<<endl;
          }

         
    cout<<"===============OUTPUT=================="<<endl;

a1.display();

getch();


}

OUTPUT:




Share:

C++ program of entering employee data and showing its output

In this program we will enter the record of employee and shows its output if the user wants.
The Code is given below.


//Code Starts
#include<iostream>
#include<conio.h>

using namespace std;

struct addr
{
       char houseno[20];
       char street[30];
       char city[20];
       char state[20];
};
struct emp
{
       char empno[10];
       char name[20];
       char desig[20];
       addr address;
       float basic;
}worker;

int main()
{
          emp evar;

  cout<<"Employee No: ";
  gets(evar.empno);
  gets(evar.name);
  cout<<"Designation: ";
  gets(evar.desig);
  cout<<"House No: ";
  gets(evar.address.houseno);
  cout<<"Street: ";
  gets(evar.address.street);
  cout<<"City: ";
  gets(evar.address.city);
  cout<<"State: ";
  gets(evar.address.state);
  cout<<"Basic Pay: ";
  cin>>evar.basic;
    cout<<endl;

     char ch;
     cout<<"Want to see ? (y/n)...";
     cin>>ch;
     if(ch=='y' || ch=='Y')
          {
  cout<<"\nEmployee Data:\n";
  cout<<"Employee No: "<<evar.empno;
  cout<<"\nName: "<<evar.name;
  cout<<"\nDesignation: "<<evar.desig;
  cout<<"\nAddress: "<<evar.address.houseno<<", ";
  cout<<evar.address.street<<", ";
  cout<<evar.address.city<<", ";
  cout<<evar.address.state<<endl;
  cout<<"Basic Pay: "<<evar.basic;
  cout<<"\n";
          }

          getch();

}


//Code Ends



Share:

Class of student data

In this program we will create class of student and enter his record using setter and getter function with one extra function of display.
The code is given below.

//Code starts 
#include<iostream>
#include<conio.h>
using namespace std;

class stu
{
          private:
                    char nam[30],id[30];
                    float cgpa;
          public:
                    char setname();
                    char setid();
                    float setcgpa();
                   
                    char* getname();
                    char* getid();
                    float getcgpa();
                   
                    void display();     
};

char stu::setname()
{
          cout<<"Enter Student's name: ";
          cin>>nam;
}
char stu::setid()
{
          cout<<"Enter Student's ID: ";
          cin>>id;
}

float stu::setcgpa()
{
          cout<<"Enter CGPA of Student: ";
          cin>>cgpa;
}

char* stu::getname()
{
          return nam;
}

char* stu::getid()
{
          return id;
}

float stu::getcgpa()
{
          return cgpa;
}

void stu::display()
{
stu  s;     //creating object of class
          s.setname();
          s.setid();
          s.setcgpa();
}

int main()
{
          stu s1; //creating object of class
         
          s1.display();
         
          getch();

}
//code ends


Share:

C++ program of finding size and address of variable

In this program we will learn how to find address and size of variable.
The code is given below.

//Code starts

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
          float x=1265.234;
          int y=12389;
         
          cout<<"Float: "<<x<<"\n";
          cout<<"Address of "<<x<<"= "<<&x<<endl;
          cout<<"Size of "<<x<<"= "<<sizeof(x)<<endl;
         
          cout<<"Integer: "<<y<<"\n";
          cout<<"Address of "<<y<<"= "<< &y<<endl;
          cout<<"Size of "<<y<<"= "<<sizeof(y);
          getch();
}

//Code ends


Share: