"C Language and Programming" project 2-15: Modular Simple banking system design

Source: Internet
Author: User
Tags diff

Problem Description:

https://edu.csdn.net/course/play/456/4808

Banking system. CPP: Defines the entry point of the console application. #include "stdafx.h" #include <stdlib.h> #pragma warning (disable:4996) int passtest (); void ibalance (); void Withdraw (); void deposit (); void Passchange (); int main () {int ichoice,testresult;printf ("Welcome to the grass Mud horse bank \ n"); TestResult = Passtest (); while (TestResult) {printf ("\ n");p rintf ("1. Check balance \ n");p rintf ("2. Withdrawals \ \");p rintf ("3. Deposit \ n"); printf ("4. Change password \ n");p rintf ("0. exit \ n");p rintf ("Please Enter (0-4):") scanf ("%d", &ichoice); switch (ichoice) {case 1:ibalance (); Break Case 2:withdraw (); Break;case 3:deposit (); Break;case 4:passchange (); Break;default:break;}    if (Ichoice = = 0) {break;}} return 0;} int Passtest () {printf ("Please enter 6-digit password:"), while (1) {int pass, passstored, Itry (1), righttime (0); File *FP;FP = fopen ("D:\\code\\pass.dat", "R"), if (fp = = NULL) {printf ("file cannot open!"); Exit (0);} for (int i = 0; i < 6; i++) {scanf_s ("%1d", &pass), fscanf (FP, "%1d", &passstored); if (pass = = passstored) {Rightt ime++;}} if (Righttime = = 6) {fclose (FP); return 1;break;}else if (itry<3) {itry++;p rintf ("Password error accumulated%d times, please re-enter:", itry-1); continue;} else{printf ("Password error accumulated%d times, system terminated \ n", itry); fclose (FP); return 0;break;}} void Ibalance () {double balance; File *FP;FP = fopen ("D:\\code\\balance.dat", "R"), if (fp = = NULL) {printf ("file cannot open!"); Exit (0);} FSCANF (FP, "%lf", &balance);p rintf ("Balance:%.2lf\n\n", balance); fclose (FP);} void Withdraw () {Double cash, balance, diff;printf ("Please enter the amount:"); scanf ("%lf", &cash); File *FP;FP = fopen ("D:\\code\\balance.dat", "R"), if (fp = = NULL) {printf ("file cannot open!"); Exit (0);} FSCANF (FP, "%lf", &balance); if (balance>cash) {diff = balance-cash;fclose (fp); fp = fopen ("D:\\code\\balance.dat "," w "); fprintf (FP,"%lf ", diff), Fclose (fp), fp = fopen (" D:\\code\\balance.dat "," R "); FSCANF (FP,"%lf ", &balance); printf ("Current balance:%.2lf\n\n", balance); fclose (FP);} else{printf ("The withdrawal amount is greater than the balance, withdrawals fail \ n"); fclose (FP);}} void deposit () {Double cash, balance, diff;printf ("Please enter Deposit Amount:"), scanf ("%lf", &cash); FILE *FP;FP = fopen ("D:\\code\\balance.dat", "R "), if (fp = = NULL) {printf (" File cannot open! "); Exit (0);} FSCANF (FP, "%lf", &balance);d iff = balance + cash;fclose (fp), fp = fopen ("D:\\code\\balance.dat", "w"), if (fp = = NULL) { printf ("File cannot open!"); Exit (0);} fprintf (FP, "%lf", diff), Fclose (fp), fp = fopen ("D:\\code\\balance.dat", "R"), if (fp = = NULL) {printf ("File cannot open!") ; exit (0);} FSCANF (FP, "%lf", &balance);p rintf ("Current balance:%.2lf\n", balance); fclose (FP);} void Passchange () {while (1) {int pass, pass2;printf ("Please enter new password:"), scanf ("%d", &pass); if (pass>=100000 && Pass <=999999) {printf ("Please enter new password:"), scanf ("%d", &pass2), if (pass = = Pass2) {FILE *FP;FP = fopen ("d:\\code\\ Pass.dat "," W "), fprintf (FP,"%d ", pass), fclose (FP);p rintf (" Password modification succeeded \ n ");} break;} else{printf ("The number of passwords is insufficient, please fill 6 bits \ n"); continue;}}

  

Feelings:

Data written to the hard disk (such as writing a text document) appears to be in effect after fclose

such as the withdrawal after the "current balance", must be written

fp = fopen ("D:\\code\\balance.dat", "W"), fprintf (FP, "%lf", diff), Fclose (fp), fp = fopen ("D:\\code\\balance.dat", "R"); FSCANF (FP, "%lf", &balance);p rintf ("Current balance:%.2lf\n\n", balance); fclose (FP);

  

=

"C Language and Programming" project 2-15: Modular Simple banking system design

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.