#include <stdlib.h>
#include <conio.h>
#include <string.h>
void regist()
void login()
void quite()
void inputpassword(char mima[])
void service()
struct bank
{
char name[20]
char password[7]
int account
double money
}kehu
int find
int a[10]
struct bank one
FILE *fp
void main()
{
int i
int t=1
for(i=0i<100i++)
{
printf("\t\t\t\t\t\t欢迎使用青软ATM系统\n")
printf("\t\t\t\t\t\t正在进入主界面,请稍等")
int j
for(j=1j<tj++)
{
printf(".")
}
t++
if(t==10)
{
t=1
}
printf("\n\t\t\t\t\t\t%d%%",i)
system("cls")
}
while(1)
{
printf("\t\橘散t\t\t\t\t服务类型: \n")
printf("\t\t\t\t\t\t[a]: 用户注册\n")
printf("神源\t\t\t\t\t\t[b]: 用户登录\n")
printf("\t\t\t\t\t\t[c]: 退出系统\n")
printf("\t\t\t\t\t\t请选择服务: ")
fflush(stdin)
char xz
scanf("%c",&xz)
if(xz=='a'||xz=='A')
{
regist()
} else if (xz=='b'||xz=='B')
{
login()
} else if(xz=='c'||xz=='C')
{
quite()
} else
{
printf("输入有误,请重新输入")
}
getch()
system("cls")
}
}
void inputpassword(char mima[])
{
int i=0
char ch
while(1)
{
ch=getch()
if(ch!='\r')
{
if(ch!='\b'){
mima[i]=ch
i++
printf("*")
}else{
if(i>0){
i--
printf("\b \b")
}
}
}else{
break
}
}
mima[i]='\0'
printf("\n")
}
void regist()
{
fp=fopen("atm.txt","ab+")
if(fp==NULL)
{
printf("\n\t\t\t文件打开失败!")
return
}
system("cls")
printf("\t\t\t现在执行的是注册函数的使用\n")
printf("\t\t请输入用户名: ")
fflush(stdin)
gets(kehu.name)
char password1[7]
while(1)
{
while(1)
{
printf("\n\n\t\t请输入密码:")
fflush(stdin)
inputpassword(kehu.password)
int n=strlen(kehu.password)
if(n==6)
{
break
}else
{
printf("\n\t\t密码必须为6位!")
}
}
printf("\n\t\t请输入正确密码!: ")
fflush(stdin)
inputpassword(password1)
if(strcmp(kehu.password,password1)==0)
{
break
}else{
printf("\n\n\t\t两次密码必须相同!")
}
}
rewind(fp)
struct bank k
if(fread(&k,sizeof(struct bank),1,fp)==1)
{
fseek(fp,-sizeof(k),2)
fread(&k,sizeof(k),1,fp)
kehu.account=k.account+1
}else{
kehu.account=20170001
}
kehu.money=0
fseek(fp,0,2)
fwrite(&kehu,sizeof(struct bank),1,fp)
fclose(fp)
printf("\n\n\t\t开户成功! ")
printf("\游伍态n\t\t您的账号为%d!",kehu.account)
printf("\n\t\t现在请您重新登录!")
}
void searchmoney()
{
system("cls")
printf("您现在使用的是查询余额功能: \n")
printf("\n\n\t\t您的余额是%0.2lf",one.money)
}
void savemoney()
{
system("cls")
double inmoney
printf("请您选择您要存款的金额 \n")
scanf("%lf",&inmoney)
int q
int r=1
for(q=0q<100q++)
{
int w
for(w=1w<rw++)
{
printf(".")
}
r++
if(r==10)
{
r=1
}
printf("\n\t\t\t\t\t\t正在存款%d%%",q)
system("cls")
}
one.money=one.money+inmoney
fseek(fp,-sizeof(one),1)
fwrite(&one,sizeof(one),1,fp)
printf("\n\n\t\t\t\t\t\t您已存款成功!")
}
void withdrawalmoney()
{
system("cls")
double outputsomemoney
printf("请您选择您要取款的金额 \n")
scanf("%lf",&outputsomemoney)
if(one.money<outputsomemoney){
printf("您的余额已不足,请您注意!")
}else {
int q
int r=1
for(q=0q<100q++)
{
int w
for(w=1w<rw++)
{
printf(".")
}
r++
if(r==10)
{
r=1
}
printf("\n\t\t\t\t\t\t正在取款%d%%",q)
system("cls")
}
one.money=one.money-outputsomemoney
fseek(fp,-sizeof(one),1)
fwrite(&one,sizeof(one),1,fp)
printf("\n\n\t\t\t\t\t\t您已取款成功!请点清钞票!")
printf("\n\n\t\t\t\t\t\t您现在的余额为%lf",one.money)
}
}
void transfermoney()
{
system("cls")
int duifang
int qian
fflush(stdin)
printf("\n\n\n\t\t您现在使用的是转账功能")
printf("\n\t\t\t请输入您要转账的账户:")
scanf("%d",&duifang)
int n=ftell(fp)
rewind(fp)
int flag=0
struct bank temp
while(fread(&temp,sizeof(temp),1,fp)==1)
{
if(temp.account==duifang)
{
flag=1
break
}
}
if(flag==1)
{
printf("请输入转账金额:")
scanf("%d",&qian)
if(one.money>=qian)
{
int q
int r=1
for(q=0q<100q++)
{
int w
for(w=1w<rw++)
{
printf(".")
}
r++
if(r==10)
{
r=1
}
printf("\n\t\t\t\t\t\t正在转账,请稍后!%d%%",q)
system("cls")
}
temp.money=temp.money+qian
fseek(fp,-sizeof(temp),1)
fwrite(&temp,sizeof(temp),1,fp)
one.money=one.money-qian
fseek(fp,n-sizeof(one),0)
fwrite(&one,sizeof(one),1,fp)
printf("\n\t\t\t\t转账成功!")
}else{
printf("\n\t\t\t\t您的余额已不足!")
}
}
}
void xiugai(){
system("cls")
printf("\n\n\t\t 现在进行的是修改密码功能\n")
char oldpassword[7]
char newpassword[7]
char newpassword1[7]
int i
for(i=0i<3i++){
printf("\n\t\t\t 请输入旧密码:\n")
inputpassword(oldpassword)
if(strcmp(oldpassword,one.password)==0){
printf("\n\t\t\t 输入成功!\n")
break
}else{
printf("\n\t\t\t 密码输入有误,请重新输入!\n")
}
}
if(i<3){
while(1){
printf("\n\t\t\t 请输入您的新密码:\n")
inputpassword(newpassword)
printf("\n\t\t\t 请输入您的确认密码:\n ")
inputpassword(newpassword1)
if(strcmp(newpassword,newpassword1)==0){
strcpy(one.password,newpassword)
fseek(fp,-sizeof(one),1)
fwrite(&one,sizeof(one),1,fp)
printf("\n\t\t\t 密码修改成功!")
break
}else{
printf("\n\t\t\t 两次密码输入不一致!")
}
}
}else{
printf("\n\t\t\t 密码输入错误!")
}
}
int zhuxiaozhanghao()
{
system("cls")
int zhuxiaoxitong
char sf
printf("你要注销的账号是%d",one.account)
printf("你是否要对此账号进行注销?\n\n\t\t请您选择:注销(Y)or不注销(N):")
fflush(stdin)
scanf("%c",&sf)
if(sf=='y'||sf=='Y')
{
printf("正在为您注销!\n",one.account)
zhuxiaoxitong=1
}else{
printf("不注销系统!\n",one.account)
}
return zhuxiaoxitong
}
void service()
{
while(1){
system("cls")
printf("\n\n\n\t\t\t\t\t\t现在是服务系统,本系统有以下服务")
printf("\n\t\t\t\t\t\t[a] 查询余额\n")
printf("\n\t\t\t\t\t\t[b] 存款服务\n")
printf("\n\t\t\t\t\t\t[c] 转账服务\n")
printf("\n\t\t\t\t\t\t[d] 取款服务\n")
printf("\n\t\t\t\t\t\t[e] 修改密码\n")
printf("\n\t\t\t\t\t\t[f] 注销\n")
printf("\n\t\t\t\t\t\t[g] 退出系统\n")
char e
printf("\n\t\t\t\t\t\t您要选择的服务是:")
fflush(stdin)
scanf("%c",&e)
switch(e)
{ case'A':
case'a': searchmoney() break
case'B':
case'b': savemoney() break
case'C':
case'c': transfermoney() break
case'D':
case'd': withdrawalmoney() break
case'E':
case'e': xiugai() break
case'F':
case'f': {int zhuxiaoxitong=zhuxiaozhanghao(){if(zhuxiaoxitong==1) return}break}
case'G':
case'g': quite()break
}
printf("\n\n\n\t\t\t\t按任意键继续......\n")
getch()
}
}
void login()
{
fp=fopen("atm.txt","rb+")
if(fp==NULL)
{
printf("\n\n\n\t\t\t\t文件打开失败!")
return
}
system("cls")
printf("\n\t\t\t\t\t\t现在执行的是登录函数的使用\n")
int zhanghao
printf("\n\t\t\t\t\t\t请输入账号:")
scanf("%d",&zhanghao)
int flag=0
while(fread(&one,sizeof(one),1,fp)==1)
{
if(zhanghao==one.account){
flag=1
break
}
}
char password2[7]
if(flag==1){
int h
for(h=0h<3h++){
printf("\n\t\t\t\t\t\t请输入密码:")
fflush(stdin)
inputpassword(password2)
if(strcmp(password2,one.password)==0)
{
printf("\n\t\t\t\t\t\t登陆成功!")
service()
break
}else{
printf("密码不正确!")
}
}
if(h==3){
printf("\n\t\t\t您的密码三次输入有误,返回")
}
}else{
printf("无此账号!")
}
fclose(fp)
}
void quite()
{
system("cls")
printf("\t\t\t现在执行的是退出函数的使用\n")
exit(0)
}
#include"stdio.h"对ATM机器的模拟就是一个对队列的模拟下面代码在VC6环境下调郑野试雹隐已经通过了其中有个缺陷就是因为代码执行速度过快导致二次执行根据时间随机出来的数字都是一样的因此你可以自己加上一个延迟子程序部分功能已经注释了#include
"stdlib.h"#include
"time.h"#define
OK
1#define
ERROR
0
typedef
struct
node{
int
number
struct
node*
next}*Lnode
typedef
struct
list{
node
*head,*rear}*Plist
//模拟
ATM开业bool
ListInit(Plist
list){
Lnode
p
p
=
(Lnode)malloc(sizeof(Lnode))
list->head
=
p
list->rear
=
list->head
list->head->next
=
NULL
if(list->head!=NULL)
return
ERROR
else
return
OK}
//模拟
有客户排队bool
ListInsert(Plist
list,int
number){
Lnode
p
p
=
(Lnode)malloc(sizeof(Lnode))
if(p==NULL)
return
ERROR
else
{
p->number
=
number
p->next
=
NULL
list->rear->next
=
p
list->rear
=
p
return
OK
}}
//模拟
客户办完事离开bool
ListDelete(Plist
list){
Lnode
p
if(list->head
==list->rear)
return
ERROR
else
{
p
=
list->head->next
list->head->next
=
p->next
list->rear
=
list->head
//
free(p)
return
OK
}}
void
sand(int*
gettime,int*
needtime){
srand(time(NULL))
*gettime
=
rand()%100
srand(time(NULL))
*needtime
=rand()%100}
//模拟客户到达事件void
CustomerArrived(Plist
list,int
gettime,int
needtime,int
kehu,int
time){
int
nextgettime,nextneedtime
sand(&nextgettime,&nextneedtime)
while(needtime>0
&&
nextgettime>0
&&
time>0)
{
needtime
--
nextgettime
--
time
--
}
if(nextgettime
==
0
&&
needtime>0
&&time>0)
{
kehu++
ListInsert(list,kehu)
while(needtime>0
&&
time>0)
{
needtime--
time
--
}
ListDelete(list)
CustomerArrived(list,nextgettime,nextneedtime,kehu,time)
}
if(needtime
==0
&&
nextgettime>0
&&
time>0)
{
ListDelete(list)
while(nextgettime>0
&&
time>0)
{
nextgettime--
time
--
}
kehu++
ListInsert(list,kehu)
//未删除
,list未传递进去
CustomerArrived(list,nextgettime,nextneedtime,kehu,time)
}
if(time
==0)
{
printf("ATM关门,请明天在来!\n")
return
}}
main(){
list
list
int
i
=
10000
/源丛厅/ATM机器每天工作时间
int
kehu
=
0
//客户标号
int
gettime,needtime
ListInit(&list)
//ATM开业
sand(&gettime,&needtime)
ListInsert(&list,kehu)
CustomerArrived(&list,gettime,needtime,kehu,i)
getchar()
}
lass consumerclass ATM // ATM取款机
{
public:
ATM(consumer& cn):cnsm(cn){}
void welcome() // 登陆界面
bool check_passwd(char n[],char pwd[]) // 核对密码
void change_passwd() // 修改密码
void fetchmoney() // 取款
void information() // 查询信息
void exitATM() // 退出系统
void functionshow() // 功能界面
void lock() // 锁机
private:
int times // 记录密码输入次数
consumer& cnsm
}
class consumer // 用户
{
public:
friend class ATM
consumer(char Name[],char Num[],float Money,char Password[])
protected:
char* get_name() // 取得姓名
char* get_num() // 取得卡号
char* get_passwd() // 取得密码
float get_money() // 取得余额
void set_passwd(char pwd[]) // 设置密码
void set_money(float m) // 取钱
private:
char passwd[8] // 用户密码
char name[20] // 用户姓名
char num[20]
float money
}
// ************************************
// * *
// * consumer类的成员函数 吵衡 *
// * *
// ************************************
#include"function.h"
#include
consumer::consumer(char Name[],char Num[],float Money,char Password[])
{
strcpy(name,Name)
strcpy(num,Num)
money=Money
strcpy(passwd,Password)
}
float consumer::get_money()
{
return money
}
char* consumer::get_name()
{
return name
}
char* consumer::get_num()
{
return num
}
char* consumer::get_passwd()
{
return passwd
}
void consumer::set_money(float m)
{
money-=m
}
void consumer::set_passwd(char pwd[])
{
strcpy(passwd,pwd)
}
// ************************************
// * 物碰肢*
// * ATM类的成员函数 *
// * *
// ************************************
#include "function.h"
#include
#include
void ATM::welcome()
{
times=0
cout<<"$ 欢迎使用若雪银行ATM自动取款机!~! "<< P>
char pwd[8],num[20],ch
int i=0
do
{
i=0
cout<<"请输入卡号:"
do
{
cin.get(ch)
num[i++]=ch
}while(ch!='\n')
num[i-1]='\0'
i=0
cout<<"请输入密码:"
do
{
cin.get(ch)
pwd[i++]=ch
}while(ch!='\n')
pwd[i-1]='\0'
if(!check_passwd(num,pwd))
{
cout<<"你输入的卡号或密码有误,请重新输入"<
times++
}
else
罩世 {
functionshow()
}
}while(times<3)
lock()
}
bool ATM::check_passwd(char num[],char pwd[])
{
if(strcmp(num,cnsm.get_num())==0&&strcmp(pwd,cnsm.get_passwd())==0)
return true
else
return false
}
void ATM::functionshow()
{
int n
do
{
cout<<"请你输入相应的 *** 作序号进行 *** 作:"<<ENDL
cout<<"1) 修改密码 "< <<"2) 取款 "< <<"3) 查询余额 "< <<"4) 退出系统 "<
cout<<"$ >\\"
cin>>n
while(n<1||n>4)
{
cout<<"请输入正确的 *** 作序号!"<
cout<<"$ >\\"
cin>>n
}
switch(n)
{
case 1: change_passwd() break
case 2: fetchmoney() break
case 3: information() break
case 4: exitATM() break
}
}while(true)
}
void ATM::change_passwd()
{
char pwd[8],repwd[8]
times=0
do
{
cout<<"请输入旧密码:"
cin>>pwd
if(!check_passwd(cnsm.get_num(),pwd))
times++
else
break
}while(times<3)
if(times==3)
lock()
int t=0
do
{
cout<<"请输入新密码:"
cin>>pwd
cout<<"请再输入一次新密码:"
cin>>repwd
if((t=strcmp(pwd,repwd))!=0)
cout<<"你输入的两次密码不一样,请从新输入!"<
}while(t!=0)
cnsm.set_passwd(pwd)
cout<<"密码修改成功,请牢记!"<< P>
}
void ATM::fetchmoney()
{
float m
char ch
do
{
cout<<"你要取多少钱:"<<"\N$>\\"<
cin>>m
while(m<=0)
{
cout<<"请输入正确的数字!"<
cout<<"$ >\\ "
cin>>m
}
if(cnsm.get_money()-m<0)
{
cout<<"对不起,你的余额不足!"<
}
else
{
cout<<" *** 作成功,请收好钱!"<<ENDL
cnsm.set_money(m)
}
cout<<"是否要继续该项 *** 作:(Y/N) "<
cout<<"$ >\\ "
cin>>ch
while(ch!='n'&&ch!='N'&&ch!='Y'&&ch!='y')
{
cout<<"$ >\\"
cin>>ch
}
}while(ch=='y'||ch=='Y')
}
void ATM::information()
{
cout<<"**********************************"<
cout<<"*"<
cout<<"* 用户姓名:"<<<ENDL
cout<<"* 卡号: "<<<ENDL
cout<<"* 余额: "<<<ENDL
cout<<"**********************************"<< P>
}
void ATM::lock()
{
cout<<"对不起,由于你的 *** 作有误,你的卡已经被没收! ?<<endl
cout<<"请取卡……"<
exit(0)
}
// ************************************
// * *
// * ATM.cpp *
// * *
// ************************************
#include
#include"function.h"
void main()
{
consumer c1("jim","12345",5200.3f,"123") // 先构造一个用户
ATM atm(c1)
atm.welcome()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)