Created
December 10, 2019 17:16
-
-
Save Gabutoo/e06fa386c88bb2e4a4f2e1044ce78c43 to your computer and use it in GitHub Desktop.
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> | |
//Multi Linked List | |
struct client { | |
//structure for users Information | |
int cardNumber; | |
char *name; | |
double money; | |
int id; | |
int pin; | |
}; | |
struct node { | |
struct client *data; | |
struct node *next; | |
}; | |
struct linkedList { | |
struct node *head; | |
struct node *tail; | |
// Understand & Apply Queue Concept!!! (Linked Queue.c) | |
}; | |
//Values for the user account | |
float userMoney = 0; | |
int userPass = 111111; | |
int userCard = 111111; | |
//Values for the admin account | |
int adminNumber = 123456; | |
int adminPass = 123456; | |
//User inputs | |
int passInput; | |
int cardInput; | |
float moneyInput; | |
int choiceInput; | |
/*structures order: | |
client | |
node(data,next) | |
linkedList | |
//Methods | |
*newClient() | |
*newNode() | |
*newList() | |
*ADD() | |
*PRINT() | |
*changePin() | |
*deposit() | |
*withdraw() | |
*checkBalance() | |
*search() | |
*authentication() | |
*/ | |
struct client *newClient(int id, int cardNumber, char *name, int pin, double money) | |
{ | |
struct client *cl = (struct client *) malloc(sizeof(struct client)); | |
cl->id = id; | |
cl->cardNumber = cardNumber; | |
cl->name = strdup(name); | |
cl->pin = pin; | |
cl->money = money; | |
return cl; | |
} | |
struct node *newNode(struct client *data) | |
{ | |
struct node *n = malloc(sizeof(struct node *)); | |
n->data = data; | |
n->next = NULL; | |
return n; | |
} | |
struct linkedList *newList() | |
{ | |
struct linkedList *ll = malloc(sizeof(struct linkedList *)); | |
//l = realloc(l, sizeof(struct linkedList*)); | |
ll->head = NULL; | |
ll->tail = NULL; | |
return ll; | |
} | |
void addList(struct linkedList *list, struct node *n) { | |
if (list->head == NULL) { | |
list->head = n; | |
} else { | |
list->tail->next = n; | |
} | |
list->tail = n; | |
} | |
void printList(struct linkedList *list) | |
{ | |
printf("\nWelcome to GBS Banking! Money Safe Guaranteed To You!\n\n"); | |
printf("VIEW RECORDS\n"); | |
printf("%3s %11s %25s %20s\n", "ID", "CARD NUMBER", "NAME", "BALANCE"); | |
struct node *n = list->head; | |
while( n != NULL) | |
{ | |
printf("%3d %11d %25s %20f\n", n->data->id, n->data->cardNumber, n->data->name, n->data->money); | |
n = n->next; | |
} | |
} | |
void changePin(struct linkedList *list, int cardnumber) | |
{ | |
struct node *n = list->head; | |
while(n != NULL ){ | |
if (n->data->cardNumber == cardnumber) | |
{ | |
printf("\nWelcome to GBS Banking! Money Safe Guaranteed To You!\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."); | |
} | |
}n = n->next; | |
} | |
} | |
void depositMoney(struct linkedList *list, int cardnumber) | |
{ | |
struct node *n = list->head; | |
while(n != NULL ) | |
{ | |
if (n->data->cardNumber == cardnumber) | |
{ | |
printf("\nWelcome to GBS Banking! Money Safe Guaranteed To You!\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); | |
}n = n->next; | |
} | |
} | |
void withdrawMoney(struct linkedList *list, int cardnumber) | |
{ | |
struct node *n = list->head; | |
while(n != NULL) | |
{ | |
if (n->data->cardNumber == cardnumber) | |
{ | |
printf("\nWelcome to GBS Banking! Money Safe Guaranteed To You!\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); | |
}n = n->next; | |
} | |
} | |
void checkBalance(struct linkedList *list, int cardnumber) | |
{ | |
struct node *n = list->head; | |
while (n != NULL) | |
{ | |
if (n->data->cardNumber == cardnumber) | |
{ | |
printf("\nWelcome to GBS Banking! Money Safe Guaranteed To You!\n\n"); | |
printf("CHECK BALANCE\n"); | |
printf("Your Current Savings Balance is Php %f \n\n", n->data->money); | |
}n = n->next; | |
} | |
} | |
void searchRecords(struct linkedList *list) { | |
printf("\nWelcome to GBS Banking! Money Safe Guaranteed To You!\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"); | |
struct node *n = list->head; | |
while(n != NULL) | |
{ | |
if (n->data->cardNumber == input) | |
{ | |
printf("%3d %11d %25s %20f\n", n->data->id, n->data->cardNumber, n->data->name, n->data->money); | |
}n = n->next; | |
} | |
} | |
int authentication(struct linkedList *list, int cardnumber, int pin) { | |
struct node *n = list->head; | |
while(n != NULL){ | |
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; | |
} | |
}n = n->next; | |
} | |
} | |
int main() { | |
// USE AN IDE WITH C++ version 11; | |
int currentCard; | |
//To create new list | |
struct linkedList *list = newList(); | |
// To create new values to be added to nodes; //ID,CARD NUMBER | NAME | PIN | BALANCE | |
struct client *c1 = newClient(1, 123456, "Admin", 123456, 50000); | |
struct client *c2 = newClient(2, 111111, "Gabutooo", 111111, 1000); | |
struct client *c3 = newClient(3, 666666, "Professor", 666666, 500000); | |
// To create new nodes and add the values | |
struct node *n1 = newNode(c1); | |
struct node *n2 = newNode(c2); | |
struct node *n3 = newNode(c3); | |
//To add each node inside the List | |
addList(list, n1); | |
addList(list, n2); | |
addList(list, n3); | |
while (choiceInput != 6) { | |
printf("Welcome to GBS Banking! Money Safe Guaranteed To You!\n\n"); | |
printf("Enter Your Card Number: "); | |
scanf("%d", &cardInput); | |
currentCard = cardInput; | |
printf("Enter Yout Pin: "); | |
scanf("%d", &passInput); | |
if (authentication(list, cardInput, passInput) == 1) { | |
while (choiceInput != 5) { | |
printf("\nWelcome to GBS Bank [Administrator]\n\n"); | |
printf("[1] View All\n"); | |
printf("[2] Delete \n"); | |
printf("[3] Modify \n"); | |
printf("[4] Search \n"); | |
printf("[5] Logout\n"); | |
printf("[6] Terminate\n"); | |
printf("Enter choice: "); | |
scanf("%d", &choiceInput); | |
switch (choiceInput) { | |
case 1: | |
printList(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 Banking [User]******\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: | |
checkBalance(list, currentCard); | |
break; | |
case 2: | |
withdrawMoney(list, currentCard); | |
break; | |
case 3: | |
depositMoney(list, currentCard); | |
break; | |
case 4: | |
changePin(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 entered!\n"); | |
} else { | |
printf("User does not exist within the list!\n"); | |
} | |
} | |
return 0; | |
} | |
///ADMIN/// | |
void delete_records() { | |
printf("\nWelcome to GBS Banking! Money Safe Guaranteed To You!\n\n"); | |
printf("DELETE RECORDS\n"); | |
} | |
void modify_records() { | |
printf("\nWelcome to GBS Banking! Money Safe Guaranteed To You!\n\n"); | |
printf("VIEW RECORDS\n"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment