0% found this document useful (0 votes)
5 views8 pages

Department of Polymer

The document outlines a C program that simulates a basic banking system, allowing users to create accounts, log in, and perform transactions like deposits and withdrawals. It includes features for account management, error handling, and user input validation, ensuring secure operations. The program is modular, making it organized and easy to maintain, while demonstrating fundamental programming concepts.

Uploaded by

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

Department of Polymer

The document outlines a C program that simulates a basic banking system, allowing users to create accounts, log in, and perform transactions like deposits and withdrawals. It includes features for account management, error handling, and user input validation, ensuring secure operations. The program is modular, making it organized and easy to maintain, while demonstrating fundamental programming concepts.

Uploaded by

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

OBJECT

Design a project that allows a user to do the following:


1) Create a bank account by supplying a user id and password.
2) Login using their id and password.
3) Quit the program.
Now if login was successful the user will be able to do the following:
1) Withdraw money.
2) Deposit money.
3) Request balance.
4) Quit the program.
If login was not successful (for example the id or password did not match) then the user will
be taken back to the introduction menu.

ANSWER
This program in C makes it possible for the complete operations of a general
banking system. Users create a new account, enter an existing one or end the
session using provided main menu. The account creation feature verifies user IDs
and protects them while storing their passwords with zero initial account balances.
When a user logs onto the system, he is presented with an account menu
containing options such as withdrawing money provided one’s balance is adequate,
depositing money, and checking one’s balance. The program allows several logins,
and after attempting to log in several times without success, the participant is sent
to the main menu. This session is notable since it illustrates the basic features of
banking services in C as well – error handling and program structure.

IMPLIMENTATION OF CODE

#include <stdio.h>
#include <string.h>

// Define maximum username and password lengths


#define MAX_USERNAME_LENGTH 20
#define MAX_PASSWORD_LENGTH 20

// Structure to represent user account


typedef struct {
char username[MAX_USERNAME_LENGTH];
char password[MAX_PASSWORD_LENGTH];
double balance;
} Account;

// Function prototypes
void createAccount(Account *accounts, int *numAccounts);
void login(Account *accounts, int numAccounts);
void deposit(Account *account);
void withdraw(Account *account);
void requestBalance(Account *account);

int main() {
Account accounts[100]; // Maximum 100 accounts
int numAccounts = 0;
int choice;

while (1) {
printf("Mr. Abc ATM Machine!\n");
printf("1. Login\n");
printf("2. Create New Account\n");
printf("3. Quit\n");
printf("Enter choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
login(accounts, numAccounts);
break;
case 2:
createAccount(accounts, &numAccounts);
break;
case 3:
printf("Thanks for stopping by!\n");
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}

return 0;
}

void createAccount(Account *accounts, int *numAccounts) {


printf("Enter username: ");
scanf("%s", accounts[*numAccounts].username);
printf("Enter password: ");
scanf("%s", accounts[*numAccounts].password);
accounts[*numAccounts].balance = 0.0;
(*numAccounts)++;
printf("Account created successfully!\n");
}

void login(Account *accounts, int numAccounts) {


char username[MAX_USERNAME_LENGTH];
char password[MAX_PASSWORD_LENGTH];
int i;

printf("Enter username: ");


scanf("%s", username);
printf("Enter password: ");
scanf("%s", password);

for (i = 0; i < numAccounts; i++) {


if (strcmp(accounts[i].username, username) == 0 && strcmp(accounts[i].password,
password) == 0) {
printf("Access granted!\n");
int choice;
while (1) {
printf("1. Deposit Money\n");
printf("2. Withdraw Money\n");
printf("3. Request Balance\n");
printf("4. Quit\n");
printf("Enter choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
deposit(&accounts[i]);
break;
case 2:
withdraw(&accounts[i]);
break;
case 3:
requestBalance(&accounts[i]);
break;
case 4:
return;
default:
printf("Invalid choice. Please try again.\n");
}
}
}
}

printf("Login failed!\n");
}

void deposit(Account *account) {


double amount;
printf("Enter deposit amount: $");
scanf("%lf", &amount);
account->balance += amount;
printf("Deposit successful. New balance: $%.2f\n", account->balance);
}

void withdraw(Account *account) {


double amount;
printf("Enter withdrawal amount: $");
scanf("%lf", &amount);

if (amount > account->balance) {


printf("Insufficient funds!\n");
} else {
account->balance -= amount;
printf("Withdrawal successful. New balance: $%.2f\n", account->balance);
}
}

void requestBalance(Account *account) {


printf("Your balance is: $%.2f\n", account->balance);
}
Explanation of Code
The current C program developed is an example of a simple but effective banking
application that can enable the users to create and manage his or her bank accounts
through a simple menu interface. At the beginning of the program, the program sets
a limit to non-transferrable bank accounts to be a total of one hundred and creates a
structure (Account) that consists of details like member ids, account passwords and
current account balance. It offers three service options for the user: creating an
account, logging in, and quitting the application. In the case that the user selects the
option for account creation, the user will be informed that they can submit their
account ID and password; additionally, in this case, the user’s balance will be set to
zero on the system. On the other hand, log in user is matched against the account
information saved on the system. After the login, the user is presented with an
account menu where he or she can withdraw money (based on enough balance),
deposit money (if the user enters a correct amount), check the balance, or log out.
Any invalid logins or actions taken will cause the user to be directed back to the
main menu for other options. Quite a bit of input control has also been incorporated
into the system, eg no two members can register with the same member I.D., no
negative deposits or overdrawn balances when withdrawing. The use of modular
functions such as create_account, login, withdraw_money, deposit_money and
request_balance has made the code clean, has created clear lines in which each
function operates and will be easy to use and maintain. This banking system is a
simple banking applications that illustrate the principles of user management and
transactions handling using C.

Conclusion
To sum up, this C program presents a simple and basic but working C program that
illustrates basic concepts in programming such as structures, login, and menus.
Considering account opening and login securely, the performing of primary
banking transactions such as deposit, withdrawal, and balance inquiries, this
program is able to emulate the functions of a bank. Because the program is
designed in a modular fashion, it is organized, easy to maintain, and easy to use.
This is a good case to illustrate how C can be used to develop software in practice.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy