Last active
December 9, 2019 22:59
-
-
Save Gabutoo/22efbf9848b8e55b3734137d17725953 to your computer and use it in GitHub Desktop.
Banking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdbool.h> | |
struct client { | |
int id; | |
int cardNumber; | |
char *name; | |
int pin; | |
double money; | |
}; | |
struct node { | |
struct client *data; | |
struct node *next; | |
}; | |
struct linked_list { | |
struct node *head; | |
struct node *tail; | |
}; | |
//Declared user values | |
float userMoney = 0; | |
int userPass = 111111; | |
int userCard = 111111; | |
//Declared admin values | |
int adminNumber = 123456; | |
int adminPass = 123456; | |
//User inputs | |
int passInput; | |
int cardInput; | |
float moneyInput; | |
int choiceInput; | |
struct client *new_client(int id, int cardNumber, char *name, int pin, double money) { | |
struct client *cl = (struct client *) malloc(sizeof(struct client)); | |
//c = realloc(c, sizeof(struct client*)); | |
cl->id = id; | |
cl->cardNumber = cardNumber; | |
cl->name = strdup(name); | |
cl->pin = pin; | |
cl->money = money; | |
return cl; | |
} | |
struct node *new_node(struct client *data) { | |
struct node *n = malloc(sizeof(struct node *)); | |
//n = realloc(n, sizeof(struct node*)); | |
n->data = data; | |
n->next = NULL; | |
return n; | |
} | |
struct linked_list *new_list() { | |
struct linked_list *l = malloc(sizeof(struct linked_list *)); | |
//l = realloc(l, sizeof(struct linked_list*)); | |
l->head = NULL; | |
l->tail = NULL; | |
return l; | |
} | |
void list_add(struct linked_list *list, struct node *n) { | |
if (list->head == NULL) { | |
list->head = n; | |
} else { | |
list->tail->next = n; | |
} | |
list->tail = n; | |
} | |
void list_print(struct linked_list *list) { | |
printf("\nWelcome to Letran Bank\n\n"); | |
printf("VIEW RECORDS\n"); | |
printf("%3s %11s %25s %20s\n", "ID", "CARD NUMBER", "NAME", "BALANCE"); | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
printf("%3d %11d %25s %20f\n", n->data->id, n->data->cardNumber, n->data->name, n->data->money); | |
} | |
} | |
void change_pin(struct linked_list *list, int cardnumber) { | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (n->data->cardNumber == cardnumber) { | |
printf("\nWelcome to Letran Bank\n\n"); | |
printf("CHANGE PIN\n"); | |
printf("Enter current pin: "); | |
scanf("%d", &passInput); | |
if (n->data->pin == passInput) { | |
printf("Enter new pin: "); | |
scanf("%d", &passInput); | |
n->data->pin = passInput; | |
} else { | |
printf("Wrong pin."); | |
} | |
} | |
} | |
} | |
void deposit_money(struct linked_list *list, int cardnumber) { | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (n->data->cardNumber == cardnumber) { | |
printf("\nWelcome to Letran Bank\n\n"); | |
printf("DEPOSIT MONEY\n"); | |
printf("Enter amount to be deposited: "); | |
scanf("%f", &moneyInput); | |
n->data->money += moneyInput; | |
printf("Current Balance is: %f", n->data->money); | |
} | |
} | |
} | |
void withdraw_money(struct linked_list *list, int cardnumber) { | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (n->data->cardNumber == cardnumber) { | |
printf("\nWelcome to Letran Bank\n\n"); | |
printf("WITHDRAW MONEY\n"); | |
printf("Enter amount to be withdrawn: "); | |
scanf("%f", &moneyInput); | |
if (moneyInput <= n->data->money) { | |
n->data->money -= moneyInput; | |
printf("Withdrawal success.\n"); | |
} else { | |
printf("Insufficient Balance.\n"); | |
} | |
printf("Current Balance is: %f", n->data->money); | |
} | |
} | |
} | |
void check_balance(struct linked_list *list, int cardnumber) { | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (n->data->cardNumber == cardnumber) { | |
printf("\nWelcome to Letran Bank\n\n"); | |
printf("CHECK BALANCE\n"); | |
printf("Your Current Savings Balance is Php %f \n\n", n->data->money); | |
} | |
} | |
} | |
void searchRecords(struct linked_list *list) { | |
printf("\nWelcome to Letran Bank\n\n"); | |
printf("VIEW RECORDS\n"); | |
int input; | |
printf("Search card number: "); | |
scanf("%d", &input); | |
printf("%3s %11s %25s %20s\n", "ID", "CARD NUMBER", "NAME", "BALANCE"); | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (n->data->cardNumber == input) { | |
printf("%3d %11d %25s %20f\n", n->data->id, n->data->cardNumber, n->data->name, n->data->money); | |
} | |
} | |
} | |
int authentication(struct linked_list *list, int cardnumber, int pin) { | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (cardnumber == 123456) { | |
if (pin == 123456) { | |
return 1; | |
} else { | |
return 3; | |
} | |
} else if (n->data->cardNumber == cardnumber) { | |
if (n->data->pin == pin) { | |
return 2; | |
} else { | |
return 3; | |
} | |
} | |
} | |
} | |
int main() { | |
int currentCard; | |
//creates new list | |
struct linked_list *list = new_list(); | |
//creates new values to be added to nodes; //ID,CARD NUMBER | NAME | PIN | BALANCE | |
struct client *c1 = new_client(1, 123456, "Admin", 123456, 999999); | |
struct client *c2 = new_client(2, 111111, "Gabutooo", 246810, 1000); | |
struct client *c3 = new_client(3, 666666, "Gabs", 111111, 500); | |
//creates new nodes and add the values | |
struct node *n1 = new_node(c1); | |
struct node *n2 = new_node(c2); | |
struct node *n3 = new_node(c3); | |
//add each nodes to the list | |
list_add(list, n1); | |
list_add(list, n2); | |
list_add(list, n3); | |
while (choiceInput != 6) { | |
printf("Welcome to LETRAN BANK\n\n"); | |
printf("Enter Card Number: "); | |
scanf("%d", &cardInput); | |
currentCard = cardInput; | |
printf("Enter pin: "); | |
scanf("%d", &passInput); | |
if (authentication(list, cardInput, passInput) == 1) { | |
while (choiceInput != 5) { | |
printf("\nWelcome to Letran Bank, Admin!\n\n"); | |
printf("[1] View all records\n"); | |
printf("[2] Delete records\n"); | |
printf("[3] Modify records\n"); | |
printf("[4] Search records\n"); | |
printf("[5] Logout\n"); | |
printf("[6] Terminate\n"); | |
printf("Enter choice: "); | |
scanf("%d", &choiceInput); | |
switch (choiceInput) { | |
case 1: | |
list_print(list); | |
break; | |
case 2: | |
//delete_records(list); | |
break; | |
case 3: | |
//modify_records(list); | |
break; | |
case 4: | |
searchRecords(list); | |
break; | |
case 5: | |
break; | |
case 6: | |
printf("Thank You!"); | |
break; | |
default: | |
printf("Invalid input.\n"); | |
break; | |
} | |
} | |
} else if (authentication(list, cardInput, passInput) == 2) { | |
while (choiceInput != 5) { | |
printf("\nWelcome to GBS Bank\n\n"); | |
printf("[1] Check Balance\n"); | |
printf("[2] Withdraw\n"); | |
printf("[3] Deposit\n"); | |
printf("[4] Change Pin\n"); | |
printf("[5] Logout\n"); | |
printf("[6] Terminate\n"); | |
printf("Enter choice: "); | |
scanf("%d", &choiceInput); | |
switch (choiceInput) { | |
case 1: | |
check_balance(list, currentCard); | |
break; | |
case 2: | |
withdraw_money(list, currentCard); | |
break; | |
case 3: | |
deposit_money(list, currentCard); | |
break; | |
case 4: | |
change_pin(list, currentCard); | |
break; | |
case 5: | |
break; | |
case 6: | |
printf("Thank You!"); | |
break; | |
default: | |
printf("Invalid input.\n"); | |
break; | |
} | |
} | |
} else if (authentication(list, cardInput, passInput)) { | |
printf("Wrong Pin.\n"); | |
} else { | |
printf("User doesn't exist.\n"); | |
} | |
} | |
return 0; | |
} | |
///ADMIN/// | |
void delete_records() { | |
printf("\nWelcome to GBS Bank\n\n"); | |
printf("VIEW RECORDS\n"); | |
} | |
void modify_records() { | |
printf("\nWelcome to GBS Bank\n\n"); | |
printf("VIEW RECORDS\n"); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdbool.h> | |
struct client { | |
int id; | |
int cardNumber; | |
char *name; | |
int pin; | |
double money; | |
}; | |
struct node { | |
struct client *data; | |
struct node *next; | |
}; | |
struct linked_list { | |
struct node *head; | |
struct node *tail; | |
}; | |
//Declared user values | |
float userMoney = 0; | |
int userPass = 111111; | |
int userCard = 111111; | |
//Declared admin values | |
int adminNumber = 123456; | |
int adminPass = 123456; | |
//User inputs | |
int passInput; | |
int cardInput; | |
float moneyInput; | |
int choiceInput; | |
struct client *new_client(int id, int cardNumber, char *name, int pin, double money) { | |
struct client *cl = (struct client *) malloc(sizeof(struct client)); | |
//c = realloc(c, sizeof(struct client*)); | |
cl->id = id; | |
cl->cardNumber = cardNumber; | |
cl->name = strdup(name); | |
cl->pin = pin; | |
cl->money = money; | |
return cl; | |
} | |
struct node *new_node(struct client *data) { | |
struct node *n = malloc(sizeof(struct node *)); | |
//n = realloc(n, sizeof(struct node*)); | |
n->data = data; | |
n->next = NULL; | |
return n; | |
} | |
struct linked_list *new_list() { | |
struct linked_list *l = malloc(sizeof(struct linked_list *)); | |
//l = realloc(l, sizeof(struct linked_list*)); | |
l->head = NULL; | |
l->tail = NULL; | |
return l; | |
} | |
void list_add(struct linked_list *list, struct node *n) { | |
if (list->head == NULL) { | |
list->head = n; | |
} else { | |
list->tail->next = n; | |
} | |
list->tail = n; | |
} | |
void list_print(struct linked_list *list) { | |
printf("\nWelcome to GBS Bank\n\n"); | |
printf("VIEW RECORDS\n"); | |
printf("%3s %11s %25s %20s\n", "ID", "CARD NUMBER", "NAME", "BALANCE"); | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
printf("%3d %11d %25s %20f\n", n->data->id, n->data->cardNumber, n->data->name, n->data->money); | |
} | |
} | |
void change_pin(struct linked_list *list, int cardnumber) { | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (n->data->cardNumber == cardnumber) { | |
printf("\nWelcome to GBS Bank\n\n"); | |
printf("CHANGE PIN\n"); | |
printf("Enter current pin: "); | |
scanf("%d", &passInput); | |
if (n->data->pin == passInput) { | |
printf("Enter new pin: "); | |
scanf("%d", &passInput); | |
n->data->pin = passInput; | |
} else { | |
printf("Wrong pin."); | |
} | |
} | |
} | |
} | |
void deposit_money(struct linked_list *list, int cardnumber) { | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (n->data->cardNumber == cardnumber) { | |
printf("\nWelcome to GBS Bank\n\n"); | |
printf("DEPOSIT MONEY\n"); | |
printf("Enter amount to be deposited: "); | |
scanf("%f", &moneyInput); | |
n->data->money += moneyInput; | |
printf("Current Balance is: %f", n->data->money); | |
} | |
} | |
} | |
void withdraw_money(struct linked_list *list, int cardnumber) { | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (n->data->cardNumber == cardnumber) { | |
printf("\nWelcome to GBS Bank\n\n"); | |
printf("WITHDRAW MONEY\n"); | |
printf("Enter amount to be withdrawn: "); | |
scanf("%f", &moneyInput); | |
if (moneyInput <= n->data->money) { | |
n->data->money -= moneyInput; | |
printf("Withdrawal success.\n"); | |
} else { | |
printf("Insufficient Balance.\n"); | |
} | |
printf("Current Balance is: %f", n->data->money); | |
} | |
} | |
} | |
void check_balance(struct linked_list *list, int cardnumber) { | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (n->data->cardNumber == cardnumber) { | |
printf("\nWelcome to GBS Bank\n\n"); | |
printf("CHECK BALANCE\n"); | |
printf("Your Current Savings Balance is Php %f \n\n", n->data->money); | |
} | |
} | |
} | |
void searchRecords(struct linked_list *list) { | |
printf("\nWelcome to GBS Bank\n\n"); | |
printf("VIEW RECORDS\n"); | |
int input; | |
printf("Search card number: "); | |
scanf("%d", &input); | |
printf("%3s %11s %25s %20s\n", "ID", "CARD NUMBER", "NAME", "BALANCE"); | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (n->data->cardNumber == input) { | |
printf("%3d %11d %25s %20f\n", n->data->id, n->data->cardNumber, n->data->name, n->data->money); | |
} | |
} | |
} | |
int authentication(struct linked_list *list, int cardnumber, int pin) { | |
for (struct node *n = list->head; n != NULL; n = n->next) { | |
if (cardnumber == 123456) { | |
if (pin == 123456) { | |
return 1; | |
} else { | |
return 3; | |
} | |
} else if (n->data->cardNumber == cardnumber) { | |
if (n->data->pin == pin) { | |
return 2; | |
} else { | |
return 3; | |
} | |
} | |
} | |
} | |
int main() { | |
// USE AN IDE WITH C++ version 11; | |
int currentCard; | |
//To create new list | |
struct linked_list *list = new_list(); | |
// To create new values to be added to nodes; //ID,CARD NUMBER | NAME | PIN | BALANCE | |
struct client *c1 = new_client(1, 123456, "Admin", 123456, 50000); | |
struct client *c2 = new_client(2, 111111, "Gabutooo", 111111, 1000); | |
struct client *c3 = new_client(3, 666666, "Gabs", 666666, 500); | |
// To create new nodes and add the values | |
struct node *n1 = new_node(c1); | |
struct node *n2 = new_node(c2); | |
struct node *n3 = new_node(c3); | |
//To add each node inside the List | |
list_add(list, n1); | |
list_add(list, n2); | |
list_add(list, n3); | |
while (choiceInput != 6) { | |
printf("Welcome to GBS BANK\n\n"); | |
printf("Enter Card Number: "); | |
scanf("%d", &cardInput); | |
currentCard = cardInput; | |
printf("Enter pin: "); | |
scanf("%d", &passInput); | |
if (authentication(list, cardInput, passInput) == 1) { | |
while (choiceInput != 5) { | |
printf("\nWelcome to GBS Bank, Admin!\n\n"); | |
printf("[1] View all records\n"); | |
printf("[2] Delete records\n"); | |
printf("[3] Modify records\n"); | |
printf("[4] Search records\n"); | |
printf("[5] Logout\n"); | |
printf("[6] Terminate\n"); | |
printf("Enter choice: "); | |
scanf("%d", &choiceInput); | |
switch (choiceInput) { | |
case 1: | |
list_print(list); | |
break; | |
case 2: | |
//delete_records(list); | |
break; | |
case 3: | |
//modify_records(list); | |
break; | |
case 4: | |
searchRecords(list); | |
break; | |
case 5: | |
break; | |
case 6: | |
printf("Thank You!"); | |
break; | |
default: | |
printf("Invalid input.\n"); | |
break; | |
} | |
} | |
} else if (authentication(list, cardInput, passInput) == 2) { | |
while (choiceInput != 5) { | |
printf("\n******Welcome to GBS Bank******\n\n"); | |
printf("[1] Check Balance\n"); | |
printf("[2] Withdraw\n"); | |
printf("[3] Deposit\n"); | |
printf("[4] Change Pin\n"); | |
printf("[5] Logout\n"); | |
printf("[6] Terminate\n"); | |
printf("Enter choice: "); | |
scanf("%d", &choiceInput); | |
switch (choiceInput) { | |
case 1: | |
check_balance(list, currentCard); | |
break; | |
case 2: | |
withdraw_money(list, currentCard); | |
break; | |
case 3: | |
deposit_money(list, currentCard); | |
break; | |
case 4: | |
change_pin(list, currentCard); | |
break; | |
case 5: | |
break; | |
case 6: | |
printf("Thank You!"); | |
break; | |
default: | |
printf("Invalid input.\n"); | |
break; | |
} | |
} | |
} else if (authentication(list, cardInput, passInput)) { | |
printf("Wrong Pin.\n"); | |
} else { | |
printf("User doesn't exist.\n"); | |
} | |
} | |
return 0; | |
} | |
///ADMIN/// | |
void delete_records() { | |
printf("\n******Welcome to GBS Bank******\n\n"); | |
printf("DELETE RECORDS\n"); | |
} | |
void modify_records() { | |
printf("\n******Welcome to GBS Bank******\n\n"); | |
printf("VIEW RECORDS\n"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment