| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1610 人关注过本帖
标题:求一个银行模拟程序
只看楼主 加入收藏
snipered
Rank: 1
等 级:新手上路
威 望:1
帖 子:90
专家分:0
注 册:2007-10-5
收藏
得分:0 
关键问题是交易的查询!!
我做了n次了,打印不出来!

2007-10-28 01:03
风致
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2007-9-22
收藏
得分:0 

#include<stdio.h> //文件函数头文件
#include<conio.h> //getch(),putch()函数头文件
#include<shlobj.h> //使用MessageBox()函数
#include"person.h" //自定义头文件
#include<time.h> //时间函数

bool bb=true; //是否登录
int n; //记录个数
char name[10]; //姓名
char id[18]; //身份证号
double money; //钱
char age[10]; //年龄
char telephone[13]; //电话
char address[50]; //地址
char password[6]; //密码
person p; //全局变量

void kh() //开户
{
system("cls"); //清屏
cout<<"姓名:"; //输入姓名
cin>>name;
cout<<"身份证号:"; //输入身份证号
cin>>id;
cout<<"开户额:"; //输入开户额
cin>>money;
cout<<"出生日期:"; //输入出生日期
cin>>age;
cout<<"电话:"; //输入电话
cin>>telephone;
cout<<"地址:"; //输入地址
cin>>address;
cout<<"密码:"<<endl; //输入密码
for(int i=0;i<6;i++)
{
password[i]=getch();
putch('*');
}
person p=person(name,id,money,age,telephone,address,password); //构造对象
FILE *f; //文件指针
f=fopen("g:\\a.txt","a+r+w"); //打开文件(读写和追加)
fwrite(&p,sizeof(p),1,f); //输入记录
MessageBox(0,"开户成功","提示",0); //显示开户信息
fclose(f); //关闭文件
}


void checkout() //取款
{
n=0;
system("cls"); //清屏
if(bb) //判断是否登录
{
cout<<"身份证号:"<<endl; //输入身份证号
cin>>id;
cout<<"密码:"<<endl; //密码
for(int i=0;i<6;i++)
{
password[i]=getch();
putch('*');
}
bb=false;
}
FILE *f; //定义文件指针
f=fopen("g://a.txt","r+w"); //打开文件
cout<<endl;
cout<<"请稍等。。。"<<endl;
while(!feof(f))
{
fread(&p,sizeof(person),1,f); //读入纪录
if((!strcmp(p.id,id))&&(!strcmp(p.password,password))) //比较
{
system("cls"); //清屏
cout<<"你的余额为:"<<p.money<<"元"<<endl; //输出信息
cout<<"取款额:"<<endl;
cin>>money;
p.checkout(money);
cout<<"你的余额为"<<p.money<<"元"<<endl;
fseek(f,n*sizeof(person),0);
fwrite(&p,sizeof(person),1,f);
_sleep(1000);
break; //跳出循环
}
else
{
n++; //记录加一
}
}
if(!feof(f))
{
}
else
{
MessageBox(0,"你输入的账号或密码不正确!","提示",0);
bb=true;
}
fclose(f); //关闭文件
}

void checkin()
{
n=0;
system("cls"); //清屏
if(bb)
{
cout<<"身份证号:"<<endl; //输入身份证号
cin>>id;
cout<<"密码:"<<endl; //密码
for(int i=0;i<6;i++)
{
password[i]=getch();
putch('*');
}
bb=false;
}
FILE *f; //定义文件指针
f=fopen("g://a.txt","r+w"); //打开文件
cout<<endl;
cout<<"请稍等...."<<endl;
while(!feof(f))
{
fread(&p,sizeof(person),1,f); //读入纪录
if((!strcmp(p.id,id))&&(!strcmp(p.password,password))) //比较
{
system("cls"); //清屏
cout<<"你的存款为:"<<p.money<<"元"<<endl; //输出信息
cout<<"存款额:"<<endl;
cin>>money;
p.checkin(money);
cout<<"你的存款为"<<p.money<<"元"<<endl;
fseek(f,n*sizeof(person),0); //修改记录
fwrite(&p,sizeof(person),1,f);
_sleep(1000); //停止1秒钟
break; //跳出循环
}
else
{
n++; //记录加一
}
}
if(!feof(f))
{

}
else
{
MessageBox(0,"你输入的账号或密码不正确!","提示",0); //显示错误信息
bb=true;
}
fclose(f); //关闭文件
}

void check()
{
n=0;
system("cls"); //清屏
if(bb)
{
cout<<"身份证号:"<<endl; //输入身份证号
cin>>id;
cout<<"密码:"<<endl; //密码
for(int i=0;i<6;i++)
{
password[i]=getch();
putch('*');
}
bb=false;
}
FILE *f; //定义文件指针
f=fopen("g://a.txt","r+w"); //打开文件
cout<<endl;
cout<<"请稍等。。。"<<endl;
while(!feof(f))
{
fread(&p,sizeof(person),1,f); //读入纪录
if((!strcmp(p.id,id))&&(!strcmp(p.password,password))) //比较
{
system("cls"); //清屏
cout<<"姓名:"<<p.name<<endl; //输出客户信息
cout<<"账号:"<<p.id<<endl;
cout<<"余额:"<<p.money<<endl;
int i=getch();
break; //跳出循环
}
else
{
n++; //记录加一
}
}
if(!feof(f))
{

}
else
{
MessageBox(0,"你输入的账号或密码不正确!","提示",0); //输出错误信息
bb=true;
}
fclose(f); //关闭文件
}

