lundi 19 mars 2018

KEEPS TRACK OF BANK TRANSACTION AND STORE THE DATA IN A FILE

#include <iostream>
#include <string>
#include<iomanip>
#include <fstream>

using namespace std;


class Bank
{
private:
    int acno;
    float balance;
    float amt;
    float bankCost;
    float more;
public:
    void newBalance();
    void withdraw();
    void deposit();
    void getbalance();
    void disp_det();
    };
//member functions of bank class
void Bank::newBalance()
{
cout<<"Enter the Account Number : ";
cin>>acno;
cout<<"Enter the Amount to Deposit : ";
cin >>balance;
}
void Bank::deposit()
{
cout <<"Depositing";
cout<<" - Enter the amount to deposit : ";
if(more!=0)
   cin>>more;
else
  more = 0;

balance+=more;
}
void Bank::withdraw()
{
cout<<"Withdrawal";
cout<<"Enter the amount to withdraw : ";
if(amt!=0)
    cin>>amt;
else
    more = 0;
    if(amt==1000)
    {
        bankCost= 25;
        balance-= (amt + bankCost);
    }
    else
    {
        balance-=amt;
    }
}
void Bank::getbalance()
{
cout<<"Account Details";
cout<<"Account Number        : "<<acno<<endl;
cout<<" Opening balance      : R"<<balance<<endl;
}
// main function , exectution starts here
int main()
{
ofstream statement ("data.dat");
Bank obj;
char choice;
while (choice != 'e' )
{
cout<<"Enter \n N- to enter new balance \n W- Withdraw\n D- Deposit \n B- get balance\n E Exit"<<endl;
cin>>choice;
switch(choice)
{
    case 'N' :obj.newBalance();
        break;
    case 'W'  :obj.withdraw();
        break;
    case 'D': obj.deposit();
        break;
    case 'B': obj.getbalance();
        break;
    case 'e':
        break;
    default: cout<<"continue with transaction"<<endl;
}
}
    return 0;

}

I want a code that will keep tract of all transactions by storing them in a file and displaying them. the end result should display as follows: Account number: 46780976 Opening balance: R3750.40 Transaction Amount Balance Bank costs Withdrawal 250.00 4000.00 Deposit 1200.00Ct 2800.00 Withdrawal 75.00 2725.00 Withdrawal 1375.00 1350.00 Deposit 1200.00Ct 1550.00 Interest 5.50 1555.50 Withdrawal 400.00 1155.50 Withdrawal 600.00 555.50 25.00 Deposit 450.00Ct 1005.50 Withdrawal 35.65 969.85 Banking costs 25.00 969.60 Closing balance: R969.60

Aucun commentaire:

Enregistrer un commentaire