Dec 2, 2014

Banking System

Define a class to represent a bank account which includes following members:
Data members –   i) Name
ii) Account number
iii) Type of account
iv) Balance Amount
Member functions –
a. To assign initial value
b. To deposit an account
c. To withdraw from an account
                                    d. To display name, account number & balance
                                    e.  To display All Account
                                    f. Delete An account



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

    class bank
    {
    public:
    char name[100];
    int ac_no;
    int deposit;
    char type ;

        void body()
        {
        system("cls");
        cout<<"\n\n\t\t ==================== Bank Management ====================\n\n";
        cout<<"\n\n\t\t 1. Create an account";
        cout<<"\n\n\t\t 2. Search account";
        cout<<"\n\n\t\t 3. Show all account";
        cout<<"\n\n\t\t 4. Deposit amount";
        cout<<"\n\n\t\t 5. withdraw amount";
        cout<<"\n\n\t\t 6. Delete an account";
        cout<<"\n\n\t\t 7. Exit";
        cout<<"\n\n\tSelect Your Option (1 ==>> 7)  ";

        }
    void getdata()
    {
        system("cls");
        cout<<"\nEnter The account No.              : ";
        cin>>ac_no;
        cout<<"\nEnter The Name of account Holder   :  ";
        cin>>name;
        cout<<"\nEnter Type of The account (S/C)    :  ";
        cin>>type;
        cout<<"\nEnter The Initial amount           :  ";
        cin>>deposit;
        cout<<"\n\n\n You have successfully  created  account..................";

    }

        void showdata()
        {
        cout<<"\nAccount No.          : "<<ac_no;
        cout<<"\nAccount Holder Name  : "<<name;
        cout<<"\nType of Account      : "<<type;
        cout<<"\nBalance amount       : "<<deposit;
        cout<<"\n\n ==================================================";
        }


void dep(int dw)
    {
        deposit+=dw;
    }

    void draw(int dw)
    {
        deposit-=dw;
    }

    int retacno()
    {
        return ac_no;
    }

    int retdeposit()
    {
        return deposit;
    }
    };

int main()
{

bank ac;
int n,dw ;
char option, select;


    FILE *fp, *ft;
    fp=fopen("users.txt","rb+");

    if (fp == NULL)
    {
        fp = fopen("users.txt","wb+");

            return 0;

    }

    while(1)
    {
    ac.body();
    select = getche();

        switch(select)
        {
        //Create account...................
        case '1':
        fseek(fp,0,SEEK_END);
        option ='Y';
        while(option == 'Y' || option == 'y')
        {
        ac.getdata();
        fwrite(&ac,sizeof(ac),1,fp);
        cout << "\n\n Create Another Account (Y/N) ";
        fflush(stdin);
        option = getchar();
        }
        break;

    //Search account.......................
            case '2' :
            system("cls");
            option = 'Y';
            while (option == 'Y'|| option == 'y')
            {
            cout << "\n\n Enter the account no  : ";
            cin >> n;
            rewind(fp);
            while (fread(&ac,sizeof(ac),1,fp)==1)
            {
            if (ac.retacno()== n)
            {
            ac.showdata();
            break;
            }
            }
            cout << "\n Find  Another Account (Y/N) ";
            fflush(stdin);
            option = getchar();
            }
            break;

        //Display all account......................
            case '3':
            system("cls");
            rewind(fp);
            cout << "\n\n=======================  View all Account ==================";
            cout << "\n";
            while (fread(&ac,sizeof(ac),1,fp))
            {
            ac.showdata();
            }
             cout << "\n\n";
            system("pause");
            break;

    //Deposit account...............
            case '4' :
            system("cls");
            option = 'Y';
            while (option == 'Y'|| option == 'y')
            {
            cout << "\n Enter the account no  : ";
            cin >> n;
            rewind(fp);
            while (fread(&ac,sizeof(ac),1,fp)== 1)
            {
            if (ac.retacno()== n)
            {
            ac.showdata();
            cout<<"\n\n\t\t\t ========= deposit amount ========== ";
            cout<<"\n\n Enter The amount to be deposited :  ";
            cin>>dw;
            ac.dep(dw);
            fseek(fp, - sizeof(ac), SEEK_CUR);
            fwrite(&ac,sizeof(ac),1,fp);
            break;
            }
            }
            cout << "\n\n Find another account..... (Y/N) ";
            fflush(stdin);
            option = getchar();
            }
            break;

         //Withdraw  account...............
            case '5' :
            system("cls");
            option = 'Y';
            while (option == 'Y'|| option == 'y')
            {
            cout << "\n Enter the account no  : ";
            cin >> n;
            rewind(fp);
            while (fread(&ac,sizeof(ac),1,fp)== 1)
            {
            if (ac.retacno()== n)
            {
            ac.showdata();
            cout<<"\n\n\t ========= Withdraw Amount ========== ";
            cout<<"\n\n Enter The amount to be Withdraw :  ";
            cin>>dw;
            int  bal=ac.retdeposit()-dw;
            if(bal<500)
            {
            cout<<"\n\n No enough balance";
            }
            else
            ac.draw(dw);
            fseek(fp, - sizeof(ac), SEEK_CUR);
            fwrite(&ac,sizeof(ac),1,fp);
            break;
            }
            }
            cout << "\n\n Find another account..... (Y/N)  ";
            fflush(stdin);
            option = getchar();
            }
            break;

     //Delete account...............
           case '6':
            system("cls");
            option = 'Y';
            while (option == 'Y'|| option == 'y')
            {
            cout << "\n Enter the account no to delete : ";
            cin >> n;
            ft = fopen("temp.dat", "wb");
            rewind(fp);
            while (fread (&ac, sizeof(ac),1,fp) == 1)
            if (ac.retacno()!= n)
            {
            fwrite(&ac,sizeof(ac),1,ft);
            }
            fclose(fp);
            fclose(ft);
            remove("users.txt");
            rename("temp.dat","users.txt");
            fp=fopen("users.txt","rb+");
            cout << "\n Delete another account... (Y/N) ";
            fflush(stdin);
            option = getchar();
            }
            break;

            case '7':
            fclose(fp);
            system("cls");
            cout << "\n\n";
            cout << "\t\t********************************************************"<<endl;
            cout << "\t\t*          THANKS BY MUJAFFOR , Batch-46, AUB          *"<<endl;
            cout << "\t\t********************************************************"<<endl;
            cout << "\n\n";
            exit(0);
        }
    }


    system("pause");
    return 0;
}

No comments:

Create a Diamond in C++

 #include<iostream> using namespace std; int main() { int i, j, k,r; cout<<"Enter the row of diamond   "; cin>>r...