




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、C語言程序?qū)嵺`實驗報告姓 名學(xué) 號班 級指 導(dǎo) 教 師開 設(shè) 學(xué) 期開 設(shè) 時 間實驗題目自動取款機程序設(shè)計實驗日期評 定 成 績評定人簽字評 定 日 期一、實驗?zāi)康?.函數(shù)的調(diào)用2.結(jié)構(gòu)體的使用3.文件的應(yīng)用:打開、關(guān)閉、輸入、輸出等4.宏定義二、實驗內(nèi)容與實驗步驟實驗內(nèi)容、原理分析1. 給出數(shù)據(jù)結(jié)構(gòu)或函數(shù)定義結(jié)構(gòu)體:struct clientslong int card_number,card_password;char name20;float money;yonghu3;card_number:銀行卡號card_password:密碼name:用戶名money:卡內(nèi)金額自定義函數(shù):vo
2、id fuction(float,int);用于登陸后的操作2. 用流程圖表示出來程序設(shè)計的思想開始用戶文件是否存在創(chuàng)建文件輸入用戶信息信息是否重復(fù)輸入卡號和密碼錯誤是否超過三次輸入信息是否正確輸入0輸入其他輸入5輸入4輸入3輸入2存款輸入1輸入錯誤修改密碼顯示菜單充話費取款結(jié)束3給出具體實驗步驟#include <stdio.h>#include <stdlib.h>#define N 3 /*用戶人數(shù)*/struct clientslong int card_number,card_password;char name20;float money;yonghuN;F
3、ILE *fp;int i;void fuction(float,int);void main()int j,number,password,times1=3,times2=3;printf(" 歡迎使用中國建設(shè)銀行自動取款機!n");fp = fopen("clients.txt","a+");if(getw(fp)=EOF)printf("用戶文件未設(shè)置!n");for(i=0;i<N;i+) /*文件不存在時,輸入用戶信息*/printf("請輸入第%d位用戶的信息:n",i+1);
4、printf("銀行卡號密碼用戶名卡內(nèi)金額n");scanf("%d %d %s %f",&yonghui.card_number,&yonghui.card_password,,&yonghui.money);if(i=1)while(yonghui.card_number=yonghui-1.card_number)|(yonghui.card_password=yonghui-1.card_password)printf("輸入信息有重復(fù)!請重新輸入n");printf("
5、;請輸入第%d位用戶的信息:n",i+1);printf("銀行卡號密碼用戶名卡內(nèi)金額n");scanf("%d %d %s %f",&yonghui.card_number,&yonghui.card_password,,&yonghui.money);if(i=2)while(yonghui.card_number=yonghui-1.card_number)|(yonghui.card_password=yonghui-1.card_password)|(yonghui.card_numbe
6、r=yonghui-2.card_number)|(yonghui.card_password=yonghui-2.card_password)printf("輸入信息有重復(fù)!請重新輸入n");printf("請輸入第%d位用戶的信息:n",i+1);printf("銀行卡號密碼用戶名卡內(nèi)金額n");scanf("%d %d %s %f",&yonghui.card_number,&yonghui.card_password,,&yonghui.money);fpri
7、ntf(fp,"%d %d %s %f",yonghui.card_number,yonghui.card_password,,yonghui.money);putc('n',fp);fclose(fp);printf("nn 請登錄系統(tǒng)n"); /*登錄系統(tǒng),輸入卡號和密碼*/printf("請輸入您的銀行卡號:n");scanf("%d",&number);printf("請輸入您的密碼:n");scanf("%d",&am
8、p;password);fp = fopen("clients.txt","r+");for(i=0;i<N;i+)fscanf(fp,"%d %d %s %f",&yonghui.card_number,&yonghui.card_password,,&yonghui.money);fclose(fp);for(i=0;i<N;i+) /*判斷卡號及密碼是否匹配*/if(number!=yonghu0.card_number)&&(number!=yongh
9、u1.card_number)&&(number!=yonghu2.card_number)if(times1-1)!=0)printf("該用戶不存在!您還有%d次嘗試機會n",times1-1);printf("請輸入您的銀行卡號:n");scanf("%d",&number);printf("請輸入您的密碼:n");scanf("%d",&password);i=-1;elseprintf("嘗試失敗!請按任意鍵退出:n");exit(0
10、);times1-;elseif(number=yonghui.card_number)if(password=yonghui.card_password)printf(" %s登陸成功!請繼續(xù)您的操作n",);j=i;i=5; /*登陸成功,退出循環(huán)*/elseif(times2-1)!=0)printf("密碼輸入錯誤!您還有%d次嘗試機會n",times2-1);printf("請輸入您的密碼:n");scanf("%d",&password);i=-1;elseprintf(
11、"嘗試失敗!請按任意鍵退出:n");exit(0);times2-;fuction(yonghuj.money,j);void fuction(float m,int k)float saved_money,fetched_money,payment;int phone_num,x,old_password,new_password;while(1)printf("1.存款.n2.取款.n3.充話費.n4.修改密碼.n5.顯示菜單.n0.退出系統(tǒng).n");scanf("%d",&x);switch(x)case 0:print
12、f("退出系統(tǒng)!");exit(0);case 1:printf("卡內(nèi)金額: %fn",m);printf("請輸入存款金額:n");scanf("%f",&saved_money);while(saved_money<0)printf("輸入有誤!請重新輸入!n");printf("請輸入存款金額:n");scanf("%f",&saved_money);m += saved_money;printf("操作成功!卡內(nèi)余
13、額為: %fn",m);yonghuk.money = m;fp = fopen("clients.txt","w+");for(i=0;i<N;i+)fprintf(fp,"%d %d %s %f",yonghui.card_number,yonghui.card_password,,yonghui.money);putc('n',fp);fclose(fp);break;case 2:printf("卡內(nèi)金額: %fn",m);printf("請
14、輸入取款金額:n");scanf("%f",&fetched_money);m -= fetched_money;while(fetched_money<0)|(m<0)printf("輸入有誤!請重新輸入!n");m += fetched_money;printf("請輸入取款金額:n");scanf("%f",&fetched_money);m -= fetched_money;printf("操作成功!卡內(nèi)余額為: %fn",m);yonghuk.mo
15、ney = m;fp = fopen("clients.txt","w+");for(i=0;i<N;i+)fprintf(fp,"%d %d %s %f",yonghui.card_number,yonghui.card_password,,yonghui.money);putc('n',fp);fclose(fp);break;case 3:printf("卡內(nèi)金額: %fn",m);printf("請輸入電話號碼:n");scanf("
16、;%d",&phone_num);printf("請輸入所交話費金額:n");scanf("%f",&payment);m -= payment;while(payment<0)|(m<0)printf("輸入有誤!請重新輸入!n");m += payment;printf("請輸入所交話費金額:n");scanf("%f",&payment);m -= payment;printf("操作成功!卡內(nèi)余額為: %fn",m);yo
17、nghuk.money = m;fp = fopen("clients.txt","w+");for(i=0;i<N;i+)fprintf(fp,"%d %d %s %f",yonghui.card_number,yonghui.card_password,,yonghui.money);putc('n',fp);fclose(fp);break;case 4:while(1)printf("請輸入原密碼:n");scanf("%d",&ol
18、d_password);if(old_password=yonghuk.card_password)printf("請輸入新密碼:n");scanf("%d",&new_password);printf("密碼修改成功!n");yonghuk.card_password = new_password;fp = fopen("clients.txt","w+");for(i=0;i<N;i+)fprintf(fp,"%d %d %s %f",yonghui.car
19、d_number,yonghui.card_password,,yonghui.money);putc('n',fp);fclose(fp);break;elseprintf("密碼輸入錯誤!n");break;case 5:break;default:printf("輸入有誤!請重新輸入!n");break;三、實驗過程與結(jié)果分析1.現(xiàn)象:輸入用戶信息后,在登錄系統(tǒng)時,輸入第一個用戶的信息,提示該用戶不存在解決方法:fp = fopen("clients.txt","r+"
20、);for(i=0;i<N;i+)fscanf(fp,"%d %d %s %f",&yonghui.card_number,&yonghui.card_password,,&yonghui.money);fclose(fp);2.現(xiàn)象:登錄系統(tǒng)時,輸入卡號或密碼超過3次錯誤后,仍能輸入解決方法:增加變量times1=3(卡號輸入錯誤的次數(shù)),times2=3(密碼輸入錯誤的次數(shù)),當(dāng)times-1>0時,提示剩余嘗試機會,當(dāng)times-1=0時,退出程序3.現(xiàn)象:存取款或充話費時,輸入負(fù)數(shù)仍能運行解決方法:增加循環(huán):wh
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- Unit 5 Free Time Let's Check(教學(xué)設(shè)計)-2023-2024學(xué)年人教新起點版英語四年級下冊
- 17他們那時候多有趣啊教學(xué)設(shè)計-2023-2024學(xué)年六年級下冊語文統(tǒng)編版
- 全國粵教清華版初中信息技術(shù)八年級下冊第2單元第4節(jié)《搭建智能應(yīng)用》教學(xué)設(shè)計
- 12《玩也有學(xué)問》教學(xué)設(shè)計-2024-2025學(xué)年道德與法治一年級上冊統(tǒng)編版
- 學(xué)院081102檢測技術(shù)與自動化裝置報錄數(shù)據(jù)分析報告
- Unit 5 Music Reading for Writing(教學(xué)設(shè)計)高一英語同步高效課堂(人教版2019必修第二冊)
- Unit 2 topic 1 You should brush your teeth.Section B 教學(xué)設(shè)計-2024-2025學(xué)年 仁愛科普版英語八年級上冊
- Module 5 Unit 1 We went to the Great Wall.(教學(xué)設(shè)計)-2024-2025學(xué)年外研版(一起)英語四年級上冊
- 科技創(chuàng)新中心項目組織結(jié)構(gòu)與管理模式
- 地方高??蒲袆?chuàng)新與產(chǎn)學(xué)研結(jié)合策略
- 《研學(xué)旅行課程設(shè)計》課件-研學(xué)課程設(shè)計計劃
- 會議記錄表格樣本
- 馬工程《藝術(shù)學(xué)概論》
- 改善護(hù)理服務(wù)行動計劃方案
- 羧基麥芽糖鐵注射液-臨床用藥解讀
- 《手語基礎(chǔ)學(xué)習(xí)》課件
- 建筑材料包銷協(xié)議書
- 2023-2024學(xué)年高中政治統(tǒng)編版必修三1-1 中華人民共和國成立前各種政治力量 課件(23張)
- SJG 09-2024 建筑基樁檢測標(biāo)準(zhǔn)
- 河南省南陽市淅川縣2023-2024學(xué)年八年級上學(xué)期期末考試數(shù)學(xué)試題(含答案)
- 口腔臨床技術(shù)操作規(guī)范
評論
0/150
提交評論