Bank4

 #include <iostream>

#include <fstream>
#include<cstdio>
#include<stdio.h>
#include <string>
#include "Header.h";
#include <stdlib.h>
#include <time.h>
#include<iomanip>
using namespace std;


struct Balance
{
    int type;
    int amount;
    char date[20];
};

//Credit=1
//Debot=2

class Bank {
    int amount;
public:
    void CreateAccount() {
        char name[250];
        string dob;
        string mobile;
        char address[300];
        int account;

        cin.ignore();
        cout << "Please Input Name:\n";
        cin.getline(name, 250);

        cout << "Please Input DOB:\n";
        cin >> dob;

        cout << "Please Input Mobile:\n";
        cin >> mobile;

        cin.ignore();
        cout << "Please Input address:\n";
        cin >> address;

        account =  GenrateAccountNumber();




        //==============P=======
        ofstream file_p(account+"p.txt");
       
        if (file_p.is_open()) {
            file_p << "Name=" << name << endl;
            file_p << "DOB=" << dob << endl;
            file_p << "Mobile" << mobile << endl;
            file_p << "Address=" << address << endl;
            file_p.close();
        }

        //==============P=======
        ofstream file_b(account + "b.txt");
        file_b.close();

        //===========================Passbook========
        cout << "=====================================================" << endl;
        cout << left << setw(20) << "Name" << name << endl;
        cout << left << setw(20) << "Mobile" << mobile << endl;
        cout << left << setw(20) << "DOB" << dob << endl;
        cout << left << setw(20) << "A/c" << account << endl;
        cout << left << setw(20) << "Branch" << "Elegant ID" << endl;


    }

    void ShowBalence() {
        string account;
        cin.ignore();
        cout << "Please Input account No:\n";
        cin >> account;

        ifstream file_p(account + "p.txt");

        if (file_p.is_open()) {
            string tempdata;
            while (getline(file_p,tempdata))
            {
                cout << tempdata <<endl;
            }
        }
        file_p.close();
        //=================Show Balance======

        ifstream file_b(account + "b.txt",ios::binary);
        if (file_b.is_open()) {
            Balance balance;
            int creditSum=0, debitSum=0;
            int i = 1;
            cout << left<<setw(10)<< "SR  "<<setw(20)<<" Action Type  "<<setw(20)<<"  Amount   "<<setw(10)<<"   Date   " << endl;
            cout << "===============================================================================================================\n";


            // Read until the end of the file
            while (file_b.read(reinterpret_cast<char*>(&balance), sizeof(Balance))) {

                if (balance.type == 1) {
                    //Credit
                    cout << left << setw(10) << i++
                        << setw(20) << "Credit"
                        << setw(20) << balance.amount
                        << setw(10) << balance.date << endl;
                    creditSum = creditSum + balance.amount;
                }
                else {
                    //Debit
                    cout << left << setw(10) << i++
                        << setw(20) << "Debit"
                        << setw(20) << balance.amount
                        << setw(10) << balance.date << endl;
                    debitSum = debitSum + balance.amount;
                }

               

            }

            file_b.close();
            cout << "===============================================" << endl;
            cout << "Total Balence:" << (creditSum - debitSum);


        }
   
    }

    //Jama
    void CreditAmount() {

        Balance balance;

        string account;
        cout << "Please Input account No:\n";
        cin >> account;


        cout << "Please Input credit amount:\n";
        cin >>balance.amount;


        cout << "Please Input  current date:\n";
        cin >> balance.date;

        cout << "Please Input  opration type:\n";
        cin >> balance.type;

       

        ofstream file_b(account + "b.txt", ios::binary | ios::out |ios::app);

        if (file_b.is_open()) {

            file_b.write(reinterpret_cast<char*>(&balance), sizeof(balance));
            file_b.close();
        }
       

    }

    int GenrateAccountNumber() {
        // Seed the random number generator with the current time
        srand(time(0));

        // Generate a random number between 1 and 100
        int random_number = rand() % 10000 + 1;

        return random_number;

    }

};




int main() {
    Bank bank;
    char key;
    int code;
    XX:
    cout << "Input Code for opration:\n";
    cout << "1  Create Account:\n";
    cout << "2  Show Balance:\n";
    cout << "3  Deposite (Credit):\n";
    cout << "4  Withdrawl (Debit):\n";
    cout << "5  Close Account:\n";

    cin >> code;

    switch (code)
    {
    case 1:
        bank.CreateAccount();
        cout << "Press M for Menu:";
        cin >> key;
        if (key == 'M' || key == 'm') {
            goto XX;
        }
        else {
            cout << "Invalid Code:" << endl;
        }
        break;
    case 2:
        bank.ShowBalence();
        cout << "Press M for Menu:";
        cin >> key;
        if (key == 'M' || key == 'm') {
            goto XX;
        }
        else {
            cout << "Invalid Code:" << endl;
        }
        break;
    case 3:
        break;
    case 4:
        break;
    case 5:
        break;

    default:
        cout << "Invalid Code Please input valid code:\n";
        goto XX;
        break;
    }


    bank.ShowBalence();
    //bank.CreditAmount();
    //bank.CreateAccount();
    //cout << bank.GenrateAccountNumber()<<endl;
   
   

    return 0;
}




Comments

Popular posts from this blog

Dynamic Memory2

Template

MultiLevel