package com.lw.thread
/*
银行账户类Account(不能透支),
包含账扰纯号id(10~16位数字),密码password(6位数字),户主姓名name,余额balence
*/
public class Account {
private String id
private int password
private String name
private double balence
public String getId() {
return id
}
public void setId(String id) {
this.id = id
}
public int getPassword() {
return password
}
public void setPassword(int password) {
this.password = password
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public double getBalence() {
return balence
}
public void setBalence(double balence) {
this.balence = balence
}
/*
* 默认构造账户信息为:1111111111111111,666666,钱三多,888888.88。
*/
public Account() {
super()
this.id = "1111111111111111"
this.password = 666666
this.name = "钱乎拿三多"
this.balence = 888888.88
}
/*
* 另一个构造方法带4个参数分别初始化4个属性(带数据有效性验证)。
*/
public Account(String id, int password, String name, double balence) {
this.id = id
this.password = password
this.name = name
this.balence = balence
}
/*
* 查询余额
*/
public static double selectMoney(Account account) {
return account.getBalence()
}
/*
* 存钱
*/
public static String setMoney(Account account, double balence) {
if (balence <0) {
return "存钱失败,请正确放入!"
}
double d = balence + account.getBalence()
account.setBalence(d)
return "您存入了" + balence + "元,现账户余额为+" + d
}
/*
* 取钱
*/
public static String getMoney(Account account, double balence) {
double d = account.getBalence()
if (balence >d) {
return "您的余缓顷咐额不足!"
}
account.setBalence(d - balence)
return "您取出了" + balence + "元,现账户余额为+" + account.getBalence()
}
}
#include<iostream>#include<cstring>using namespace stdclass count{public:friend class ATMcount (char Name[],char Num[],floatMoney,char Password[])//初始化protected:char * get_name()//返回姓名char * get_num()//返回卡号char * get_password()/咐运芹/返回密码float get_money()//返回金额void set_password(char pwd[])//设置密码void set_money(float m)//取钱private:char password[6]//用户密码char name[20]//用户姓名char num[20]float money}class ATM{public:ATM(count &cn):ctm(cn){}void welcome()//登陆界面bool check_password(char p[],char pwd[])//核对密码void change_password()//修改密码void get_money()//取钱void get_information()//查询信息void exit_ATM()//退出ATMvoid show_function()//功能界面void push_card()//吞卡private:int times//记录输入密码的次数count &ctm}//构造ATM的函数void ATM::welcome() //构造welcome{times=0cout<<"欢迎使用ATM模拟自动取款机"<<endlcout<<"-------------------------"<<endlcout<<"请选择:\n1.新开帐户\t2.客户服务\t3.退出系统衡毕"悄皮<<endl//输出主菜单char pwd[7],num[20]//6位密码19位卡号int i=0do{cout<<"请输入卡号"cin>>numcout<<"请输入密码:"cin>>pwdif(!check_password(num,pwd)){cout<<"你输入的密码有错误,请重新输入"<<endltimes++}else{show_function()}}while(times<3)push_card()}bool A.....欢迎分享,转载请注明来源:内存溢出
评论列表(0条)