プロジェクト実践:銀行貯蓄システムの設計と実現


8.14銀行貯蓄システムの設計と実現
一、問題の説明:
銀行カウンター業務の要求をシミュレートし、小型の「銀行貯蓄システム」ソフトウェアの開発を実現し、その中には口座開設、預金、引き出し、振替、改密、紛失届、解掛、販売などの機能が含まれている.
開発の過程で、問題解決の過程の要求に従って、開発の過程でしなければならない仕事を体験してください.以下のシステムの基本的な機能の説明を除いて、調査研究を奨励して、あなたが開発したソフトウェアをできるだけ実際の銀行貯蓄システムの実際の業務内容に合致させます.8.1節の適切なデータ構造の選択に関する議論を参照して、データストレージスキームを決定することができる.
プログラムの実行中またはプログラムの実行が終了する前に、業務で発生したデータをファイルに保存し、次の実行時にファイルからデータを読み出し、業務を元の基礎の上で継続させることが要求される.テキストファイルを使用することも、バイナリファイルを使用することもできます.
モジュール化プログラム設計の要求に基づいて,各機能を独立した関数実現に設計する.必要に応じて,各関数におけるサブ機能呼び出しをサポートするモジュールとして共通の機能設計専門の関数を抽出する.「メニュー」式の操作インタフェースを設計し、ユーザーの使用を便利にすることをお勧めします.
各機能の要件は、次のとおりです.
(1)口座開設:銀行口座を1つ増やし、口座番号、氏名、パスワード、金額を入力し、状態は自動的に0(正常)に設定する.パスワードを入力する過程で、実際に入力した記号の代わりにアスタリスク(*)を表示することをお勧めします(実装方法は検索エンジンで助けてください).パスワードの設定としては、パスワードを1回入力した後、再度パスワードを入力する必要があり、2回入力が一致した後、受け入れて保存します.パスワードが設定されているため、他の業務は入力したアカウント、パスワードが正しい場合に継続しなければならない.
(2)預金:口座番号、金額を入力し、その口座の残高を増やす.
(3)引き出し:口座番号、金額を入力し、引き出し後の残高を減らす.要求引き出し額は元の残高を超えてはならない.
(4)照会:口座番号を入力し、口座情報を表示する.
(5)振り替え:振り替えた口座、金額及び振り替えた口座を入力し、振り替え口座の残高を減らし、振り替え口座の残高を増やす.転出口座を要求する金額は当該口座の残高を超えてはならず、転出減少した金額は、転入口座の増加した金額と同じである.
(6)紛失届け:アカウントを入力し、その状態を1(紛失届け)に変更します.紛失状態にあるアカウントは、アンフック以外の操作は実行できません.
(7)保留解除:アカウントを入力し、ステータスが1(紛失)のアカウントのステータスを0(正常)に変更します.
(8)口座販売:口座番号を入力し、確認した後、残高を全部引き出し、残高を0にし、ステータスstateを2(口座販売)にするように提示する.口座を開設した後の口座番号は、照会以外の機能を実行することはできません.
(9)改密:古いパスワードの代わりに新しいパスワードを使用します.新しいパスワードは2回入力する必要があります.一致してから、秘密変更に成功したことを確認します.
二、コード実現:
#include
#include
#include
int i=0;
int n=-1;
int k;
int id1;
FILE *p;
struct score{
	int  num;
	char name[20];
	int secret;
	int money;
	int state;
}rec[20];
void open()//  
{
     n=n+1;
    printf("	please input your name: 
"); scanf("%s",rec[n].name); rec[n].num=n; printf("please input your secret:
"); scanf("%d",&rec[n].secret); printf("how much do you want to saving?
"); scanf("%d",&rec[n].money); rec[n].state=0; printf("Open account successful,your account is %d!",n); system("pause"); } void savings()// { int id; int dl; printf("input num
"); scanf("%d",&id); printf("input your money
"); scanf("%d",&dl); if(rec[id].state==0) { rec[id].money+=dl; printf("Saving money successful!
"); // // printf("%d %s %d %d %d
",rec[id].num,rec[id].name,rec[id].secret,rec[id].money,rec[id].state); } else { printf("your account is report you can't saving money
"); } system("pause"); } void draw()// { int id1; int dl; int k; int i=0; printf("input num
"); scanf("%d",&id1); // , do { printf("input your key
"); scanf("%d",&k); i++; }while((k!=rec[id1].secret)&&(i<=2)); if(k==rec[id1].secret) { printf("How much do you want to draw
"); scanf("%d",&dl); if(rec[id1].state==0) { // if(dl>rec[id1].money) { do { printf("your money is only %d,you can't tansfer,please resume load:
",rec[id1].money); scanf("%d",&dl); } while(dl>rec[id1].money); rec[id1].money=rec[id1].money-dl; printf("Draw money successful!
"); } else { rec[id1].money=rec[id1].money-dl; printf("Draw money successful!
"); } } else { printf("your account is report
"); } } else{printf("your key is wrong you can't do account
");} system("pause"); } void refer()// { int id; int k; int i=0; printf("Input your num:
"); scanf("%d",&id); // , do { printf("input your key
"); scanf("%d",&k); i++; }while((k!=rec[id].secret)&&(i<=2)); if(k==rec[id].secret) { printf("Your account information:
"); if(rec[id].state==0) { printf("name:%5s
money:%5d
your account is normal
",rec[id].name,rec[id].money); } else if(rec[id].state==0){ printf("name:%5s
money:%5d
your account is report
",rec[id].name,rec[id].money); } else { printf("name:%5s
money:%5d
your account is closed
",rec[id].name,rec[id].money); } } else{printf("your key is wrong you can't do account
");} system("pause"); } void transfer()// { int id1; int id2; int s; int k; int i=0; printf("what is your account?
"); scanf("%d",&id1); printf("which account do you want to transfer?
"); scanf("%d",&id2); do { printf("Please input your key:
"); scanf("%d",&k); i++; }while((k!=rec[id1].secret)&&(i<=2)); if(k==rec[id1].secret) { if(rec[id1].state==1||rec[id1].state==1) { printf("your can't transfer
"); } else { printf("how much do you want to tansfer?
"); scanf("%d",&s); if(s>rec[id1].money) { do { printf("your money is only %d,you can't tansfer,please resume load
",rec[id1].money); scanf("%d",&s); }while(s>rec[id1].money); rec[id1].money=rec[id1].money-s; rec[id2].money=rec[id2].money+s; printf("transfer success!
"); } else { rec[id1].money=rec[id1].money-s; rec[id2].money=rec[id2].money+s; printf("transfer success!
"); } } } else{printf("your key is wrong you can't do account
");} system("pause"); } void report()// { int i=0; int k; int id1; printf("what is your account?
"); scanf("%d",&id1); do { printf("Please input your key:
"); scanf("%d",&k); i++; }while((k!=rec[id1].secret)&&(i<=2)); if(k==rec[id1].secret) { if(rec[id1].state==0) { rec[id1].state=1; printf("Report successful!
"); } else { printf("The account already reported,you needn't repetition report
"); } } else{ printf("your key is wrong you can't do account"); } system("pause"); } void cancel_report()// { int id1; int i=0; int k; printf("what is your account?
"); scanf("%d",&id1); do { printf("Please input your key:
"); scanf("%d",&k); i++; }while((k!=rec[id1].secret)&&(i<=2)); if(k==rec[id1].secret) { if(rec[id1].state==1) { rec[id1].state=0; printf("Cancel report successful!
"); } else { printf("The account is not report,you can't cancel report
"); } } else{ printf("your key is wrong you can't do account"); } system("pause"); } void cancel_account()// { int id1; int i=0; int k; printf("what is your account?
"); scanf("%d",&id1); do { printf("Please input your key:
"); scanf("%d",&k); i++; }while((k!=rec[id1].secret)&&(i<=2)); if(k==rec[id1].secret) { rec[id1].state=2; printf("We will draw all the money in your account
"); printf("Give you your money %d yuan
",rec[id1].money); rec[id1].money=0; printf("Close account successful!
"); } else{ printf("your key is wrong you can't do account"); } system("pause"); } void change_security()// { int s; int i=0; int k; int id1; int k1,k2; printf("what is your account?
"); scanf("%d",&id1); do { printf("Please input your key:
"); scanf("%d",&k); i++; }while((k!=rec[id1].secret)&&(i<=2)); if(k==rec[id1].secret) { printf("what key do you want to change to?"); scanf("%d",&k1); printf("Input your key one more time"); scanf("%d",&k2); if(k1==k2) { rec[id1].secret=k1; printf("Change security successful!
"); } else {printf("Change security FAIL,the two key isn't same!
");} } else{ printf("your key is wrong you can't do account"); } system("pause"); } void readDate() { int i=0; FILE *fp; if((fp=fopen("date.txt","r+"))==NULL) { printf("Can't open the date
"); exit(0); } while(fscanf(fp,"%d %s %d %d %d
",&rec[i].num,rec[i].name,&rec[i].secret,&rec[i].money,&rec[i].state ) != EOF) { i++; n++; } fclose(fp); } void writeDate() { int i; FILE *fp; if((fp=fopen("date.txt","r+"))==NULL) { printf("Can't open the date
"); exit(0); } for(i=0;i<=n;i++) { fprintf(fp,"
"); fprintf(fp,"%d %s %d %d %d
",rec[i].num,rec[i].name,rec[i].secret,rec[i].money,rec[i].state); } fclose(fp); printf("saving date successful!
"); system("pause"); } int main() { int s; readDate(); while(1) { system("cls"); printf("******************************MENU*********************************************

"); printf(" 0:Open a new account
"); printf(" 1:Savings money
"); printf(" 2:Draw money
"); printf(" 3:Refer account
"); printf(" 4:Transfer account
"); printf(" 5:Report account
"); printf(" 6:Cancel report
"); printf(" 7:cancel_account
"); printf(" 8:change_security
"); printf(" 9:Save date
"); printf(" 10:Quit
"); printf("*******************************************************************************

"); do{ printf("
Input your choice(0 ~ 10):"); scanf("%d",&s); }while(s<0||s>10); system("cls"); switch(s) { case 0:open();break; case 1:savings();break; case 2:draw();break; case 3:refer();break; case 4:transfer();break; case 5:report();break; case 6:cancel_report();break; case 7:cancel_account();break; case 8:change_security();break; case 9:writeDate();break; case 10:exit(0); } } return 0; }

この银行管理システムの设计は比较的に简単で、いくつかの机能はパスワードを隠すなどの机能も実现していません.また、パスワードの入力に対して长さの制限がありません.长さを超えるとプログラムが间违います.皆さんはいくつか改善してみてください.私も后で変更します.
三、プログラムテスト:
「data.txt」に銀行のデータが格納されると、プログラム実行時にメモリに読み込まれて処理され、処理が完了するとファイルに書き込まれます.プログラム実行前、ファイルのデータは以下の通りです.
               0 king 1 1 0
               1 ding 1 1 0
               2 vkj 1 1 0
               3 k 1 1 0
                4 j 1 2 0
最初の列から5番目の列は、カード番号、名前、パスワード、残高、ステータスに対応します.テストするときはこのファイルでテストできます.