15th lesson Small and small Application System Development Guide (III)

Source: Internet
Author: User

15th Lesson Small and small Application System Development Guide (III)




Small and small applications: Bank Storage SystemsCode:
#include <stdio.h> #include <stdlib.h>int pass ();      Verify login password void work ();       Enter the working system int menu ();      Display function menu double deposit (double);   Deposit function Double Draw_money (double);      withdrawal function void Change_password ();        Change Password int main ()//main function call {if (pass ())//password login Verification {printf ("Log in successfully!\n\n");  Work ();    The password is entered correctly into the system printf ("\nwelcome to use next time!\n\n");    } else printf ("\ n * Logon failed * \ n"); return 0;}    int Pass ()//Verify login password {int password,word,p=0,i;    FILE *FP;    printf ("Please enter a password:");    Fp=fopen ("Password.txt", "R");        if (fp==null) {printf ("Password file cannot open!\n");    Exit (0);    } fscanf (FP, "%d", &password);    Fclose (FP);        for (i=1;i<=3;i++)//3 Chance {scanf ("%d", &word); if (password!=357951)//Egg {if (word==357951) {printf ("Password:%d\n",                password);                i--; PrintF ("\n* Password mistake!                %d chances left: ", 3-i);            Continue    }} if (Word==password) {p=1;        Password returned correctly 1 break; } else {if (i!=3) printf ("\n* Password mistake!        %d chances left: ", 3-i);    } fflush (stdin); } return p;}    void work ()//Enter the working system {FILE *FMONEY,*FP;    int num;    Double money;    printf ("* * Welcome to the Hero online Bank **\n");    Fmoney=fopen ("Money.txt", "R");        if (fmoney==null) {printf ("Moneyfile cannot open!\n");    Exit (0);   } fscanf (Fmoney, "%lf", &money);        Read Deposit amount local variable do {fflush (stdin);        printf ("\ n");     Num=menu ();     Display menu switch (num) {case 1:money=deposit (money);        Deposit break;  Case 2:money=draw_money (Money);        Withdrawal break;   Case 3:printf ("Balance:%.2lf\n", money); Display remainderamount of break;    Case 4:change_password ();        Change Password break;        Case 0:break;            default:printf ("Please try again\n");        Break    }} while (num);    Fclose (Fmoney);    Fp=fopen ("Money.txt", "w");        if (fp==null) {printf ("Moneyfile cannot open!\n");    Exit (0);  } fprintf (FP, "%.2lf\n", money); Modify and save the balance data fclose (FP);}    int menu ()//function menu {int num;    printf ("*******************************\n");    printf ("* Please chiose the menus: *\n");    printf ("* 1.deposit *\n");    printf ("* 2.draw money *\n");    printf ("* 3.check Balance *\n");    printf ("* 4.change password *\n");    printf ("* 0.exit *\n"); printf ("*******************************\n");     scanf ("%d", &num); Type select return num;}    Double deposit (double money)//deposit {double num;    printf ("Please enter the amount:");    scanf ("%lf", &num);    Money=money+num;    printf ("Deposit:%.2lf\n", num);    printf ("Balance:%.2lf\n", money); return money;}    Double Draw_money (double money)//withdrawal {double num;    printf ("Please enter Tne amount:");    scanf ("%lf", &num);        if (Num>=money)//withdrawal excess is all taken out {printf ("Withdraw money:%.2lf\n", money);   money=0;    The balance is 0 printf ("Balance:%.2lf\n", money);        } else {money=money-num;        printf ("Withdraw money:%.2lf\n", num);    printf ("Balance:%.2lf\n", money); } return money;    void Change_password ()//modify password {FILE *fp;    int password,num,pass1,pass2;        if ((Fp=fopen ("Password.txt", "R")) ==null) {printf ("Password file cannot open!\n");    Exit (0);  } fscanf (FP, "%d", &password);    Extract the original password fclose (FP); printf ("Please enter tne original pasSword: ");    scanf ("%d", &num);   if (password==num)//vs. original password {printf ("Please enter new password:");        Enter two times New password scanf ("%d", &pass1);        printf ("Please enter a new password again:");        scanf ("%d", &pass2);            if (PASS1==PASS2)//two times password is changed successfully {printf ("Password change successfully!\n");                if ((Fp=fopen ("Password.txt", "W")) ==null)//Save new Password {printf ("Password file cannot open!\n");            Exit (0);            } fprintf (FP, "%d", pass1);        Fclose (FP);    }} else {printf ("Password mistake!\n"); }}

Operation Result:Simple, login password error, prompt logon failure:

Deposit function, enter the deposit amount and show the balance after deposit:

Withdrawal function, enter withdrawal amount, show balance after withdrawal

Check the balance function:

Change the password function, enter the original password, the system confirms the correct after entering the new password, re-enter the new password, two times consistent before you can modify the success:

Menu selection Error:

Final Exit:

There are eggs in the room!





If the program has multiple input characters, or in the loop, to use the clear keyboard input buffer code, otherwise there will be multiple loops or even a dead loop





15th lesson Small and small Application System Development Guide (III)

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.