Advanced 21st class, practice, simplified Banking system Development Fourth edition

Source: Internet
Author: User

/**copyright (c) 2015/6/3 csdn blog *all rights reserved.* file name: main.c*    Creator: Golden Leaf * finish Date: 2015/6/3* version number: v1.0* problem Description: Small Banking application * Program output: */#include <stdio.h> #include "bank.h" int main () {    if (ipass () ==1)    {        downdate ();        Work ();        Update ();    }    return 0;}


#ifndef bank_h_included#define bank_h_included#define upnum 2000int ipass (); Bank Employee Password confirmation void downdate (); Load data int ichoose (); The bank employee selects the function int search (int id); Used to find the account corresponding subscript int inputpass (); Used to enter the password void work (); Main Menu void Open_account (); 1 Open account void cancellation (); 2 write-off void deposit (); 3 deposit void Withdraw_money (); 4 withdrawal void query (); 5 query void Transfer_accounts (); 6 transfer void loss (); 7 reporting void Unloss (); 8 unpacking void change (); 9 The Secret Void Update (); Save data, exit struct bank{    int num;    Char name[20];    int password;    Double balance;    int state;}; struct bank user[upnum];int N; Actual number of bank users #endif//bank_h_included

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <    conio.h> #include "bank.h" int ipass () {int i,j=3,k;    int right=0;    Char ch;    Char worker[20][20];    Char ipass[20][20];    Char worker1[20];    Char ipass1[20];    FILE *FP;    printf ("+-------------------+\n");    printf ("+ Welcome to CSDN Bank +\n");    printf ("+-------------------+\n");        if ((Fp=fopen ("Worker.txt", "R")) ==null) {printf ("Worker file cannot open!");    Exit (0);    } for (i=0; i<20; i++) {fscanf (FP, "%s%s", worker[i],ipass[i]);//read into the worker user name} fclose (FP);        Do {printf ("Please enter the clerk's user name:");        scanf ("%s", worker1);        printf ("Please enter password:");        i=0;   while ((Ch=getch ()) = ' \ r ') {ipass1[i++]=ch-1;        File save password using encrypted Putchar (' * ');        } ipass1[i]= ' + ';        Fflush (stdin);        printf ("\ n"); for (k=0; k<20; k++) {if (strcmp (worker1,worker[k]) ==0&AMP;&AMP;STRCMP (Ipass1,ipass[k]) ==0) right=1;        } if (right==1) {break;            } else {j--; if (j>0) {printf ("more than 3 times will exit, you can also try%d times!")            \ n ", j);                } else {printf ("Sorry, you cannot enter the system \ n");            Exit (0);    }}} while (j); return right;}

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <    conio.h> #include "bank.h" void Downdate () {int i=0;    FILE *FP;        if ((Fp=fopen ("Bank.txt", "R")) ==null) {printf ("Bank file cannot open!");    Exit (0); } while (FSCANF (FP, "%d%s%d%lf%d", &user[i].num,user[i].name, &user[i].password, &user[i].balance,&    user[i].state)! = EOF) {i++;    } n=i;    Fclose (FP); return;}    void work () {int ichose;        do {ichose=ichoose ();        Switch (ichose) {case 1:open_account ();//opening a break; Case 2:cancellation ();        2 write-off break; Case 3:deposit ();        3 Deposit break; Case 4:withdraw_money ();        4 withdrawal break; Case 5:query ();        5 query break; Case 6:transfer_accounts ();        6 transfer break; Case 7:loSS ();        7 Report loss break; Case 8:unloss ();        8 Unpacking break; Case 9:change ();        9 The secret break;            Case 0:printf ("Welcome again \"); Update (); Save Exit}} while (Ichose);}    int Ichoose () {int ichose;        while (1) {printf ("\ n");        printf ("+----------------------------+\n");        printf ("+ 1 account opening 2 pin households 3 deposit +\n");        printf ("+ 4 withdrawals 5 enquiries 6 transfer +\n");        printf ("+ 7 lost 8 9 +\n");        printf ("+ 0 exit +\n");        printf ("+----------------------------+\n");        printf ("Please enter operation instructions:");        scanf ("%d", &ichose);        if (ichose>=0 && ichose<=9) {break;    } else printf ("Input error, please re-select \ n \ nthe"); } return ichose;}    void Open_account () {int ipass1,ipass2;    if (n==upnum) {printf ("The bank user reaches the upper limit and cannot open an account \ \");    } printf ("Opening an account \ n");    printf ("Please enter user account:"); scanf ("%d", &user[N].num);    printf ("Please enter user name:");    scanf ("%s", user[n].name);    printf ("Please enter password:");    Ipass1=inputpass ();    printf ("Please Confirm password again:");    Ipass2=inputpass ();        if (ipass1==ipass2) {user[n].password=ipass1;        user[n].state=0;        printf ("Deposit Amount:");        scanf ("%lf", &user[n].balance); printf ("Successful account opening!")        \ n ");    n++; } else {printf ("Bad password, failed to open account!")    \ n ");    }}void cancellation () {int i;    int cancel;    int pass;    printf ("Enter the user account to be sold:");    scanf ("%d", &cancel);    I=search (cancel);    printf ("Name:%s\n", user[i].name);    printf ("Password:");    Pass=inputpass ();        if (Pass==user[i].password) {printf ("Balance:%.2lf", user[i].balance);        printf ("Confirm pin y/n:");  if (ToLower (GetChar ()) = = ' Y ') {user[i].balance=0;  After withdrawal, the balance becomes 0 user[i].state=2; Status changed to logout printf ("Withdrawal%.2f yuan, pin the success of the household!")        \ n ", user[i].balance); } else {printf ("You canceled the operation, the PIN user failed!")        \ n "); }} else {printf ("Password error, pinFailed!    \ n ");    }}void deposit () {int i;    int id;    int pass;    Double money;    printf ("Please enter your account:");    scanf ("%d", &id);    I=search (ID); if (i<0) {printf ("username does not exist!")    \ n ");        } else {printf ("Name:%s", user[i].name);        printf ("Password:");        Pass=inputpass ();            if (pass==user[i].password&&user[i].state==0) {printf ("Enter Deposit Amount:");            scanf ("%lf", &money);        printf ("Total balance%.2lf, deposit success", money+user[i].balance); } else if (pass==user[i].password&&user[i].state==1) {printf ("card has been lost, deposit failed!")        \ n "); } else if (pass==user[i].password&&user[i].state==2) {printf ("card is unregistered, deposit failed!")        \ n "); } else {printf ("Bad password, deposit failed!        \ n ");    }}}void Withdraw_money () {int i;    int id;    int pass;    Double money;    printf ("Please enter your account:");    scanf ("%d", &id);    I=search (ID); if (i<0) {printf ("username does not exist!")    \ n "); } else    {printf ("Name:%s", user[i].name);        printf ("Password:");        Pass=inputpass ();            if (pass==user[i].password&&user[i].state==0) {printf ("Balance:%.2lf\n", user[i].balance);            printf ("Withdrawal amount:");            scanf ("%lf", &money);            if (money>user[i].balance) {printf ("Insufficient balance, withdrawal failed");                } else {User[i].balance-=money;            printf ("Balance:%.2lf", user[i].balance); }} else if (pass==user[i].password&&user[i].state==1) {printf ("card has been lost, withdrawal failed!")        \ n "); } else if (pass==user[i].password&&user[i].state==2) {printf ("card is unregistered, withdrawal failed!")        \ n "); } else {printf ("Bad password, withdrawal failed!        \ n ");    }}}void query () {int i;    int id;    int pass;    printf ("Please enter your account:");    scanf ("%d", &id);    I=search (ID);    printf ("Name:%s", user[i].name);    printf ("Password:"); Pass=inputPass ();        if (Pass==user[i].password) {printf ("Balance:%.2lf\n", user[i].balance);        if (user[i].state==0) {printf ("Current state: normal \ n");        } else if (user[i].state==1) {printf ("Current status: report loss \ n");        } else printf ("Current status: Logoff \ n"); printf ("Query finished!    \ n ");    } else {printf ("Bad password, query failed \ n");    }}void transfer_accounts () {int id,id2;    int i,i2;    Double money;    int pass;    printf ("Please enter the transfer account:");    scanf ("%d", &id);    I=search (ID);    printf ("Name:%s", user[i].name);    printf ("Password:");    Pass=inputpass ();        if (pass==user[i].password&&user[i].state==0) {printf ("Please enter the transfer account:");        scanf ("%d", &AMP;ID2);        I2=search (ID2);        printf ("Transfer amount:");        scanf ("%lf", &money); if (money>user[i].balance) {printf ("Insufficient amount, transfer failed!")        \ n ");            } else {printf ("Transfer succeeded, balance%.2lf\n", User[i].balance-money);  User[i2].balance+=money;      }}}void loss () {int id;    int i;    int pass;    printf ("Please enter your account:");    scanf ("%d", &id);    I=search (ID);    printf ("Name:%s", user[i].name);    printf ("Password:");    Pass=inputpass ();        if (Pass==user[i].password) {printf ("Balance:%.2lf\n", user[i].balance);            if (user[i].state==0) {printf ("Current state: normal \ n");            user[i].state=1; printf ("Success in reporting!"        \ n ");        } else if (user[i].state==1) {printf ("Current status: report loss \ n");    } else printf ("Current status: Logoff \ n");    } else {printf ("Bad password, lost report \ n");    }}void Unloss () {int id;    int i;    int pass;    printf ("Please enter your account:");    scanf ("%d", &id);    I=search (ID);    printf ("Name:%s", user[i].name);    printf ("Password:");    Pass=inputpass ();        if (Pass==user[i].password) {printf ("Balance:%.2lf\n", user[i].balance);        if (user[i].state==0) {printf ("Current state: normal \ n"); } else if (user[i].state==1) {printf ("currentStatus: Loss of the report \ n ");            user[i].state=0; printf ("The solution hangs successfully!")        \ n ");    } else printf ("Current status: Logoff \ n");    } else {printf ("Bad password, failed to hang \ n");    }}void change () {int id;    int i;    int pass,pass1,pass2;    printf ("Please enter your account:");    scanf ("%d", &id);    I=search (ID);    printf ("Name:%s", user[i].name);    printf ("Password:");    Pass=inputpass ();        if (pass==user[i].password&&user[i].state!=2) {printf ("New password:");        Pass1=inputpass ();        printf ("Enter again:");        Pass2=inputpass ();        if (pass1==pass2) {user[i].password=pass1;        } else {printf ("2 times input is incorrect, password failed \ n"); }} else {printf ("The password is incorrect!    \ n ");    }}void Update () {FILE *p;    int i=0;        if ((P=fopen ("Bank.txt", "W")) ==null) {printf ("Bank.txt file cannot open!");    Exit (0); } for (i=0; i<n; i++) fprintf (p, "%d%s%d%lf%d\n", User[i].num, User[i].name, User[i].password, User[i].balan CeUser[i].state);    Fclose (P); Exit (0);}

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <    conio.h> #include "bank.h" int search (int id) {int index;    Index=-1;    int i;            for (i=0; i<n; i++) {if (user[i].num==id) {index=i;        Break }} return index;}  int Inputpass () {char ch;   Receive character form cipher int ipass=0;    To convert to a number int i;  while (1) {for (i=0; i<6; i++) {ch=getch ();   Enter but do not show Putchar (' * ');            Output * if (isdigit (CH)) ipass=ipass*10+ (ch-' 0 ');                else {ipass=0;  Break After exiting for loop, accept}} fflush (stdin) again;        Clears the input printf ("\ n") already in the keyboard buffer; if (ipass==0)//This condition may be caused by two cases: entered non-numeric characters are directly reset to 0, or 6-bit full 0 after the normal exit for loop {printf ("Password requirements are all numbers, and not all 0!")            \ n ");        printf ("Re-enter Password:");    } else break; } return iPass;}







And so the teacher to the advanced all the practice has been completed again to see the advanced, the current in the review before the content


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Advanced 21st class, practice, simplified Banking system Development Fourth edition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.