當前位置:首頁 » 編程語言 » c語言模擬銀行存款的程序
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言模擬銀行存款的程序

發布時間: 2022-06-08 14:03:50

『壹』 銀行存款方案比較的c語言程序編寫

代碼:
#include<stdio.h>
char c='y';
float money;
char key[6];//定義了三個全局變數,用來存儲文件中的余額和密碼。
void check()//查詢余額
{
char a;
printf("%f",money);
printf("按任意鍵返回主菜單\n");
a=getch();
}

void draw()//取款
{
int a;
printf("1.取50元\n2.取100元\n3.取200元\n4.取500元\n5.按任意鍵返回\n");
scanf("%d",&a);
switch(a)
{
case 1:
money=money-50;printf("取款成功");break;
case 2:
money=money-100;printf("取款成功");break;
case 3:
money=money-200;printf("取款成功");break;
case 4:
money=money-500;printf("取款成功");break;
case 5:
c='y';break;
}
}

void changekey()//修改密碼
{
char a[6],d[6],b='y';int j;
for(;b=='y';)
{
printf("請輸入一個六位數的新密碼");
gets(a);puts(a);
printf("請再次輸入");
gets(d);puts(d);
for(j=0;j<6;j++)
{
if(a[j]!=d[j])break;
}

if(j<6) printf("兩次輸入的密碼不相同,請重新輸入\n");
else
{
for(j=0;j<6;j++)
{
key[j]=a[j];
}
printf("修改密碼成功,按任意鍵返回主菜單\n");
b=getch();b='n';
}
}
}

main()
{
int a,j,d=0;char b[6],e;
FILE *fp;
if((fp=fopen("message.txt","rb"))==NULL)
printf("message error\n");
fread(&money,4,1,fp);
for(j=0;j<6;j++)
fread(&key[j],1,1,fp);
fclose(fp);
for(j=0;j<6;j++)
{
key[j]='8';
}
money=100000;
printf("歡迎使用模擬ATM系統\n");
for(;c='y';)
{
printf("請輸入密碼\n");
gets(b);puts(b);
for(j=0;j<6;j++)
{
if(b[j]!=key[j])
{
printf("密碼輸入錯誤,請重新輸入\n");
d++;break;
}
}
if(j>=6)break;
if(d>=3)
{
printf("密碼三次輸入錯誤!系統即將自動退出\n");
c='n';break;
}
}
for(;c=='y';)
{
printf("\n");
printf("請選擇你需要的服務,如余額查詢請輸入1\n");
printf("1.余額查詢\n");
printf("2.取款\n");
printf("3.修改密碼\n");
printf("4.退出\n");
scanf("%d",&a);e=getchar();
switch(a)
{
case 1:
check(money);break;
case 2:
draw();break;
case 3:
changekey();break;
case 4:
c='n';printf("謝謝您的使用\n");break;
}
}
if((fp=fopen("message.txt","wb"))==NULL)
{
printf("cannot open file\n");
}
if(fwrite(&money,4,1,fp)!=1)
printf("file write error\n");
for(j=0;j<6;j++)
{
if(fwrite(&key[j],1,1,fp)!=1)
printf("file write error\n");
}
fclose(fp);
}
經測試通過。
請自行在這個文件的相同目錄下新建一個文本文檔,命名為message,並將下面冒號後面的代碼全部復制過去(如果不行,請補充,最好給個郵箱,我把代碼和文件都發過去,省事): P肎888888

『貳』 C程序設計 模擬銀行自動存取款機

模擬自動存取款機功能編寫一個小型程序,至少具備4個功能模塊:
1. 余額查詢 2修改密碼 3提款 4存款
卡號、密碼、余額是三個必須的數據。
1. 程式會先顯示歡迎訊息 ,歡迎界面,比如「開戶成功,歡迎使用**銀行自動取款機服務」;
2. 接著要求使用者輸入帳號
3. 再要求使用者入密碼
4. 如果三次嘗試都錯誤的話就中止程式 否則就是登入成功
登入後, 你的」主畫面」會顯示出五種功能選項:
1餘額查詢 2修改密碼 3提款 4存款 5退出

1.第一步列印出:「請輸入你的帳號和密碼」。然後你從鍵盤分別輸入六位數的帳號和密碼。如果正確進入第二步.
第二步:請修改初始密碼。
你的程序列印:「請輸入你的新密碼:」然後你從鍵盤輸入六位數密碼。此時你的程序列印:「請再輸入一遍新密碼。」如果兩次輸入的密碼不一致,則你的程序列印:「你兩次輸入的密碼不一致,修改密碼未成功,請再輸入一次。」在main()里定義(四個數組,其中兩個用來存放你輸入的六位數帳號和密碼,另兩個數組存放你的六位數帳號和密碼,)注意你定義的數組應該能存放七個字元。比較你輸入的密碼和數組中的密碼是否一致,如果不一致,則列印出:「密碼錯誤,請再試一次。

2. 檢視帳戶余額: 顯示該帳戶的余額 , 然後再回到主畫面.
3. 提款 : 當使用者選擇提款時,畫面應該進入提款畫面,你應該提供六個選項讓使用者選擇: 1. 100, 2. 500, 3. 1000, 4. 2000, 5. 3000, 6. 取消交易 . 選擇1-5的選項後,你應該顯示出使用者領用了多少錢,存款剩多少,然後回到」主畫面」. 記住: 你要確認使用者的存款是否有足夠的錢可以提領! 如果使用者選擇取消交易,則系統會回到」主畫面」. 選擇「取錢」的功能按鍵,輸入要取出的錢數,進行取錢操作,操作完畢需要「取錢成功,您的當前余額為。。。」的提示信息
4. 存款 :當使用者選擇存款時,畫面應該進入存款畫面,你應該提供六個選項讓使用者選擇: 1. 100, 2. 500, 3. 1000, 4. 2000, 5. 3000, 6. 取消交易 . 選擇1-5的選項後,你應該顯示出使用者存入了多少錢,存款變成多少,然後回到」主畫面」. 選擇「存錢」的功能按鍵,輸入存儲的錢數,進行存錢操作,操作完畢需要「存錢成功,您的當前余額為。。。」的提示信息
5.在「存錢」、「取錢」、「查看余額」等每項操作結束後,需要有「繼續其他操作還是退出」的選項,如果選擇「繼續其他操作」,那麼重新進入「按鍵使用功能說明」界面,如果選擇「退出」則轉到功能9;
6、 退出程序功能(按某個功能鍵可以退出本程序,並列印友好提示信息「本次服務結束,歡迎再次光臨**銀行」);
問題補充:要求採用C語言,謝絕C++~~簡潔明了者可加高分

『叄』 C語言小程序.寫一個關於銀行存取錢的

代碼如下:

#include<stdlib.h>
#include<stdio.h>

intmain()
{
floatbalance;//余額
floatwithdraw;//取款
floatsave;//存款
charchoice;//用戶選擇鍵

printf("請輸入存款余額(包含兩位小數): ");
scanf("%f",&balance);
do{
printf("請選擇:D(存款);W(取款);F(結束). ");
fflush(stdin);
choice=getchar();
switch(choice)
{
case'D':
case'd':
scanf("%f",&withdraw);
balance+=withdraw;
break;
case'W':
case'w':
scanf("%f",&save);
balance-=save;
if(balance<=0.0)balance=0.0;
break;
case'F':
case'f':
printf("當前余額為:%.2f ",balance);
system("pause");
return0;
default:
break;
}
}while(true);
}

『肆』 用C語言編寫一個自動存取款機模擬

