[code]#include <iostream>
#include <fstream>
#include <conio.h>
#include <ctime>
using namespace std;
////////////////////////////////////////////////////////////////////////////////
class account{
public:
account(){
i = 0;
balance = 0;
transaction_during_one_day = 0;
one_month_balance = 0;
minimumBalance = 99999999999999;
startTime = clock();
}
//````````````````````````````````````````````````````````````````````````````````````````````````
void depositBalance(){
cout << "Enter Amount to Deposit: "; cin >> depositAmount;
balance += depositAmount;
fstream fs("balance_Record.txt", ios::app | ios::out | ios::in);
fs << balance << endl;
fs.close();
//Setting minimum Balance.
double currentTime = clock();
double timeElapsed = currentTime - startTime;
double seconds = (double) timeElapsed/CLOCKS_PER_SEC;
if (minimumBalance > balance){
minimumBalance = balance;
}
if (seconds >= 2.62974*1000000){
one_month_balance = minimumBalance;
startTime = 0;
}
}
//````````````````````````````````````````````````````````````````````````````````````````````````
void withDraw(){
bool fine = 0;
if (i == 0){ //first time.
sTime = clock();//Time starts when First Transaction is done.
}
i = 1;
do{
cout << "Enter Amount to withdraw: "; cin >> withDrawAmount;
cTime = clock();
double diffT = cTime - sTime;
double seconds = (double) diffT/CLOCKS_PER_SEC;
if(seconds <= 86400){ //During 1 Day.
transaction_during_one_day += withDrawAmount;
}
if (seconds > 86400){
sTime = clock();
}
if (withDrawAmount > balance){
cout << "You do not have sufficient amount of Money in your account." << endl;
fine = 0;
}
else{
if (withDrawAmount>=5000){
withDrawAmount -= (withDrawAmount * 0.002); // 0.2% "service charges" Deducted during transaction over 5000.
}
balance -= withDrawAmount;
fine = 1;
if (transaction_during_one_day > 50000){
balance -= 2.5*0.01*transaction_during_one_day;
}
}
}while (fine == false);
}
//````````````````````````````````````````````````````````````````````````````````````````````````
double getBalance(){
return balance;
}
//````````````````````````````````````````````````````````````````````````````````````````````````
void displayBalance(){
cout << "Balance: " << balance << endl;
}
//````````````````````````````````````````````````````````````````````````````````````````````````
public: double balance;
protected:
bool i;
char accountType[50];
double minimumBalance;
double transaction_during_one_day;
double startTime;
double sTime;//startTime;
double cTime;//currentTime
double one_month_balance;
double depositAmount;
double withDrawAmount;
};
////////////////////////////////////////////////////////////////////////////////
class savingAccount: virtual public account{
public:
savingAccount(){
minimumBalance = balance;
strcpy(accountType,"Saving Account");
}
void setInterest(){
// double endTime = clock();
// double timeElapsed = endTime - startTime;
// double time_elapsed_in_seconds = (double)timeElapsed/CLOCKS_PER_SEC; //convert to seconds
// if (time_elapsed_in_seconds > 30){
interest = one_month_balance*0.01;
interest = interest - interest*0.5*0.01;//The profit/interest paid to the customer is subject to a 0.5% tax to be deducted from the account automatically (applicable only to saving accounts)
balance += interest;
cout << "Balance: " << balance << endl;
// }
}
double getInterest(){
return interest;
}
protected:
double interest;
};
////////////////////////////////////////////////////////////////////////////////
class creditCard: public account{
public:
creditCard();
virtual void calculate() = 0;
protected:
static long no;
double interest;
double upperLimit;
};
//````````````````````````````````````````````````````````````````````````````````````````````````
creditCard::creditCard(){
no += 1;
}
////////////////////////////////////////////////////////////////////////////////
class masterCard: public creditCard{
public:
void calculate();
};
//``````````````````````````````````````````````````````````````````````````````
void masterCard::calculate(){
interest = balance *18*0.01;
upperLimit = 50000;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
class visaCard: public creditCard{
public:
void calculate();
};
//``````````````````````````````````````````````````````````````````````````````
void visaCard::calculate(){
interest = balance * 10*0.01;
upperLimit = 100000;
}
////////////////////////////////////////////////////////////////////////////////
class checkingAccount: virtual public account{
public:
checkingAccount(){
strcpy(accountType,"Checking Account");
}
void DepositBalance(){
account::depositBalance();
}
double getBalance(){
return balance;
}
};
////////////////////////////////////////////////////////////////////////////////
class localCard: public creditCard{
public:
localCard();
void calculate();
private:
int i;//3 time,
};
//````````````````````````````````````````````````````````````````````````````````````````````````
localCard::localCard(){
i = 0;
}
//````````````````````````````````````````````````````````````````````````````````````````````````
void localCard::calculate(){
if (i<=4)
if (depositAmount >= balance){
++i;
}
if (i<=3){
interest = balance * 25*0.01;
upperLimit = 10000;
}
else{
interest = balance * 20*0.01;
upperLimit = 15000;
}
}
//////////////////////////////////////***LINKED LIST***///////////////////////////////////////////
struct link: virtual public checkingAccount, virtual public savingAccount, virtual public masterCard, virtual public visaCard, virtual public localCard{
link();
void getData();
void print();
void withDraw();
static unsigned long int id;
char firstName[100];
char middleName[100];
char lastName[100];
unsigned long int cnic;//???????BALANCE??
char address[5000];
unsigned long int tel; //Telephone Number.
char date_of_birth[100];
char creditCard[50];
link* next;
bool masterCardFlag;
bool localCardFlag;
bool visaCardFlag;
};
//``````````````````````````````````````````````````````````````````````````````
link::link(){
++id;
cnic = tel = masterCardFlag = localCardFlag = visaCardFlag = 0;
}
//``````````````````````````````````````````````````````````````````````````````
void link::getData(){
cout << "First Name: "; cin >> firstName;
cout << "Middle Name: "; cin >> middleName;
cout << "Last Name: "; cin >> lastName;
cout << "CNIC: "; cin >> cnic; cin.ignore();
cout << "Address: "; cin.getline(address,100,'\n');
cout << "Telephone Number: ";cin >> tel;
cout << "Account Type: "; cin >> accountType; //Inserted at accountType of 'account' base class.
cout << "Do you want to have a credit card? (y/n): "; char opt = getch();
switch(opt){
case 'y':
cout << "Which Credit Card:\n"
<< "1. Master Card\n"
<< "2. Local Card\n"
<< "3. Visa Card\n" << endl;
opt = getch();
switch(opt){
case '1':
masterCardFlag = 1;
masterCard::calculate();
break;
case '2':
localCardFlag = 1;
break;
case '3':
visaCardFlag = 1;
break;
}
break;
case 'n':
cout << "No problem dear." << endl;
break;
}
account::depositBalance();
}
//``````````````````````````````````````````````````````````````````````````````
void link::print(){
cout << "First Name: " << firstName << endl;
cout << "Middle Name: " << middleName << endl;
cout << "Last Name: " << lastName << endl;
cout << "CNIC: " << cnic << endl;
cout << "Address: " << address << endl;
cout << "Telephone Number: " << tel << endl;
cout << "Credit Card: " << creditCard << endl;
cout << "Balance: " << balance << endl;
}
//``````````````````````````````````````````````````````````````````````````````
void link::withDraw(){
account::withDraw();
}
////////////////////////////////////////////////////////////////////////////////
class ll: public masterCard, public visaCard, public localCard, public savingAccount, public checkingAccount{
public:
ll();
void insertNode();
void find();
void update();
void Delete();
void display_all_accounts_of_particular_type();
void deposit();
void WithDraw();
private:
link* head;
link* tail;
};
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
ll::ll(){
head = tail = NULL;
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void ll::insertNode(){
link* temp = new link;
temp->next = 0;
temp->getData();
if (head == 0 && tail == 0){
head = temp;
tail = temp;
}
else{
tail->next = temp;
tail = temp;
}
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void ll::find(){
char opt;
unsigned long int acc;
unsigned long int cnic;
do{
cout << "Enter Account Number OR CNIC number.\nPress 1 to enter account number\nPress 2 to enter CNIC number: "; cin >> opt;
switch(opt){
case '1':
cout << "Account Number: "; cin >> acc;
break;
case '2':
cout << "CNIC: "; cin >> cnic;
break;
default:
cout << "Wrong input." << endl;
cout << "Re_Enter" << endl << endl;
break;
}
}while ((opt != '1') && (opt != '2'));
//Finding in the linked list.
for (link* p = head; p != NULL; p = p->next){
if (p->cnic == cnic || p->id == acc){
p->print();
}
}
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void ll::update(){
cout << "Enter CNIC: "; int cnic; cin >> cnic;
for (link*p = head; p!=NULL; p = p->next){
if (cnic == p->cnic){
cout << "FOUND! " << endl;
cout << "\nCurrent Account Information:\n";
p->print();
cout << "\nEnter modified details";
p->getData();
break;
}
}
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void ll::Delete(){
if (head == NULL){
cout << "Cannot Delete. No record Entered" << endl;
}
else{
cout << "Enter CNIC: "; int cnic; cin >> cnic;
for (link*p = head; p!=NULL; p = p->next){
if (cnic == p->cnic){
//delete this node.
if (p == head){
head = head->next;
delete p;
p = 0;
}
else{
for (link* b = head; b->next != p; b=b->next);//b points just before p.
b->next = p->next;
delete p;
p = 0;
}
break;
}
}
}
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void ll::display_all_accounts_of_particular_type(){
if (head == NULL){
cout << "Cannot Display. No record Entered" << endl;
}
else{
cout << "Enter Account Type/Credit Card: "; char accountType[50]; cin >> accountType;
for (link* p = head; p != NULL; p = p->next){
if ( /*(strcmp(p->accountType,accountType)) ||*/ (strcmp(p->creditCard,accountType)) ){
cout << "-----------------------------------------------" << endl;
p->print();
}
}
cout << "-----------------------------------------------" << endl;
}
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void ll::deposit(){
cout << "Enter CNIC of Account Holder: "; unsigned long int cnic; cin >> cnic;
//finding required Account Holder.
for (link* p = head; ((p != NULL) && (p->cnic != cnic)); p = p->next);//p points to the Account holder in which we'll DEPOSIT.
cout << "Enter Amount to Deposit: "; unsigned long double amount; cin >> amount;
unsigned long double previousBalance = checkingAccount::getBalance();
p->balance += amount;
cout << "Deposited." << endl
<< "Previous Balance: " << previousBalance << endl
<< "Current Balance: " << p->balance << endl;
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void ll::WithDraw(){
cout << "Enter CNIC: "; double cnic; cin >> cnic;
//Search This CNIC in your link list:
if (head == 0){
cout << "Sorry Account is Empty." << endl;
exit(0);
}
for (link* p = head; (p!=NULL) && (p->cnic!=cnic); p = p->next){
}// p points to the desired Data.
p->withDraw(); //withDraw is same for Checking and Saving Account.
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void gotoxy(int,int);
void employeeMenu2();
void creatAccount();
void findAccount();
void customerMenu2();
void miniStatement();
void withdraw_money_via_credit_card();
//*****************************************************************************************************************************************
ll llo;
long creditCard:: no = 0;
unsigned long int link::id = 1;
int main(){
char opt;
do{
cout << "1. Login as Bank Employee\n"
<< "2. Login as Bank Customer.\n"
<< "3. Exit.\n\t"; cin >> opt; system("cls"); cout << '\a';
if (opt == '1' || opt == '2'){
cout << "Password: "; long unsigned int password; cin >> password;
cout << "Welcome to FAST Banking System." << endl;
}
switch(opt){
case '1':
employeeMenu2();
break;
case '2':
customerMenu2();
break;
case '3':
exit(0);
default:
cout << "Wrong input." << endl;
cout << "Re_Enter" << endl << endl;
break;
}
system("cls");
}while (1);
return 0;
}
//*****************************************************************************************************************************************
void employeeMenu2(){
char opt;
do{
cout << "1.\t Create Accout." << endl
<< "2.\t Update Account." << endl
<< "3.\t Delete Account." << endl
<< "4.\t Find Account." << endl //Find account holders information using account number or CNIC number.
<< "5.\t Display All Accounts of particular type." << endl
<< "6.\t Deposit" << endl
<< "7.\t Withdraw." << endl
// << "8.\t Bonus." << endl;
<< "0.\t Log Out." << endl;
cin >> opt;
switch(opt){
case '1':
creatAccount();
break;
case '2':
llo.update();
break;
case '3':
llo.Delete();
break;
case '4':
findAccount();
break;
case '5':
llo.display_all_accounts_of_particular_type();
break;
case '6':
llo.deposit();
break;
case '0':
break;
default:
cout << "Wrong input." << endl;
cout << "Re_Enter" << endl << endl;
break;
}
}while (opt != '0');
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void creatAccount(){
llo.insertNode();
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void findAccount(){
llo.find();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void customerMenu2(){
char opt;
do{
cout << "1.\t See Mini Statement." << endl
<< "2.\t Withdraw money via Credit Card";
cin >> opt;
switch(opt){
case '1':
miniStatement();
break;
case '2':
withdraw_money_via_credit_card();
break;
case '3':
llo.DepositBalance();
break;
default:
cout << "Wrong input." << endl;
cout << "Re_Enter" << endl << endl;
break;
}
}while ((opt != '1') && (opt != '2'));
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void miniStatement(){
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
void withdraw_money_via_credit_card(){
llo.WithDraw();
}
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
//````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////[/code]
MRehanQadri 0 Junior Poster in Training
MRehanQadri 0 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.