Department of Polymer
Department of Polymer
TOPIC Name
Applications(PP-211)
OPEN ENDED LAB (PP-211)
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;
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");
}
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");
}
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.