給你個加強版:include<iostream.h>
#include<stdlib.h>
#include<string.h>
struct Bank
{
char name[6],num[8],password[6];
double money,o;
}b,q;
void tuichu();
void fuction();
void cunqian();
void queren();
void cin1()
{
b.money=0;
cin>>b.name;
cout<<"請輸入您的卡號:"<<endl;
cin>>b.num;
cout<<"請輸入您的密碼:"<<endl;
cin>>b.password;
cout<<endl;
}
void error()
{
cout<<"您的輸入錯誤,請再輸入一遍!"<<endl;
}
void cout1()
{
cout<<"您的名字是:"<<b.name<<endl<<"您的卡號是:"<<b.num<<endl<<"您的密碼是:"<<b.password<<endl;
}
void one()
{
cout<<"請按『1』存錢, 請按『2』取錢!"<<endl<<"請按『3』查錢, 請按『4』退出!" <<endl;
}
void tishi()
{
char c;
cout<<"如果您想退出,請按 'Y' . 否則,請按'N' !";
cin>>c;
if(c=='y'||c=='Y') tuichu();
if(c=='n'||c=='Y') fuction();
else
{
error();
tishi();
};
}
void yue()
{
cout<<"您的余額為:"<<b.money<<endl;
tishi();
}
void cunqian()
{
b.o=b.money;
cout<<"您想存多少錢?"<<endl;
cin>>b.money;
if((b.money<'0')&&(b.money>'9'))
{
cout<<"請輸入數字!"<<endl;
cunqian();
}
if((b.money<=999999999)&&(b.money>=(-999999999)))
{
b.money+=b.o;
yue();
}
else
{
error();
cunqian();
b.money=0;
}
}
void quqian()
{
double d;
cout<<"您想取多少錢?"<<endl;
cin>>d;
if((d<999999999)&&(d>=0)&&(d<=b.money+2000))
{
b.money-=d;
yue();
}
else
{
cout<<"您的透支余額超過2000元,操作失敗!"<<endl;
quqian();
}
}
void chaqian()
{
yue();
}
void tuichu()
{
cout<<endl<<"歡迎下次光臨歡迎進入C++工商銀行!!"<<endl;
cout<<"請取回您的卡,再次感謝!"<<endl;
exit(0);
}
void fuction()
{
char x;
{
one();
cin>>x;
switch(x)
{
case '1': cunqian();break;
case '2': quqian();break;
case '3': chaqian();break;
case '4': tuichu();break;
default: cout<<"您的輸入錯誤,請輸入1到4按鍵,謝謝!"<<endl;fuction();
}
}
}
void cin2()
{
cout<<"請輸入您的卡號:"<<endl;
cin>>q.num;
cout<<"請輸入您的密碼:"<<endl;
cin>>q.password;
cout<<endl;
}
void cout2()
{
cout<<"歡迎進入C++工商銀行!"<<endl<<"請您先開戶,謝謝!"<<endl<<"請輸入您的名字:"<<endl;
cin1();
cout1();
queren();
}
void queren()
{
cout<<"請再次確認您的信息:"<<endl;
int e,f;
cin2();
e=strcmp(q.num,b.num);
f=strcmp(q.password,b.password);
if (e==0&&f==0) fuction();
else {
cout<<"您的信息有誤,請重新輸入:"<<endl;
cin2();
e=strcmp(q.num,b.num);
f=strcmp(q.password,b.password);
if (e==0&&f==0) fuction();
else
{
cout<<"您的信息有誤,請重新輸入:"<<endl;
cin2();
e=strcmp(q.num,b.num);
f=strcmp(q.password,b.password);
if(e==0&&f==0) fuction();
else {
cout<<"您的信息有誤,請重新輸入:"<<endl;
tuichu();
}
}
}
}
void main()
{
cout2();
}

『伍』 C語言 銀行存儲模擬系統

// t.cpp : Defines the entry point for the console application.//#include "stdafx.h"int Card[100][5+3];void main(){ for(int i=0;i<100;i++) { Card[i][0]=i; Card[i][1]=0; ]==nCahao) { nT=1; nPose=i; break; } } printf("卡號不正確"); } printf("你的存款余額為%d\n",Card[nPose][1]); while(1) { printf("1,取款 2, 存款\n"); int nSelect; scanf("%d",&nSelect); switch(nSelect) { case 1: printf("請輸入提款金額\n"); int nJine; scanf("%d",&nJine); Card[nCahao][Card[nCahao][2]]=-nJine; Card[nCahao][2]=Card[nCahao][2]++; printf("你的取款額為%d請在出鈔口領現金\n",nJine); nJine); printf("請取卡\n"); return; } } }

『陸』 編寫一個C語言程序模擬銀行ATM機的賬戶管理功能,系統主要實現以下功能

按照你的願意把空都填好了,VC++ 6.0下編譯能通過,有警告信息,運行基本上能用,不過個人認為這個系統有很大的不足,比如輸入賬號的時候沒有輸出反饋信息,以及沒有對誤操作的處理等等。需要的話可以幫你改改!

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define AN 9 //表示賬號8位
#define PN 7 //表示密碼6位
#define ASN 3 //表示系統中共有3個賬戶信息
struct Account
{
char accountnumber[AN]; //表示賬號信息
char password[PN]; //表示賬戶的密碼信息
double balance; //表示賬戶的余額
};
struct Account ats[ASN]={{"00000001","123456",100},{"00000002","123456",200},{"00000003","123456",300}};
//ats數組用於存儲系統中三個賬戶的信息
int isCorrect(char *an,char *psd)
{
int i;
for(i=0;i<ASN;i++)
if(strcmp(ats[i].accountnumber,an)==0 && strcmp(psd,ats[i].password)==0)
return 1;
return 0;
}
double getBalance(char *an)
{
int i;
for(i=0;i<ASN;i++)
if(strcmp(an,ats[i].accountnumber)==0)
return ats[i].balance;
}

void deposit(char *an,int amount)
{
int i;
for(i=0;i<ASN;i++)
if(strcmp(an,ats[i].accountnumber)==0)
ats[i].balance+=amount;
}
int withdraw(char *an,int amount)
{
int i;
for(i=0;i<ASN;i++)
if(strcmp(an,ats[i].accountnumber)==0)
return ats[i].balance-=amount;
}

void main()
{
char AccountNumber[AN]={'\0'};
char psd[PN]={'\0'};
int i,errorcount=0;
while(1)
{
printf("\n請輸入8位賬號:");
for(i=0;i<8;i++)
AccountNumber[i]=getch();
printf("\n請輸入6為密碼:");
for(i=0;i<6;i++)
{
psd[i]=getch();
putchar('*');
}
if(isCorrect(AccountNumber,psd)==1)
{
int tag,amount;
while(1)
{
printf("\n歡迎登錄銀行賬戶管理系統,請選擇您要的服務:1、查詢余額;2、存款操作;3、取款操作;4、退出系統\n");
scanf("%d",&tag);
switch(tag)
{
case 1:
printf("您現在的余額為%f元\n",getBalance(AccountNumber));
break;
case 2:
printf("請輸入您的存款金額:");
scanf("%d",&amount);
deposit(AccountNumber,amount);
printf("存款成功!您的當前余額為:%f元\n",getBalance(AccountNumber));
break;
case 3:
printf("請輸入您的取款金額:");
scanf("%d",&amount);
if(amount<=getBalance(AccountNumber))
printf("取款成功!您的當前余額為:%f元\n",withdraw(AccountNumber,amount));
else
printf("取款失敗!\n");
break;
case 4:
break;
}
if(tag==4)
break;
}

}
else
{
errorcount++;
if(errorcount==3)
{
printf("您已經連續三次輸入錯誤,系統將自動關閉\n");
break;
}
}
}
}

『柒』 C語言設計銀行賬戶模擬程序

能傳附件嗎?不知道怎麼傳。我就貼給你吧。
#include<iostream>
#include<string>
#include<fstream>
using namespace std;

class account //atm賬戶類
{
private:
string CardNum,Psw; //卡號、密碼
float Balance;
public:
friend class ATM; //atm為友元
/*void get_cardnum();
void get_psw();
void get_balance();*/
account(){}//<---------------------here
account(string num,string passwd,float balance); //構造函數
void Write();
};

class ATM //atm機類
{
private:
int times;
account *ac;
public:
ATM(); void load( account *act ); //裝入賬戶信息
void welcome(); //初始歡迎信息
bool check_passwd( string pwd ); //驗證當前賬戶信息的密碼
void change_psw(); //修改密碼
void get_money(); //取錢
float check_balance(); //查賬
void tran(); //轉賬
void exit(); //退卡
void function_show(); //顯示功能菜單
void lock(); //鎖定賬戶
};

/*
* account::account( string num, string passwd, float balance )
* account類構造函數
* 用途: 使用給定的賬號密碼等信息初始化一個account對象
* 參數: string num 賬號
* string passwd 密碼
* float balance
*/
account::account( string num, string passwd, float balance )
{
CardNum = num;
Psw = passwd;
Balance = balance;
}
//atm類構造函數
/*account::get_cardnum()
{
return CardNum;
}
account::get_psw()
{
return Psw;
}
account::get_balance()
{
return Balance;
}*/
void account::Write()
{
ofstream outfile("atm.txt",ios::binary);//<-----------------here
outfile.write((char *)(this),sizeof(account));//<-------------here
outfile.close();
}

ATM::ATM()
{
}

/*
* void ATM::load( account *act )
* ATM類裝入賬戶信息函數
* 用途: 載入指定的account對象,模擬atm插卡過程
* 參數: account *act 要載入的account對象指針
*/
void ATM::load( account *act )
{
ac = act;
}

/*
* void ATM::welcome()
* ATM類顯示初始歡迎信息函數
* 用途: 顯示歡迎信息,提示密碼輸入並驗證
* 參數: 無
*
*/
void ATM::welcome()
{
times = 0; //記錄密碼輸入錯誤次數
cout << "Welcome to use the China Bank ATM!" << endl;
string pwd; //這一個語句應該上移的,一般來說數據的定義和初始化一塊寫在開頭,下面才是各種操作的語句
while( times < 3 )
{
cout << "Please enter the password: " << endl;
cin >> pwd;
if( !check_passwd( pwd ) )
{
cout << "The password you entered is wrong, please enter again" << endl;
times++;
}
else
{
function_show();
break;
}
}
if( times >= 3 )
lock(); //輸入密碼錯誤次數超過(等於)3次,鎖定賬戶
}

bool ATM::check_passwd( string pwd )
{
if( pwd == ac->Psw )
return true;
else
return false;
}

void ATM::function_show()
{
int n;
cout << "(1) Change Password" << endl;
cout << "(2) Get Money" << endl;
cout << "(3) Check Balance" << endl;
cout << "(4) Transfer accounts" << endl;
cout << "(5) Exit" << endl;
cin >> n;
while(n != 1 && n != 2 && n != 3 && n != 4 && n != 5) //這樣就可以完全限制用戶的輸入
{
cout << "Please enter the right number" << endl;
cin >> n;
}
switch( n )
{
case 1:
change_psw();
break;
case 2:
get_money();
break;
case 3:
cout << check_balance() << endl;
break;
case 4:
tran();
break;
case 5:
exit();
break;

}
}

void ATM::lock()
{
cout << "Sorry! Your card has been confiscated!" << endl;
exit();
}