void changpass()
{
system("cls"); //清屏
if(bb)
{
cout<<"身份证号:"<<endl; //输入身份证号
cin>>id;
cout<<"密码:"<<endl; //密码
for(int i=0;i<6;i++)
{
password[i]=getch();
putch('*');
}
bb=false;
}
FILE *f; //定义文件指针
f=fopen("g://a.txt","r+w"); //打开文件
cout<<endl;
cout<<"请稍等....."<<endl;
while(!feof(f))
{
fread(&p,sizeof(person),1,f); //读入纪录
if((!strcmp(p.id,id))&&(!strcmp(p.password,password)))
{
system("cls"); //清屏
p.changepass(); //修改密码
fseek(f,n*sizeof(person),0); //修改记录
fwrite(&p,sizeof(person),1,f);
int i=getch();
break; //跳出循环
}
else
{
n++; //记录加一
} //跳出循环
}
if(!feof(f))
{

}
else
{
MessageBox(0,"你输入的账号或密码不正确!","提示",0); //显示错误信息
bb=true;
}
fclose(f); //关闭文件
}


void main() //主函数
{
MessageBox(0,"欢迎使用此系统","提示",0);
while(1) //主菜单
{
system("cls"); //清屏
system("color 7c"); //屏幕颜色

char c; //菜单选取变量
cout<<"1.开 户"<<endl; //菜单
cout<<"2.取 款"<<endl;
cout<<"3.存 款"<<endl;
cout<<"4.修改密码"<<endl;
cout<<"5.查 询"<<endl;
cout<<"6.退 出"<<endl;
c=getch(); //选取服务种类
switch(c)
{
case '1': //进入开户系统
kh();
break;
case '2': //进入取款系统
checkout();
break;
case '3': //进入存款系统
checkin();
break;
case '4': //进入转帐系统
changpass();
break;
case '5': //进入查询系统
check();
break;
case '6':
exit(1); //退出
}
}
}

#include<iostream.h> //输入输出函数
#include<stdlib.h> //putch(),getch()函数
#include<string.h> //字符函数


class person
{
public:
char name[20]; //姓名
char id[20]; //身份证号
double money; //钱
char age[10]; //年龄
char telephone[20]; //电话
char address[20]; //地址
char password[6]; //密码

public:
person(); //构造函数
person(char[],char[],double,char[],char[],char[],char[]); //构造函数
double checkin(double); //存款
double checkout(double); //取款
void changepass(); //修改密码
};

person::person() //构造函数
{
}

person::person(char n[20],char i[20],double m,char a[10],char t[13],char add[20],char p[6]) //实现构造函数
{
strcpy(name,n); //姓名
strcpy(id,i); //身份证号
money=m; //钱
strcpy(age,a); //年龄
strcpy(telephone,t); //电话
strcpy(address,add); //地址
strcpy(password,p); //密码
}

double person::checkin(double m) //存款函数实现
{
money=money+m;
return money;
}

double person::checkout(double m) //取款函数实现
{
if(money>m) //判断钱是否够取
money=money-m;
else
{
cout<<"你的钱仅有"<<money<<"元";
}
return money; //返回剩余额
}


void person::changepass() //修改密码
{
char a[6]; //第一次输入密码
char b[6]; //第二次输入密码
cout<<"输入新密码:"<<endl;
for(int i=0;i<6;i++) //第一次输入密码
{
a[i]=getch();
putch('*');
}
cout<<endl;
cout<<endl;
cout<<"确认新密码:"<<endl; //第二次输入密码
for (i=0;i<6;i++)
{
b[i]=getch();
putch('*');
}
cout<<endl;
cout<<endl;
cout<<a<<endl;
cout<<b<<endl;
cout<<strcmp(a,b)<<endl;
if(!strcmp(a,b)) //密码比较
{
strcpy(password,a); //相同者更改
MessageBox(0,"密码修改成功","提示",0);
}
else //输出错误信息
MessageBox(0,"密码输入错误","提示",0);
}
#include<iostream.h>
#include<time.h>

void main()
{
time_t t;
t=time(NULL);
tm *T=gmtime(&t);
int year=T->tm_year+1900;
int month=T->tm_mon+1;
int day=T->tm_mday;
int hour=T->tm_hour+8;
int min=T->tm_min;
int sec=T->tm_sec;
cout<<year<<"年"<<month<<"月"<<day<<"日 "<<hour<<":"<<min<<":"<<sec<<endl;
}

2007-10-29 22:19
a217zxg
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-10-20
收藏
得分:0 
   这个程序有C或C++来写的话好大啊,如果用labview来写的话,可能会容易得多。
2007-11-03 22:10
mingreign
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2007-9-15
收藏
得分:0 
回复:(风致)#include //文...
    请教一下,为什么你的程序里用了几个主函数呢?他还可以正确执行吗?而且为什么执行是显示"person.h"不能打开呀.谢谢了.
2007-11-04 15:30
快速回复:求一个银行模拟程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015695 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved