版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
C說話程序實踐I2J
試驗報告
姓名學號
班級指導教師
開設學期
開設時間
試驗標題主動取款機程序設計
試驗日期
評定人簽字
評定日期
第1頁,一共17頁
一.試驗目標
I.函數的挪用
2.構造體的運用
3.文件的運用:打開.封閉.輸入.輸出等
4.宏界說
二.試驗內容與試驗步驟
試驗內容.道理剖析
1.給出數據構造或函數界說
構造體:
structclients
(
longintcard_number,card_password;
charname[20];
floatmoney;
}yonghuf3];
card_number:銀行卡號
card_passwordW音瑪
name:用戶名
money:卡內金額
自界說函數:
voidfuction(float,int);
用于登陸后的操作
第2頁,一共17頁
2.用流程圖表示出來程序設計的思惟
輸
入
O
停止
3.給出具體試驗步驟
#include<stdio.h>
#include<stdlib.h>
#defineN3/*用戶人數*/
第3頁,一共17頁
structclients
longintcaid_number,card_password;
charname[20];
floatmoney;
)yonghu[N];
FILE*fp:
inti;
voidfuction(float,int);
voidmain()
(
intj,number,passwoidjimes1=3,times2=3;
printf("迎接運月中國扶植銀行主動取款機!\n”);
fp=fopenCclients.txt","a+");
if(getw(fp)==EOF)
printf("用戶文件未設置!\n“);
for(i=0;i<N;i++)/*文件不消失時,輸入用戶信息*/
printf("請輸入第%d位用戶的信息:\n”,i+1);
printf("銀行卡號暗碼用戶名卡內金額\n”);
scanf("%d%d%s%f',&yonghui].card_numbcr,&yonghulij.card_password,,&yonghuli].money);
if(i==l)
while((yonghu[i].card_number==yonghufi-ll.card_number)||(yonghu[i].card_passwoid==yonghu[i-
第4頁,一共17頁
I].card_password))
printf("輸入信息有反復!請從新輸入\n”);
prinlf("請輸入第%11位用戶的信息:\n”,i+I);
prinlf("銀行卡號暗碼用戶名卡內金額\n”);
scanf("%d%d%s%f',&yonghu[i].card_number,&yonghu[i].caiii_passvvord,yonghu[i].name,&yonghu[i].money);
)
)
if(i==2)
(
while((yonghu[i].card_nuniber==yonghu[i-l].card_number)||(yonghu[i].card_password==yonghu[i-
1].card_pass\vord)||(yonghuli].card_nuniber==yonghu[i-2J.card_number)||(yonghu[i].card_password==yonghu[i-
2].card_password))
{
prinlf(“輸入信息有反復!請從新輸入\n");
printfC請輸入第%€1位用戶的信息:\n”,i十1);
printf("銀行卡號暗碼用戶名卡內金額\n”);
scanf("%d%d%s%f',&yonghL[i].card_numbcr,&yonghu[i].card_password,yonghu[i].namc,&yonghu[i].money);
)
)
fprintf(fp."%d%d%s%r,yonghu[i].card_number,yonghu[il.card_password.yonghu[.yonghu[il.money);
putc('\n\fp);
)
)
fclose(fp);
第5頁,一共17頁
printf("\n\n請登錄體系\n");/*登錄體系,輸入卡號和暗碼*/
printf("請輸入您的銀行卡號:\n”);
scanf("%d",&number);
printf("請輸入您的暗碼:\n");
scanf("%d",&password);
fp=fopen("clients.txt","r+");
for(i=0;i<N;i++)
{
fscanf(fp,"%d%d%s%r',&yonghu[i].card_number,&yonghu[il.card_password,yonghu[i].nanie,&yonghu[i].mon
ey);
)
fclose(fp);
for(i=0;i<N;i++)/*斷定卡號及暗碼是否匹配*/
{
if((number!=yonghulOJ.card_number)&&(number!=yonghu[I].card_number)&&(number!=yonghu[2].car
(J_iiuinbci))
{
if((timesl-l)!=O)
(
printf("該用戶不消失!您還有%d次嘗試機遇\n\timesl」);
printR"請輸入您的銀行卡號:\n");
scanf("%d'\&number);
printf("請輸入您的暗碼:\n”);
scanf("%d'\&password);
i=-l;
第6頁,一共17頁
else
printf("嘗試掉敗!請按隨意率性鍵退出:\n”);
exit(O);
)
times1-;
)
else
{
if(nuniber==yonghu[i].card_number)
(
if(password==yonghuli].card_password)
(
printf("%s登陸成功!請持續(xù)您的操作\n”,yonghu[i].namc);
j=i;
i=5;/*登陸成功,退出輪回*,
)
else
{
if((times2-l)!=0)
{
printf("暗碼輸入錯誤!您還有%d次嘗試機遇\n",times2-1);
printf(“請輸入您的暗碼
scanf("%d",&password);
第7頁,一共17頁
else
printf(“嘗試掉敗!請按隨意率性鍵退出:\n");
exit(O);
)
times2";
fuction(yonghu(j].money,j);
}
voidfuction(floatk)
(
floatsaved_money,fetched_inoney,payment;
in(phone_num,x.old_password,rew_password;
while(l)
{
pnnU(”I.存款.\n2.取款.\n3.允話費.\n4.修正暗碼.\n5.顯示菜單.\nO.退出體系.\n");
scanf("%d'\&x);
switch(x)
{
case0:
第8頁,一共17頁
printf("退出體系!");
exit(O);
case1:
prinlf("卡內金額:
printf(”請輸入存款金額:\n");
scanf("%f'.&saved_money);
while(saved_money<0)
{
printf(“輸入有誤!請從新輸入!\n");
printfC請輸入存款金額:\n”);
scanf("%f'.&saved_money);
)
m+=savcd_moncy;
prinlfC操作成功!卡內余額為:
yonghufk].money=m;
fp=fopcn("clicnts.txt",,'w+");
for(i=0;i<N;i++)
(
fprintf(fp/'%d%d%s%f,,yonghu[i].caid_number,yonghu[il.card_password.yonghu[,yonghufi].money);
putc('\n\fp);
)
fclose(fp);
break;
case2:
prinlf("卡內金額:%f\n",m);
第9頁,一共17頁
printf("請輸入取款金額:\n");
scanf("%f',&fetched_money);
m-=fctchcd_moncy;
while((fetched_money<0)||(m<0))
(
printf("輸入有誤!請從新輸入!\n");
m+=fetched_money;
printff請輸入取款金額:\n");
scanf("%f',&fetched_money);
m-=fetched_money;
)
prinlf("操作成功!卡內余額為:
yonghu|k].money=m;
fp=fopenCclients.txt",,^4-");
for(i=0;i<N;i++)
{
fprintf(fp."%d%d%s%f',yonghu[i].card_number,yonghu[i].card_password.yonghu[i].name.yonghu[i].money);
putc('\n'.fp);
)
fclose(fp);
break;
case3:
printf("卡內金額:
printf("請輸入德律風號碼:\n");
scanf("%d",&phone_nuni);
第10頁,一共17頁
prinlf(“請輸入所交話費金額:\n”);
scanf("%f',&payment);
m-=payment;
while((payment<())||(m<0))
(
printf("輸入有誤!請從新輸入!\n");
m+=payment;
printf(”請輸入所交話費金額:\n”);
scanf("%f',&payment);
m-=payment;
)
prinlf("操作成功!卡內余額為:
yonghu|k].money=m;
fp=fopenCclients.txt",,^4-");
for(i=0;i<N;i++)
{
fprintf(fp."%d%d%s%f,,yonghu[i].card_number,yonghu[i].card_password.yonghu[.yonghu[il.money);
putc('\n'.fp);
)
fclose(fp);
break;
case4:
while(l)
(
printf("請輸入原暗碼:\n");
第11頁,一共17頁
scanf("%d",&old_password);
if(old_password==yonghu[k].card_password)
{
printf("請輸入新暗碼:\n");
scanf("%d".&new_password);
printf("暗碼修正成功!\n”);
yonghu[k].card_password=new_password;
fp=fopenCclients.txt","w+");
for(i=0;i<N;i++)
{
fprin(f(fp,"%d%d%s%r,yongriu[i].card_number,yonghu[i].card_password,yonghu[i].name,yonghu[i].money);
putc('\n'.fp);
)
fclosc(fp);
break;
)
else
prinif("暗碼輸入錯誤!\n");
)
break;
case5:
break;
default:
printf("輸入有誤!請從新輸入!\n");
break;
第12頁,一共17頁
三.試驗進程與成果剖析
1.現象:輸入用戶信息后,在登錄體系時,輸入第一個用戶的信息,提醒該用戶不消失
解決辦法:
fp=fopenCclients.txt","r+,');
for(i=0;i<N;i++)
{
fscanf(fp,"%d%d%s%f',&yonghu[i].card_number,&yonghu[i].card_password,yonghu[i].name,&yonghu[i]
.money);
)
fclose(fp);
2.現象:登錄體系時,輸入卡號或暗碼超過3次錯誤后,仍能輸入
解決辦法:
增長變量times1=3(卡號輸入錯誤的次數),times2=3(暗碼輸入錯誤的次數),當times-1>0時,提醒
殘剩嘗試機遇,當times-1=()時,退出程序
3.現象:存取款或充話費時,輸入負數仍能運行
解決辦法:
增長輪回:
while(saved_money<0)
(
printf("輸入有誤!請從新輸入!\n”);
printf(“請輸入存款金額:\n”);
第13頁,一共17頁
scanf("%「',&saved_money);
while((fetched_money<0)||(m<0))
(
printf("輸入有誤!請從新輸入!\n”);
m+=fetched_money;
prinlf(”請輸入取款金額:\n");
scanf("%f",&fetched_money);
m-=fetched_money;
}
while((payment<0)||(m<0))
{
prinlf("輸入有誤!請從新輸入!\n");
m+=payment;
printf("請輸入所交話費金額:\n");
scanf("%f,,&payment);
m-=payment;
}
四.試驗成果總結
第14頁,一共17頁
*C:\Progra>Files\licrosoftVisualStudio\lyProjects\b\Debug\b.exe*-口區(qū)
困戶文,
的信息:
限行卡密碼用戶名卡內金額
201122442244lirunze9999
常購入靠2位用戶的信息:
假行卡高密碼用戶名卡內金額
201122452245poi8888
晴項i人等3位用戶的信息:
k哈卡再密碼用戶名卡內金額
201122462246qwe7777
請登錄系統(tǒng)
情輸入您的銀行卡號:
20112244
請輸入您的密碼:
1irunze登陸成功?請繼續(xù)您的操作
1存蔓
2?
斡
筆?
3費
改
修
?
4密
一
顯
亶
5菜
畬
退
統(tǒng)
系
V金額:9999.000000
Si入存款金額:
:成功?卡內余額為:10000.000000
%.修改密伸.
由系統(tǒng).
2
|卡內金額:10000.000000
晴輸入取款金額:
1000
操隹成功?卡內余額為:9000.000000
(2.取款.
F.充話費.
4.修改密碼.
顯示節(jié)L.
第15頁,一共17頁
\Progra>Files\licrosoftVisualStudio\lyProjects\b\Debug\b.exe*-力|
范
話費
?
宓
改
修
亶
黑
一
4.顯
木
5.統(tǒng)
蠶
退
B3.系
卡
覲
&金
請
以
入
12
請789
34所
輸56
入
10。
操
功卡
內余
額為
雪成?
?8900.000000
遷
a..鬢.
B.
改
B.修
?
一
4.顯
黑
5.亶
蠶
退
素
統(tǒng)
22輸
請
成功
修
11改
20碼
密
心
1存
勃?
鬢
2球.
費
遷
3修
一
密
4改
顯
亶
菜
5一
退
統(tǒng)
系
0蠶
5
存
?
1.冬
?
23.話費
修
?
改
4密
顯
鱉
一
5菜
退
統(tǒng)
畬
0
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 第一單元第2課+物聯(lián)網終端設備+課件+2025-2026學年清華大學版B版初中信息科技八年級上冊
- 《GB-T 39561.7-2020數控裝備互聯(lián)互通及互操作 第7部分:工業(yè)機器人測試與評價》專題研究報告
- 《GBT 21870-2008天然膠乳醫(yī)用手套水抽提蛋白質的測定 改進Lowry法》專題研究報告
- 道路交通安全演講課件
- 2026年海南三亞市高職單招英語考試題庫(附含答案)
- 重陽節(jié)文化活動方案
- 道口安全教育培訓計劃課件
- 2023美國胸外科醫(yī)師學會心房顫動外科治療指南解讀課件
- 三年(2023-2025)湖北中考英語真題分類匯編:專題01 完形填空(解析版)
- 邊檢站消防安全培訓總結課件
- 頂管施工技術培訓
- 《JJG 1081.2-2024鐵路機車車輛輪徑量具檢定規(guī)程第2部分:輪徑測量器》 解讀
- YY/T 1488-2025中醫(yī)器械舌象信息采集設備
- 2024人教版八年級生物上冊全冊教案
- 2025年春新人教版英語七年級下冊全冊教學課件
- 2025年上海城投集團社會招聘模擬試卷附答案詳解(黃金題型)
- 供電公司一把手講安全課
- 解讀手術室護理實踐指南
- 管道焊接工藝規(guī)程
- 2026屆遼寧省沈陽134中學化學九上期末調研試題含解析
- 自來水公司安全培訓課件
評論
0/150
提交評論