Professional Documents
Culture Documents
DSA Miniproject Report
DSA Miniproject Report
BANK MANAGEMENT
SYSTEM USING C
GROUP MEMBERS:
Akshat Jain: 37
Abhishek Kadam: 38
Sahil Jain: 39
Siddharth Bhagwat: 40
Satvik Tajne: 44
Aman Niranjan: 46
www.mitwpu.edu.in
Introduction
The C Bank Management System is a console-based applic-
ation that provides basic banking functionalities such as cre-
ating an account, deleting an account, withdrawing money,
depositing money, displaying account information, and
printing all accounts. The system allows users to perform
these operations by interacting with a menu-driven interface.
www.mitwpu.edu.in
FUNCTIONALITY
Creating an Account
The user can create a new bank account by providing in-
formation such as name, address, phone number, password,
account number, and initial balance. The system checks if
the account number is already taken and ensures that the
password contains at least one letter and one number. The
account details are then saved to a file named “accounts.txt."
Deleting an Account
The user can delete an existing account by entering the ac-
count number. The system searches for the account in the
list of accounts and removes it from the system. If the ac-
count is not found, an appropriate message is displayed.
www.mitwpu.edu.in
Depositing Money: The user can deposit money into an ex-
isting account by entering the account number and the
amount to be deposited. The system validates the account
and updates the account balance accordingly.
www.mitwpu.edu.in
Data Structure
www.mitwpu.edu.in
File Handling
The system utilises file handling to store the account details
in a file named "accounts.txt." The function save_account is
responsible for opening the file in append mode and writing
the account information in a formatted manner. Each ac-
count's details are written as separate lines in the file.
Menu-Driven Interface
The system presents a menu-driven interface that allows
users to select from a range of options. The user is prompted
to enter the corresponding option number to perform a spe-
cific operation. Invalid choices are handled with appropriate
error messages.
www.mitwpu.edu.in
CODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
typedef struct {
char name[MAX_NAME_LENGTH];
char address[MAX_ADDRESS_LENGTH];
char phone[MAX_PHONE_LENGTH];
char password[MAX_PASSWORD_LENGTH];
char account_number[MAX_ACCOUNT_NUMBER_LENGTH];
char balance[MAX_BALANCE_LENGTH];
} account;
account accounts[MAX_ACCOUNTS];
www.mitwpu.edu.in
int num_accounts = 0;
int alpha=0;
int numeric=0;
void save_account(account acc)
{
FILE *file = fopen("accounts.txt", "a"); // Open the file in append
mode
if (file == NULL) {
printf("Error opening file.\n");
return;
}
www.mitwpu.edu.in
bool is_account_number_taken(char *account_number) {
for (int i = 0; i < num_accounts; i++) {
if (strcmp(accounts[i].account_number, account_number) == 0) {
return true;
}
}
return false;
}
void create_account() {
if (num_accounts == MAX_ACCOUNTS) {
printf("Cannot create more accounts.\n");
return;
}
printf("Enter name: ");
scanf("%s", accounts[num_accounts].name);
printf("Enter address: ");
scanf("%s", accounts[num_accounts].address);
printf("Enter phone number: ");
scanf("%s", accounts[num_accounts].phone);
printf("Enter password: ");
scanf("%s", accounts[num_accounts].password);
while (true) {
printf("Enter account number: ");
scanf("%s", accounts[num_accounts].account_number);
if (is_account_number_taken(accounts[num_accounts].accoun-
t_number)) {
printf("Account number already taken. Please enter a different
account number.\n");
} else {
break;
}
}
www.mitwpu.edu.in
save_account(accounts[num_accounts]);
num_accounts++;
}
void delete_account() {
printf("Enter account number: ");
char account_number[MAX_ACCOUNT_NUMBER_LENGTH];
scanf("%s", account_number);
int i;
for (i = 0; i < num_accounts; i++) {
if (strcmp(accounts[i].account_number, account_number) == 0) {
break;
}
}
if (i == num_accounts) {
printf("Account not found.\n");
return;
}
for (int j = i; j < num_accounts - 1; j++) {
accounts[j] = accounts[j + 1];
}
num_accounts--;
}
void withdraw() {
printf("Enter account number: ");
char account_number[MAX_ACCOUNT_NUMBER_LENGTH];
scanf("%s", account_number);
int i;
for (i = 0; i < num_accounts; i++) {
if (strcmp(accounts[i].account_number, account_number) == 0) {
break;
}
}
if (i == num_accounts) {
www.mitwpu.edu.in
printf("Account not found.\n");
return;
}
printf("Enter amount: ");
char amount[MAX_BALANCE_LENGTH];
scanf("%s", amount);
int balance = atoi(accounts[i].balance);
int amount_int = atoi(amount);
if (amount_int > balance) {
printf("Insufficient balance.\n");
return;
}
balance -= amount_int;
sprintf(accounts[i].balance, "%d", balance);
printf("Withdrawal successful.\n");
}
void deposit() {
printf("Enter account number: ");
char account_number[MAX_ACCOUNT_NUMBER_LENGTH];
scanf("%s", account_number);
int i;
for (i = 0; i < num_accounts; i++) {
if (strcmp(accounts[i].account_number, account_number) == 0) {
break;
}
}
if (i == num_accounts) {
printf("Account not found.\n");
return;
}
printf("Enter amount: ");
char amount[MAX_BALANCE_LENGTH];
scanf("%s", amount);
int balance = atoi(accounts[i].balance);
int amount_int = atoi(amount);
www.mitwpu.edu.in
balance += amount_int;
sprintf(accounts[i].balance, "%d", balance);
printf("Deposit successful.\n");
}
void show_account_info() {
printf("Enter account number: ");
char account_number[MAX_ACCOUNT_NUMBER_LENGTH];
scanf("%s", account_number);
printf("Enter password: ");
char password[MAX_PASSWORD_LENGTH];
scanf("%s", password);
int i;
for (i = 0; i < num_accounts; i++) {
if (strcmp(accounts[i].account_number, account_number) == 0 &&
strcmp(accounts[i].password, password) == 0) {
break;
}
}
if (i == num_accounts) {
printf("Account not found or password incorrect.\n");
return;
}
printf("Account information:\n");
printf("Name: %s\n", accounts[i].name);
printf("Address: %s\n", accounts[i].address);
printf("Phone number: %s\n", accounts[i].phone);
printf("Account number: %s\n", accounts[i].account_number);
printf("Balance: %s\n", accounts[i].balance);
printf("\n");
}
void print_accounts() {
www.mitwpu.edu.in
for (int i = 0; i < num_accounts; i++) {
printf("Name: %s\n", accounts[i].name);
printf("Address: %s\n", accounts[i].address);
printf("Phone number: %s\n", accounts[i].phone);
printf("Password: %s\n", accounts[i].password);
printf("Account number: %s\n", accounts[i].account_number);
printf("Balance: %s\n", accounts[i].balance);
printf("\n");
}
}
int main() {
while (true) {
printf("------------------------\n");
printf ("Welcome to the Bank\n");
printf("------------------------\n");
printf("\n");
printf("1. Create account\n");
printf("2. Delete account\n");
printf("3. Withdraw\n");
printf("4. Deposit\n");
printf("5. Show account information\n");
printf("6. Print accounts\n");
printf("7. Exit\n");
printf("Enter choice: ");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
create_account();
break;
case 2:
delete_account();
break;
case 3:
withdraw();
www.mitwpu.edu.in
break;
case 4:
deposit();
break;
case 5:
show_account_info();
break;
case 6:
print_accounts();
break;
case 7:
return 0;
default:
printf("Invalid choice.\n");
}
}
}
www.mitwpu.edu.in
OUTPUT
1.Account Creation
2.Account Deletion
3.Withdrawal
www.mitwpu.edu.in
4.Deposit
6.Print Accounts
www.mitwpu.edu.in
4.Account Details Stored in a Text File
www.mitwpu.edu.in
Conclusion
www.mitwpu.edu.in
References
• https://www.geeksforgeeks.org/structures-c/
• https://www.geeksforgeeks.org/c-arrays/
• https://www.geeksforgeeks.org/isalpha-isdigit-func-
tions-c-example/
• https://www.geeksforgeeks.org/time-h-header-file-in-c-
with-examples/
www.mitwpu.edu.in