用c++编写ATM程序

用c++编写ATM程序,第1张

#include <iostream>

using namespace std

////////////尘汪///////////////////用户类//////////////////////////////////////

class User

{

private:

int money

string userName

string password

public:

User()

~User()

User(string userName, string password)

int saveMoney(int money)// 存款

int getMoney(int money)// 取款

int checkMoney() // 查询余额

string getUserName() // 取得用户名

string getPassword() // 取得密码

}

User::User()

{

money = 0

}

User::User(string userName, string password)

{

money = 0

this->userName = userName

this->password = password

}

int User::saveMoney(int money)

{

this->money += money

return this->money

}

int User::getMoney(int money)

{

this->money -= money

return this->money

}

int User::checkMoney()

{

return this->money

}

string User::getUserName()

{

return this->userName

}

string User::getPassword()

{

return this->password

}

/////////////////////////////////////////////////////////////////////////

///////////////////////////////////数据库类,用来存储用户//////////////////////

class DataBase

{

private:

User *users[40] // 默认数据可最多能存放40个用户

int userNumber // 已注册用户的数量

public:

DataBase()

~DataBase()

bool add(User *user) // 添加新用户

User * getUser(int i)// 按照索引取得用户

User * getUser(string name)// 按照用户名取得用户

int getUserNumber() // 取得数据库中用户的数量

}

DataBase::DataBase()

{

userNumber = 0

}

DataBase::~DataBase()

{

delete users

}

bool DataBase::add(User *user)

{

if(userNumber <40 &&getUser(user->getUserName()) == NULL) // 如果当前用户名在数据库中不存在

{

users[userNumber] = user

userNumber++

return true // 返悄兄碧回true表示新用户添加成功

}

return false// 返回false表示新用户添加失败

}

User * DataBase::getUser(int i)

{

if(i >40 || i <0) return NULL

return users[i]

}

User * DataBase::getUser(string userName)

{

for(int i = 0i <userNumberi++)

{

User *user = getUser(i)

if(user->getUserName() == userName) return user

}

return NULL

}

///////启举//////////////////////////////////////////////////////////////////

DataBase database

int welcom()

// 注册

User * user_register()

User * user_login()

int exit()

int user_process()

int main()

{

int state

int user_state

User *user

do

{

state = welcom()

switch(state)

{

case 1:

user = user_register()// 用户注册

if(NULL != user)

{

cout<<"\n注册成功\n"

do

{

user_state = user_process()

switch(user_state)

{

case 1:// 存钱

{

cout<<"输入存钱金额:"

int num

cin>>num

cout<<"余额为:"<<user->saveMoney(num)<<endl

}

break

case 2:// 取钱

{

cout<<"输入取钱金额:"

int num

cin>>num

cout<<"余额为:"<<user->getMoney(num)<<endl

}

break

case 3:// 查看余额

{

cout<<"余额为:"<<user->checkMoney()<<endl

}

break

case 4://返回

user_state = 0

default: break

}

} while(user_state)

user = NULL

}

else cout<<"\n注册失败\n"

break

case 2:

user = user_login()// 用户登陆

if(NULL != user)

{

cout<<"登陆成功"<<endl

do

{

user_state = user_process()

switch(user_state)

{

case 1:// 存钱

{

cout<<"输入存钱金额:"

int num

cin>>num

cout<<"余额为:"<<user->saveMoney(num)<<endl

}

break

case 2:// 取钱

{

cout<<"输入取钱金额:"

int num

cin>>num

cout<<"余额为:"<<user->getMoney(num)<<endl

}

break

case 3:// 查看余额

{

cout<<"余额为:"<<user->checkMoney()<<endl

}

break

case 4://返回

user_state = 0

default: break

}

} while(user_state)

user = NULL

}

else cout<<"\n登陆失败\n"

break

case 3:

state = exit()

break

default: break

}

}

while(state)

return 0

}

int welcom()

{

cout<<"\t\t**********欢迎使用ATM系统**********\n"

cout<<"\t\t* 1.用户注册 *\n"

cout<<"\t\t* 2.用户登录 *\n"

cout<<"\t\t* 3.退出系统 *\n"

cout<<"\t\t***********************************\n"

int num

cin>>num

return num

}

// 注册

User * user_register()

{

string userName

string password

cout<<"请输入账号:"

cin>>userName

if(NULL != database.getUser(userName)) // 如果用户名存在

return NULL// 注册失败

cout<<"请输入密码:"

cin>>password

User *user = new User(userName, password)

database.add(user)

return user// 注册成功

}

User * user_login()

{

string userName

string password

cout<<"请输入账号:"

cin>>userName

cout<<"请输入密码:"

cin>>password

User *user = database.getUser(userName)

if(NULL != user) // 如果用户存在

if(user->getPassword() == password)

return user// 如果密码匹配则登陆成功

return NULL// 如果用户不存在

}

int exit()

{

return 0// 退出系统

}

int user_process()

{

cout<<"\t\t******************************\n"

cout<<"\t\t* 请选择 *** 作类型 *\n"

cout<<"\t\t* 1.存 钱 *\n"

cout<<"\t\t* 2.取 钱 *\n"

cout<<"\t\t* 3.查 看 余 额 *\n"

cout<<"\t\t* 4.返 回 *\n"

cout<<"\t\t******************************\n"

int num

cin>>num

return num

}

#include<stdio.h>

void main()

{

char SelectKey,CreditMoney,DebitMoney

while(1)

{

do{

clrscr()

puts("Please select key:")

puts("1.Quary")

puts("2.Credit")

puts("3.Debit")

puts("4.Return")

SelectKey=getch()

}while(SelectKey!='1'&&SelectKey!='2'&&SelectKey!='3'&&SelectKey!='4')

switch(SelectKey)

{

case'1':

clrscr()

puts("Your balance is $1000")

getch()

break

case'2':

do{

clrscr()

puts("Please select Credit money:")

puts("1.$50")

puts("2.$100")

puts("3.Return")

CreditMoney=getch()

}while(CreditMoney!='1'&&CreditMoney!='2'&&CreditMoney!='3')

switch(CreditMoney)

{

case'1':

clrscr()

puts("Your Credit money is $50,Thank you!")

getch()

break

case'2':

clrscr()

puts("Your Credit money is $100,Thank you!")

getch()

break

case'3':

break

}

break

case'3':

do{

clrscr()

puts("Please select Debit money:")

puts("1.$50")

puts("2.$100")

puts("3.$500")

puts("4.$1000")

puts("5.Return")

DebitMoney=getch()

}while(DebitMoney!='1'渗派&&DebitMoney!='2'&&DebitMoney!='3'&&DebitMoney!='4'&&DebitMoney!='5')

switch(DebitMoney)

{

case'1':

clrscr()

puts("Your Debit money is $50,Thank you!")

getch()

break

case'2':

clrscr()

puts("Your Debit money is $100,Thank you!")

getch()

break

case'3':

clrscr()

puts("Your Debit money is $500,Thank you!")

getch()

break

case'4':

clrscr()

puts("Your Debit money is $1000,Thank you!")

getch()

break

case'5':

break

}

break

case'4':

return

}

}

}

几个小错误而已...比孙携如忘了写双撇号,switch写错了...还有!= 忘了写! 等等.. 以上程序可以运则喊伏行了


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12388255.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存