Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

PROJECT 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.

Withdrawing Money: The user can withdraw money from


an existing account by specifying the account number and
the amount to be withdrawn. The system verifies the ac-
count's existence and checks if the account balance is suffi-
cient for the withdrawal. If the conditions are met, the bal-
ance is updated accordingly.

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.

Showing Account Information: The user can view the ac-


count information by entering the account number and the
account's associated password. The system searches for the
account and verifies the password. If the account and pass-
word are correct, the account details are displayed on the
screen.

Printing Accounts: The system provides an option to print


all existing accounts. It iterates through the account list and
displays the account information for each account.

www.mitwpu.edu.in
Data Structure

The main data structure used in this system is the "account"


structure, which stores information related to an individual
bank account. The structure includes the following fields:

• name: Stores the name of the account holder.


• address: Stores the address of the account holder.
• phone: Stores the phone number of the account holder.
• password: Stores the password associated with the ac-
count.
• account_number: Stores the unique account number.
• balance: Stores the account balance.

The system maintains an array of account structures named


"accounts," which has a maximum capacity of 100 accounts.
The variable num_accounts keeps track of the current num-
ber of accounts stored in the array.

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.

User Input Validation


The system includes input validation for various scenarios.
For example, when creating an account, it checks if the ac-
count number is already taken. If so, the user is prompted to
enter a different account number. Additionally, the system
verifies that the password contains at least one letter and one
number. If the password doesn't meet this requirement, the
user is prompted to enter a valid password.

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>

#define MAX_ACCOUNTS 100


#define MAX_NAME_LENGTH 20
#define MAX_ADDRESS_LENGTH 100
#define MAX_PHONE_LENGTH 10
#define MAX_PASSWORD_LENGTH 10
#define MAX_ACCOUNT_NUMBER_LENGTH 10
#define MAX_BALANCE_LENGTH 10
#define MAX_TRANSACTION_LENGTH 10
#define MAX_TRANSACTIONS 100

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

// Write the account data to the file


fprintf(file, "Name: %s\n", acc.name);
fprintf(file, "Address: %s\n", acc.address);
fprintf(file, "Phone number: %s\n", acc.phone);
fprintf(file, "Password: %s\n", acc.password);
fprintf(file, "Account number: %s\n", acc.account_number);
fprintf(file, "Balance: %s\n", acc.balance);
fprintf(file, "\n");

fclose(file); // Close the file


}
bool has_letter_and_number(char *password)
{
for (int i = 0; i < strlen(password); i++)
{
if (isalpha(password[i])) {
alpha++;
}
if (isdigit(password[i])) {
numeric++;
}
}
return alpha > 0 && numeric > 0;
}

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

printf("Enter balance: ");


scanf("%s", accounts[num_accounts].balance);

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

5.Show Account Information

6.Print Accounts

www.mitwpu.edu.in
4.Account Details Stored in a Text File

www.mitwpu.edu.in
Conclusion

In conclusion, this project focused on the development of a ba-


sic banking system using C programming language.The imple-
mented code offers various functionalities such as creating ac-
counts, deleting accounts, performing withdrawals, making de-
posits, and displaying account information.

Throughout the project, we leveraged data structures, such as


‘account’ structure to store and manage account information ef-
ficiently.The code utilised file handling to persist account data
in a text file, allowing for data persistence between program
executions.

Additionally, the program incorporated password validation lo-


gic, ensuring that passwords contain at least one letter and one
number, thereby enhancing the security of user accounts

Overall this project provided valuable insights into C pro-


gramming and file handling, showcasing how basic banking
operations can be implemented

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

You might also like