void ATM::change_psw()
{
string old_psw, new_psw1, new_psw2;
int t = 0 ;
while( t < 3 )
{
cout << "Please enter the old password: ";
cin >> old_psw;
if( !check_passwd( old_psw ) )
{
cout << "The password you enter is wrong, please enter again" << endl;
t++;
}
else
{
cout << "Please enter the new password: ";
cin >> new_psw1;
cout << "Please enter the new password again: ";
cin >> new_psw2;
if( new_psw1 == new_psw2 )
{
ac -> Psw = new_psw2;
cout << "You have change your password successfully!" << endl;
break;
}
else
cout << "Sorry, entered passwords do not match! " << endl;
}
}
//}//<----------------------here
if( t >= 3 )
{
cout << "Sorry, you have inputed the wrong password for three times and more! " << endl;
}
}

void ATM::get_money()
{
float money;
cout << "Please enter the amount of money you want to get: " <<endl;
cin >> money;
while( money > ac -> Balance)
{
cout << "Your balance is not enough, please enter again" << endl;
cin >> money;
}
ac -> Balance = ac -> Balance - money;
}

float ATM::check_balance()
{
return ac -> Balance;
}

void ATM::tran()
{
account a[5];
string cn;
float m;
cout<<"please enter the cardnum of the account you want to transfer money to"<<endl;
cin>>cn;
ifstream infile("atm.txt",ios::binary);
infile.seekg(0,ios::beg);
for(int i=0;i<5;i++)
{
infile.read((char *)(&a[i]),sizeof(a[i]));
}
for(int j=0;j<5;j++)
{
if(cn==a[i].CardNum)
{
cout<<"please enter the amount of money"<<endl;
cin>>m;
while(m>ac->Balance)
{
cout<<"there is no enough money in your account,please enter again"<<endl;
cin>>m;
}
ac->Balance=ac->Balance-m;
a[i].Balance=a[i].Balance+m;
ofstream outfile("atm.txt",ios::binary);
outfile.seekp(i*sizeof(a[0]),ios::beg);
outfile.write((char *) &a[i],sizeof(a[i]));
}
}
if(j>=5)
{
cout<<"the account doesn't exit"<<endl;
}
}

void ATM::exit()
{
cout << "Please take your card!" << endl;
}

int main()
{
account a[5]={account("10001","1111",5000.0f),account("10002","2222",10000.0f),account("10003","3333",15000.0f),
account("10004","4444",20000.0f),account("10005","5555",25000.0f)};
account temp( "10001", "1111", 5000.0f );
ATM atm;
atm.load( &temp );
atm.welcome();
return 0;
}

『捌』 數據結構:銀行業務模擬的C語言程序

像這樣的要求嘛,來網路就錯了,你得上專業網站找高手。還急需的話,就不要繼續在這兒浪費時間了

『玖』 c語言 程序設計 銀行存款

{
i=i+1;
x=x*(1.0+r/100.0); <---每年取整
}

『拾』 用c語言如何寫一個銀行存取款管理設計

功能:能夠輸入和查詢客戶存款取款記錄。在客戶文件中,每個客戶是一條記錄,包括編號、客戶姓名、支取密碼、客戶地址、客戶電話、賬戶總金額;在存取款文件中,每次存取款是一條記錄,包括編號、日期、類別、存取數目、經辦人。類別分為取款和存款兩種。本系統能夠輸入客戶存款或取款記錄;根據客戶姓名查詢存款和取款記錄。分步實施:1、初步完成總體設計,搭好框架,確定人機對話界面,確定函數個數;2、建立一個文件,輸入客戶的必要信息,能對文件進行顯示、輸入、修訂、刪除等。3、進一步要求:完成客戶姓名查詢存款和取款記錄,並能得到每次帳戶總金額。要求:1、用C語言實現系統;2、利用結構體數組實現信息的數據結構設計;3、系統的各個功能模塊要求用函數的形式實現;4、界面友好(良好的人機交互),程序加必要的注釋。課程設計實驗報告要求:1、預習報告:題目、課程設計任務、數據結構、程序的總體設計(演算法)、模塊劃分 。2、實驗總結報告:流程圖、主要源程序代碼(需列印)、測試情況及調試中問題與解決方案、小結等要求:標明所用函數的用途和目的,簡單敘述製作思路。