Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<ctype.h>
- typedef struct dt{
- int aMoney;
- }WD;
- typedef struct at{
- char gender;
- char FName[10];
- char MI;
- char LName[10];
- }Pinfo;
- typedef struct bt{
- char pin[100];
- }Pcode;
- typedef struct ct{
- Pcode code;
- Pinfo info;
- WD withD;
- int idNum;
- }account;
- typedef struct nodeT{
- account d;
- struct nodeT *next;
- }NODE_T;
- void admin(account acc[],int count,NODE_T **LL);
- int signIn(account acc[],account container[],int count5);
- void createAcc(account acc[], int *count,int size);
- int main(void){
- FILE *fp,*fp2;
- fp=fopen("storage.txt","a");
- fp2=fopen("num.txt","r");
- NODE_T *LL;
- int size=5;
- account person[size],strg[size];
- int opt, count,i;
- fscanf(fp2,"%d",&count);
- printf("%d",count);
- printf("*****************************************************************\n");
- printf("\5\tT \5\n");
- printf("\5\t\tE \5\n");
- printf("\5\t\t\tC \5\n");
- printf("\5\t\t\t\tH \5\n");
- printf("\5\t\t\t\t\tS \5\n");
- printf("\5\t\t\t\t\t\tC \5\n");
- printf("\5\t\t\t\t\t\t\tI \5\n");
- printf("\5\t\t\t B A N K\t\t\t\t\5\n");
- printf("*****************************************************************\n");
- system("pause");
- system("cls");
- do{
- printf("************************\n");
- printf("* Welcome to TSB! *\n");
- printf("* \20 1.) User Login *\n");
- printf("* \20 2.) Admin Login *\n");
- printf("* \20 3.) Create Account *\n");
- printf("* \20 4.) Exit *\n");
- printf("************************\n");
- printf(" Input: ");
- fflush(stdin);
- scanf("%d", &opt);
- system("pause");
- system("cls");
- switch(opt){
- case 1: signIn(person,strg,count);//This is where the person will be directed to the Sign In Function
- break;
- case 2: admin(person,count,&LL);//This is where the person will be directed to the Admin only Function(FILES)
- break;
- case 3: createAcc(person, &count,size);//This is where the person will be directed to the Creation Function
- person[count-1].idNum=count;//count2 and count is to keep track of the number of persons
- fwrite(&person[count-1],sizeof(account),1,fp);//writes the whole structure to admin.txt
- break;
- case 4: break;
- default: printf("Try Again\n");
- system("pause");
- system("cls");
- }
- }while(opt!=4);
- fclose(fp);
- printf("Thank You for Using Our System!");
- getch();
- return 0;
- }
- int signIn(account acc[],account container[],int count5){
- FILE *fp,*fp3;
- fp3=fopen("storage.txt","r");
- char s[100],t;
- int m,z,num,pin,i=0,x,count=0, count2,count3=0;
- char opt;
- do{
- z=0;
- t='\b';
- count2=count;
- printf("--SIGN IN--\n");
- printf("Note: Pin code must be 5 digits\n");
- printf("Enter Pin Code:");
- while(t!='\r'){
- t=getch();
- if(t=='\b' && z>0){
- z--;
- putch(t);
- putch(' ');
- putch(t);
- }
- else if(t!='\r' && t!='\b'){
- putch('*');
- s[z]=t;
- z++;
- }
- }
- s[z]='\0';
- if(strlen(s)==5){
- m==0;
- count3=3;
- while(fread(&container[i],sizeof(account),1,fp3)){
- if(strcmp(s,container[i].code.pin)==0){
- m=1;
- printf("\nLogin Successful!");
- do{ printf("\n");
- system("pause");
- system("cls");
- if(container[i].info.gender=='M'||container[i].info.gender=='m'){
- printf("Welcome Mr. ");
- for(x=0;x<strlen(container[i].info.LName);x++){
- if(islower(container[i].info.LName[x])>0){
- printf("%c", toupper(container[i].info.LName[x]));
- }else{
- printf("%c",container[i].info.LName[x]);
- }
- }
- }else if(container[i].info.gender=='F'||container[i].info.gender=='f'){
- printf("Welcome Ms. ");
- for(x=0;x<strlen(container[i].info.LName);x++){
- if(islower(container[i].info.LName[x])>0){
- printf("%c", toupper(container[i].info.LName[x]));
- }else{
- printf("%c",container[i].info.LName[x]);
- }
- }
- }
- printf("!\n1.) Cash Withdrawal\n");
- printf("2.) Cash Deposit\n");
- printf("3.) Balance Inquiry\n");
- printf("4.) Back to Main Menu\n");
- printf("Input:");
- scanf("%d", &num);
- system("pause");
- system("cls");
- switch(num){
- case 1: printf("--Cash Withdrawal--\n");
- if(container[i].withD.aMoney!=0){
- printf("Enter Valued Amount:");
- scanf("%d", &num);
- if(num>container[i].withD.aMoney){
- printf("Cannot Withdraw Requested Amount!\n");
- }else{
- fp=fopen("storage.txt","w");
- container[i].withD.aMoney=container[i].withD.aMoney-num;
- fwrite(&container[i],sizeof(account),1,fp);
- fclose(fp);
- printf("Withdraw Succesful\n");
- }
- }else{
- printf("Insufficient balance\n");
- }
- break;
- case 2: printf("--Cash Deposit--\n");
- printf("Enter Valued Amount:");
- scanf("%d", &num);
- fp=fopen("storage.txt","w");
- container[i].withD.aMoney=container[i].withD.aMoney+num;
- fwrite(&container[i],sizeof(account),1,fp);
- fclose(fp);
- printf("Deposit Succesful\n");
- break;
- case 3: printf("Balance: %d\n", container[i].withD.aMoney);
- break;
- case 4:
- return 0;
- break;
- default: printf("Try Again!\n");
- }
- printf("Do you want to go back?(Y/N)\n");
- printf("Input:");
- fflush(stdin);
- scanf("%c", &opt);
- }while(opt!='N'||opt!='n');
- }
- i++;
- }
- }else{
- printf("\nTry Again!(PIN must be 5 digits)\n");
- system("pause");
- system("cls");
- count3++;
- }
- }while(count3!=3);
- if(m==0){
- printf("\nAccount not found!\n");
- system("pause");
- system("cls");
- }
- fclose(fp3);
- }
- void createAcc(account acc[], int *count,int size){
- FILE *fp4;
- fp4=fopen("num.txt","w");
- int num,count2,i,count3=0;
- char pin[100];
- if(*count<=size){
- printf("--CREATE ACCOUNT--\n");
- printf("First Name:");
- fflush(stdin);
- gets(acc[*count].info.FName);
- printf("Middle Initial:");
- fflush(stdin);
- scanf("%c", &acc[*count].info.MI);
- printf("Last Name:");
- fflush(stdin);
- gets(acc[*count].info.LName);
- printf("Gender(M/F):");
- fflush(stdin);
- scanf("%c", &acc[*count].info.gender);
- printf("Enter Amount:");
- scanf("%d", &acc[*count].withD.aMoney);
- do{
- printf("PIN Code(MUST BE 5 DIGITS):");
- fflush(stdin);
- gets(pin);
- if(strlen(pin)==5){
- if(*count==0){
- count3=3;
- strcpy(acc[*count].code.pin,pin);
- *count=*count+1;
- fprintf(fp4,"%d",*count);
- printf("Account Creation Successful!\n");
- system("pause");
- system("cls");
- i=size;
- }else{
- for(i=0;i<*count;i++){
- if(pin!=acc[i].code.pin){
- count3=3;
- strcpy(acc[*count].code.pin,pin);
- *count=*count+1;
- fprintf(fp4,"%d",*count);
- printf("Account Creation Successful!\n");
- system("pause");
- system("cls");
- i=size;
- }
- }
- }
- }else{
- printf("Try Again!\n");
- system("pause");
- system("cls");
- count3++;
- }
- }while(count3!=3);
- }else{
- printf("Can't Create Account. Storage is Full!\n");
- system("pause");
- system("cls");
- }
- fclose(fp4);
- }
- void admin(account acc[],int count,NODE_T **LL){
- FILE *fp,*fp2;
- NODE_T *trav, *temp, person[100];
- fp=fopen("admin.txt","r");
- account container[100];
- char container2[10],code[10];
- char s[100],t;
- int y,z=0, i=0,x,count2=0;
- if(fp!=NULL){
- fscanf(fp,"%s", &container2);
- }else{
- printf("Error! file not found");
- }
- do{
- y=0;
- t='\b';
- printf("Enter Admin Code:");
- while(t!='\r'){
- t=getch();
- if(t=='\b' && y>0){
- y--;
- putch(t);
- putch(' ');
- putch(t);
- }
- else if(t!='\r' && t!='\b'){
- putch('*');
- s[y]=t;
- y++;
- }
- }
- s[y]='\0';
- if(strcmp(s,container2)==0){
- count2=3;
- printf("\nLogin Successful!\n");
- system("pause");
- system("cls");
- fp2=fopen("storage.txt","r");
- *LL=NULL;
- while(fread(&container[z],sizeof(account),1,fp2)){
- if(*LL == NULL){
- *LL=(NODE_T *)malloc(sizeof(NODE_T));
- strcpy((*LL)->d.info.FName, container[z].info.FName);
- strcpy((*LL)->d.info.LName, container[z].info.LName);
- strcpy((*LL)->d.code.pin,container[z].code.pin);
- (*LL)->d.info.MI = container[z].info.MI;
- (*LL)->d.info.gender = container[z].info.gender;
- (*LL)->d.withD.aMoney=container[z].withD.aMoney;
- (*LL)->d.idNum=container[z].idNum;
- (*LL)->next=NULL;
- trav=*LL;
- }else{
- temp=(NODE_T *)malloc(sizeof(NODE_T));
- strcpy(temp->d.info.FName, container[z].info.FName);
- strcpy(temp->d.info.LName, container[z].info.LName);
- strcpy(temp->d.code.pin,container[z].code.pin);
- temp->d.info.MI = container[z].info.MI;
- temp->d.info.gender = container[z].info.gender;
- temp->d.withD.aMoney=container[z].withD.aMoney;
- temp->d.idNum=container[z].idNum;
- temp->next=NULL;
- trav->next=temp;
- while(trav->next!=NULL){
- trav=trav->next;
- }
- }
- z++;
- }
- trav=*LL;
- if(trav==NULL){
- printf("Storage Empty!\n");
- }
- while(trav!=NULL){
- printf("********************************\n");
- printf("Account: %d\n", i+1);
- printf("ID Num: %d\n", trav->d.idNum);
- printf("FULL NAME: ");
- for(x=0;x<strlen(trav->d.info.LName);x++){
- if(islower(trav->d.info.LName[x])>0){
- printf("%c", toupper(trav->d.info.LName[x]));
- }else{
- printf("%c",trav->d.info.LName[x]);
- }
- }
- printf(", ");
- for(x=0;x<strlen(trav->d.info.FName);x++){
- if(islower(trav->d.info.LName[x])>0){
- printf("%c", toupper(trav->d.info.FName[x]));
- }else{
- printf("%c",trav->d.info.FName[x]);
- }
- }
- printf(" ");
- if(islower(trav->d.info.MI)>0){
- printf("%c", toupper(trav->d.info.MI));
- }else{
- printf("%c",trav->d.info.MI);
- }
- printf(".\n");
- if(trav->d.info.gender=='m'||trav->d.info.gender=='M'){
- printf("Gender: Male\n");
- }else{
- printf("Gender: Female\n");
- }
- printf("Balance: %d\n", trav->d.withD.aMoney);
- printf("Pin Code: %s\n", trav->d.code.pin);
- trav = trav->next;
- ++i;
- printf("********************************\n");
- }
- system("pause");
- system("cls");
- fclose(fp2);
- }else{
- count2++;
- printf("\nPlease Try Again!\n");
- system("pause");
- system("cls");
- fflush(stdin);
- }
- }while(count2!=3);
- fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement