本文目录一览:
- 1、怎样编写 c语言 银行账户信息管理系统
- 2、C语言设计银行账户模拟程序
- 3、编写一个C语言程序模拟银行ATM机的账户管理功能,系统主要实现以下功能
- 4、c语言银行程序
- 5、有关银行贷款还贷的c语言程序
- 6、c语言 银行贷款的月利率 简单代码
怎样编写 c语言 银行账户信息管理系统
参考如下:
#include conio.h
#include string.h
#include stdio.h
#include stdlib.h
char cFile[] = "date.txt";
struct bank
{
char id[10+1];
char psw[6+1];
double money;
};
welcome1()
{
printf("\n\n\t\t欢迎使用虚拟银行自动取款机服务!\t\t\n\n");
printf("请选择功能:\n");
printf("\n=================================================\n");
printf(" || 请输入序号 ||\n");
printf(" || 1.新用户开户。 ||\n");
printf(" || 2.老用户登陆。 ||\n");
printf(" || 3.退出系统。 ||\n");
printf("=================================================\n");
}
welcome2()
{
printf("\n\n\t\t注册须知\n\n");
printf("**************************************************\n");
printf("* 1.请填写您的真实资料! *\n");
printf("* 2.开户首期必须存入100元以上 *\n");
printf("**************************************************\n");
}
welcome3()
{
printf("\n\n\t\t\3 欢迎进入虚拟银行系统 \3\n\n");
printf("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
printf("\1\1\t 请选择功能:1.取款(最多透资2000); \1\1\n");
printf("\1\1\t 2.存款; \1\1\n");
printf("\1\1\t 3.查询余额; \1\1\n");
printf("\1\1\t 4.修改密码; \1\1\n");
printf("\1\1\t 5.返回主页面; \1\1\n");
printf("\1\1\t 任意键退出. \1\1\n");
printf("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
}
int search(char* user, char* pwd, char* real_pwd)/*判断帐号是否相同,不相同返回1*/
{
FILE* file;
char user_buff[256], pwd_buff[256];
file = fopen(cFile, "r");
if (!file) return 0;
while (!feof(file))
{
if (fscanf(file, "%s%s\n", user_buff, pwd_buff) == EOF) return 0;
if (!strcmp(user_buff, user))
{
if (real_pwd) strcpy(real_pwd, pwd_buff);
return 1;
}
}
fclose(file);
return 0;
}
int add(char* user, char* pwd, double coin_n)
{
FILE* file;
file = fopen(cFile, "a");
if (!file) return 0;
fprintf(file, "%s %s %.2lf\n", user, pwd, coin_n);
fclose(file);
return 0;
}
int wenjian(char* user, char* pwd,double coin)
{
if (search(user, pwd, NULL)) return 0;
else add(user, pwd, coin);
return 1;
}
zhuce()/*注册*/
{
struct bank *p;
int i=0,k=0,judge1,judge2;
char name[30];
char sex,ch;
char sh[18];
int n;
p=(struct bank*)malloc(sizeof(struct bank));/*给p分配内存*/
welcome2();
printf("请输入您的名字(纯英文):");
gets(name);
printf("请输入您的性别(男:1 女2):");
fflush(stdin);
scanf("%c",sex);
fflush(stdin);
printf("请输入您的身份证号码:");
gets(sh);
for(n=0;nstrlen(name);n++)/*判断输入信息是否正确*/
{
if(name[n]='0'name[n]='9')
{
printf("您输入的名字有误!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
if(sex!='1'sex!='2')/*判断输入信息是否正确*/
{
printf("您输入的性别不对!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
if(strlen(sh)!=18)/*判断输入信息是否正确*/
{
printf("您输入的身份证号码不全!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
for(n=0;nstrlen(sh)-1;n++)/*判断输入信息是否正确*/
{
if(sh[n]48||sh[n]57)
{
printf("您输入的身份证号码非法!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
else
{
if(sh[18]!='x'sh[18]48sh[18]57)
{
printf("您输入的身份证号码非法!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
}
printf("请输入您的帐号(10位纯数字):\n");
fflush(stdin);
scanf("%s",p-id);
fflush(stdin);
while(i strlen(p-id))
{
if((p-id[i] 48) || (p-id[i] 57))
{
judge1=0;
}
i++;
}
while(strlen(p-id)!=10 ||judge1==0)/*判断帐号的正确性*/
{
printf("您输入的帐号不正确,必须为10位纯数字!");
printf("请重新输入(10位纯数字):");
fflush(stdin);
scanf("%s",p-id);
fflush(stdin);
}
printf("请输入您的密码(6位纯数字):\n");
fflush(stdin);
scanf("%s",p-psw);
fflush(stdin);
while(k strlen(p-psw))
{
if((p-psw[k] 48) || (p-psw[k] 57))
{
judge2=0;
}
k++;
}
while(strlen(p-psw)!=6 ||judge2==0)/*判断密码形式的正确性*/
{
printf("您输入不正确!密码必须为6位纯数字!\n");
printf("请重新输入密码(6位纯数字):");
fflush(stdin);
scanf("%s",p-psw);
fflush(stdin);
}
printf("请输入您的首期存款:");
fflush(stdin);
scanf("%lf",p-money);
fflush(stdin);
while((p-money)100)
{
printf("您必须存入100元以上,请重新输入:");
fflush(stdin);
scanf("%lf",p-money);
fflush(stdin);
}
if (wenjian(p-id,p-psw,p-money))/*存入文件并输出基本信息*/
{
system("cls");
printf("注册成功!");
printf("您的注册信息如下,请牢记:\n");
printf("名字:");
puts(name);
printf("性别代码:%c\n",sex);
printf("身份证号码:");
puts(sh);
printf("帐号:");
puts(p-id);
printf("密码:");
puts(p-psw);
printf("您帐户里的余额为:%.2lf\n",p-money);
printf("请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
else/*如有相同帐号,注册失败*/
{
system("cls");
printf("您输入的帐号已经存在!注册失败!\n");
printf("请选择:按1返回主页面. 按任意键退出:");
scanf("%c",ch);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
gongneng(char Account[10+1],char Password[6+1],double Money)/*登陆成功后的功能界面*/
{
FILE *ps;
struct bank xin[1000];
int k=0,b=0;
char mima[6+1],Chiose,x;
char count[10+1],word[6+1];
double inmoney,outmoney,addmoney;
welcome3();
fflush(stdin);
scanf("%c",Chiose);
fflush(stdin);
ps=fopen(cFile,"r");
if (!ps)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",x);
fflush(stdin);
exit(0);
}
if(Chiose=='1')
{
printf("输入您的取款金额:");
fflush(stdin);
scanf("%lf",outmoney);
fflush(stdin);
while(!feof(ps))
{
fscanf(ps, "%s %s %lf",xin[k].id,xin[k].psw,xin[k].money);
k++;
}
fclose(ps);
ps=fopen(cFile,"wb");
if (!ps)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",x);
fflush(stdin);
exit(0);
}
while(!feof(ps))
{
//printf("%s %s %.2lf\n",xin[b].id,xin[b].psw,xin[b].money);
if ((strcmp(Account, xin[b].id)==0)(strcmp(Password, xin[b].psw)==0))
{
xin[b].money=xin[b].money-outmoney;
}
printf("%.2lf\n",xin[b].money);
fprintf(ps, "%s %s %.2lf\n", xin[b].id, xin[b].psw, xin[b].money);
b++;
}
}
}
denglu()/*登陆*/
{
FILE *fp;
char account[10+ 1],password[6 + 1],h;
int m=0;
char real_account[10+ 1]; /* 帐号缓存 */
char real_password[6 + 1]; /* 密码缓存*/
double real_money_o=0.0; /*存款缓存*/
printf("请输入您的帐号(10位纯数字):");
gets(account);
printf("请输入您的密码(6位纯数字):");
gets(password);
fp = fopen(cFile, "r");
if (!fp)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",h);
fflush(stdin);
exit(0);
}
while (m=2) /*判断是否输入错3次了*/
{
while(fscanf(fp, "%s %s %lf", real_account, real_password,real_money_o) != EOF) /*循环判断帐号密码*/
{
if ((strcmp(real_account, account)==0)(strcmp(real_password, password)==0))
{
system("cls");
printf("登陆成功!");
gongneng(real_account,real_password,real_money_o);
fclose(fp);
return 0;
}
}
rewind(fp); /*重新打开文件,进行新一轮的密码验证*/
printf("您输入的帐号不存在或密码不正确!\n请重新输入:\n");
m++;
printf("请输入您的帐号(10位纯数字):");
fflush(stdin);
gets(account);
fflush(stdin);
printf("请输入您的密码(6位纯数字):");
fflush(stdin);
gets(password);
fflush(stdin);
}
fclose(fp);
printf("您输入帐号密码不正确已经3次,您被强制退出系统(按任意键退出)!");
fflush(stdin);
scanf("%c",h);
fflush(stdin);
exit(0);
}
int main()
{
char chiose;
welcome1();
scanf("%c",chiose);
getchar();
if(chiose ='0' ||chiose='4')
{
while(chiose ='0' || chiose='4')
{
printf("您的输入有误,请重新输入:");
scanf("%c",chiose);
getchar();
}
}
if(chiose=='1')
{
system("cls");
zhuce();/*注册*/
}
if(chiose=='2')
{
system("cls");
denglu();/*登陆*/
}
if(chiose=='3')
{
printf("谢谢您的使用!");
exit(0);
}
}
C语言设计银行账户模拟程序
能传附件吗?不知道怎么传。我就贴给你吧。
#includeiostream
#includestring
#includefstream
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;
cincn;
ifstream infile("atm.txt",ios::binary);
infile.seekg(0,ios::beg);
for(int i=0;i5;i++)
{
infile.read((char *)(a[i]),sizeof(a[i]));
}
for(int j=0;j5;j++)
{
if(cn==a[i].CardNum)
{
cout"please enter the amount of money"endl;
cinm;
while(mac-Balance)
{
cout"there is no enough money in your account,please enter again"endl;
cinm;
}
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语言程序模拟银行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;iASN;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;iASN;i++)
if(strcmp(an,ats[i].accountnumber)==0)
return ats[i].balance;
}
void deposit(char *an,int amount)
{
int i;
for(i=0;iASN;i++)
if(strcmp(an,ats[i].accountnumber)==0)
ats[i].balance+=amount;
}
int withdraw(char *an,int amount)
{
int i;
for(i=0;iASN;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;i8;i++)
AccountNumber[i]=getch();
printf("\n请输入6为密码:");
for(i=0;i6;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语言银行程序
#includemath.h
#includestdio.h
main(){
int a,c,d,e;
float b=10000;
int f;
int num=1;
printf("\t\t\t CHNIA BANK ATM\nplease input your secret code:\n");
scanf("%d",a);
if(a==num){
printf(" welcome you to use your count,you have %.2f RMB!\n",b);
printf(" how much money do you want? please input the numbers: ");
scanf("%d",e);
printf("\n");
c=b-e;
printf(" you till have : %d ,please choose exit or choose function ! \n",c);
scanf("%c",d);
printf("\n");
}
else if(a!=num){
printf("your secret code is wrong,please input the correct secret code!\n");
}
printf("\t\t \tHELLO,WELCOME TO USE ATM\nplease choose you want function\n");
printf("\n\n");
printf("\t\t-----------------------------------\n");
printf("\t\t|\t\t|\t\t |\n");
printf("\t\t| 1. check\t| 2. withdraw money\t |\n");
printf("\t\t|\t\t|\t\t |\n");
printf("\t\t-----------------------------------\n");
printf("\t\t|\t\t|\t\t |\n");
printf("\t\t| 3. transfer account\t| 4. midify secret code|\n");
printf("\t\t|\t\t|\t\t |\n");
printf("\t\t-----------------------------------\n");
printf("\t\t|\t\t\t\t |\n");
printf("\t\t|\t 0. exit \t\t |\n");
printf("\t\t|\t\t\t\t |\n");
printf("\t\t-----------------------------------\n");
printf("please choose function:\n ");
scanf("%d",f);
switch(f)
{ case 0:printf("exit");break;
case 1:printf("check");break;
case 2:printf("withdraw money");break;
case 3:printf("transfer account");break;
case 4:printf("midify secret code");break;
default :printf("it's wrong,please choose in 0~4!");
}
getch();
}
有关银行贷款还贷的c语言程序
你的错误实在太多了。看代码王的程序简洁易懂
#includestdio.h
#includemath.h
int main()
{
double z,k,x,monthPay,allMoney,temp=0;
int n,i;
printf("输入借款总额、贷款年限、年利率: ");
//贷款总和最好不要用int型的,int的最大值是32767,那你岂不是超了
scanf("%lf%d%lf",z,n,k);
//计算n年后要还的总的钱数 pow(x,y)是在头文件math.h中的函数计算x^y
allMoney = z*pow((1+k/12),12*n);
//式子∑x(1+k/12)^i (i=0,1,2,..,n*12-1)将x提出到前面计算 temp=∑(1+k/12)^i
for(i=0; i12*n; i++)
temp += pow((1+k/12),i);
//根据等式z(1+k/12)^(12*n) = ∑x(1+k/12)^i (i=0,1,2,..,n*12-1) 得x=allMoney/temp;
x = allMoney/temp;
printf("每月应还款:%lf", x);
}
c语言 银行贷款的月利率 简单代码
#include stdio.h
#includemath.h
main()
{
double money,capital;
double rate[4]={0.009,0.01,0.0111,0.012};
int n;
printf("请输入本金和期限(年)\n");
scanf("%lf%d",capital,n);
if(n3)
money=capital*pow((1+rate[3]),12*n);
else
money=capital*pow((1+rate[n-1]),12*n);
printf("%d年后本金和利息合计为:%.2lf\n",n,money);
}