0% found this document useful (0 votes)
2 views9 pages

Department of Polymer

The document outlines a project for a banking system implemented in C, allowing users to create accounts, log in, and perform transactions like deposits and withdrawals. It includes code for account management, error handling, and a structured menu system. The program demonstrates fundamental programming concepts such as structures and modular design.

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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Department of Polymer

The document outlines a project for a banking system implemented in C, allowing users to create accounts, log in, and perform transactions like deposits and withdrawals. It includes code for account management, error handling, and a structured menu system. The program demonstrates fundamental programming concepts such as structures and modular design.

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 PDF, TXT or read online on Scribd
You are on page 1/ 9

Department of Polymer & Petrochemical Engineering

NED University of Engineering & Technology

TOPIC Name

Name: Saim Riaz

Seat No: PP-23005

Submitted To: Miss Nuzhat

Course Code & Course Title: Computer Programming and its

Applications(PP-211)
OPEN ENDED LAB (PP-211)

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

Qno:1 Create a bank account by supplying a user id and password.


Login using their id and password.
Quit the program.

Now if login was successful the user will be able to do the following:

Withdraw money.
Deposit money.
Request balance.
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 MAX_USERNAME_LENGTH 20
#define MAX_PASSWORD_LENGTH 20

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

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

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