0% found this document useful (0 votes)
14 views3 pages

2 ND

Vvv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

2 ND

Vvv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <iostream.

h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>

struct Transaction {
char type[10];
float amount;
Transaction *next;
};

struct Customer {
int id;
char name[50];
float balance;
Customer *next;
Transaction *transactions; // Pointer to store transaction history
};

Customer *head = NULL; // Head of the linked list for customers

void addCustomer(int id, const char *name, float balance) {


Customer *newCustomer = new Customer;
newCustomer->id = id;
strcpy(newCustomer->name, name);
newCustomer->balance = balance;
newCustomer->next = head;
newCustomer->transactions = NULL; // Initialize transaction list
head = newCustomer;
}

void displayCustomers() {
Customer *temp = head;
while (temp != NULL) {
cout << "ID: " << temp->id << ", Name: " << temp->name << ", Balance: " <<
temp->balance << endl;
temp = temp->next;
}
}

void pushTransaction(Customer *customer, const char *type, float amount) {


Transaction *newTransaction = new Transaction;
strcpy(newTransaction->type, type);
newTransaction->amount = amount;
newTransaction->next = customer->transactions;
customer->transactions = newTransaction;
}

void deposit(int id, float amount) {


Customer *temp = head;
while (temp != NULL) {
if (temp->id == id) {
temp->balance += amount;
pushTransaction(temp, "Deposit", amount);
cout << "Deposited: " << amount << ", New Balance: " << temp->balance
<< endl;
return;
}
temp = temp->next;
}
cout << "Customer not found!" << endl;
}

void withdraw(int id, float amount) {


Customer *temp = head;
while (temp != NULL) {
if (temp->id == id) {
if (temp->balance >= amount) {
temp->balance -= amount;
pushTransaction(temp, "Withdraw", amount);
cout << "Withdrew: " << amount << ", New Balance: " << temp-
>balance << endl;
} else {
cout << "Insufficient balance!" << endl;
}
return;
}
temp = temp->next;
}
cout << "Customer not found!" << endl;
}

void viewTransactionHistory(int id) {


Customer *temp = head;
while (temp != NULL) {
if (temp->id == id) {
Transaction *trans = temp->transactions;
while (trans != NULL) {
cout << "ID: " << temp->id << " Name: " << temp->name << " " <<
trans->type << ": " << trans->amount << endl;
trans = trans->next;
}
return;
}
temp = temp->next;
}
cout << "Customer not found!" << endl;
}

float calculateCompoundInterest(float principal, float rate, int time) {


if (time == 0)
return principal;
return calculateCompoundInterest(principal * (1 + rate / 100), rate, time - 1);
}

void main() {
clrscr();
int choice, id, time;
char name[50];
float amount, principal, rate;

do {
cout << "\nBank Management System Menu:\n";
cout << "1. Add New Customer\n";
cout << "2. Display Customers\n";
cout << "3. Deposit Money\n";
cout << "4. Withdraw Money\n";
cout << "5. View Transaction History\n";
cout << "6. Calculate Compound Interest\n";
cout << "0. Exit\n";
cout << "Enter your choice: ";
cin >> choice;

switch (choice) {
case 1:
cout << "Enter ID, Name, Initial Balance: ";
cin >> id >> name >> amount;
addCustomer(id, name, amount);
break;
case 2:
displayCustomers();
break;
case 3:
cout << "Enter Customer ID and Amount to Deposit: ";
cin >> id >> amount;
deposit(id, amount);
break;
case 4:
cout << "Enter Customer ID and Amount to Withdraw: ";
cin >> id >> amount;
withdraw(id, amount);
break;
case 5:
cout << "Enter Customer ID to view transaction history: ";
cin >> id;
viewTransactionHistory(id);
break;
case 6:
cout << "Enter Principal, Rate of Interest, Time: ";
cin >> principal >> rate >> time;
float totalAmount = calculateCompoundInterest(principal, rate,
time);
cout << "Total Amount after interest: " << totalAmount << endl;
break;
case 0:
exit(0);
default:
cout << "Invalid choice! Please try again.\n";
}
} while (choice != 0);

getch();
}

You might also like