Dynamic Memory

 #include <iostream>

#include <fstream>
#include<cstdio>
#include<stdio.h>
#include <string>
#include "Header.h";
#include <stdlib.h>
#include <time.h>
#include <stdlib.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];
        string 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 = to_string(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 << "A/C=" << 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) << "Debit"
                        << setw(20) << balance.amount
                        << setw(10) << balance.date << endl;
                    creditSum = creditSum + balance.amount;
                }
                else {
                    //Debit
                    cout << left << setw(10) << i++
                        << setw(20) << "Credit"
                        << setw(20) << balance.amount
                        << setw(10) << balance.date << endl;
                    debitSum = debitSum + balance.amount;
                }

            }

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


        }
   
    }

    //Jama
    void CreditDebitAmount() {

        Balance balance;
        int code;
        string account;
        cin.ignore();
        cout << "Please Input account No:\n";
        cin >> account;
        SS:
        cout << "\n\nPlease Select Opration:\n";
        cout << "-1 Withdrawl (Debit):\n";
        cout << "-2 Deposite (Credit):\n";
        cin >> code;
       
        if (code == 1) {
            cout << "Please Input Debit amount:\n";
        }
        else if (code == 2) {
            cout << "Please Input credit amount:\n";
        }
        else {
            goto SS;
        }

        cin >>balance.amount;


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

        //========
        balance.type = code;

       

        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();
        }
       

    }


    void CloseAccount() {
        string account;
        cout << "Please Inpute Account Number:\n";
        cin >> account;
        char key;
        cout << "Note: Ones you delete your account you cant recover bank account:\n";
        cout << "Are you sure delete account:(y/n)\n";
        cin >> key;
        if (key == 'y' || key == 'Y') {
            remove((account + "p.txt").c_str());
            remove((account + "b.txt").c_str());
        }
   

    }

    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;

    }

};



class AAA {
public:
    int a, b; /// step 1  2 byte 4 byte
   
             

              // step 2
    AAA(int a,int b) {
        cout << "Constructorn\n";
        cout << "Sum=" << (a + b)<<endl;
    }

    void fun1() {
        int x=20, y=5;
        cout << "Mul=" << (x*y) << endl;
    }
    int fun2() {
        cout << "Please Input 2 number";
        cin >> a >> b ;

        return (a + b);
    }

    ~AAA() {
        cout << "Distructor\n ";
    }

};



int main() {

    //===Inpute How Many element Read 20 => elementsize ()
    //=======int number[5]


    int no[5];
    //AAA* obj = new AAA(12,34);
    //obj->fun1();

    ////dymnamic declar
    //int c= obj->fun2();
    //cout << "C=" << c << endl;


    //==========use========
    for (int i = 0; i < 5; i++) {
        cin >> no[i];
    }

    int sum = 0;
    for (int i = 0; i < 5; i++) {
        sum=sum+ no[i];
    }

    cout << "Sum=" << sum;


    //
    //int* a = new int();//
    //*a= 10;  ///  &a a&
    //cout << "a=" << *a<< " b="<<&a;

    //delete a;
    //
    //
    //cout << "a=" << *a << " b=" << &a;

    return 0;
}



void BANK() {
    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) Withdrawl (Debit):\n";
    cout << "4  Close Account:\n";

    cin >> code;

    switch (code)
    {
    case 1:
        bank.CreateAccount();

        break;
    case 2:
        bank.ShowBalence();
        break;
    case 3:
        bank.CreditDebitAmount();

        break;
    case 4:
        bank.CloseAccount();
        break;

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

    cout << "\nPress M for Menu:";
    cin >> key;
    if (key == 'M' || key == 'm') {
        system("cls");
        goto XX;
    }
    else {
        cout << "\nInvalid Code:" << endl;
    }



}



Comments

Popular posts from this blog

Dynamic Memory2

Template

MultiLevel