博客
关于我
银行系统改编版
阅读量:579 次
发布时间:2019-03-11

本文共 2676 字,大约阅读时间需要 8 分钟。

今天对银行系统进行了修改终于修改好了。下面是我今天忙了一大早的成果。大家看看吧。

#include<iostream>

using namespace std;
class Account
{
friend class CheckingAccount;
protected:
double balance;  //账户余额
public:
Account(double Balanc);
void credit();//向当前余额加钱
int debit();//从账中取钱
int getBalance();//返回balance值
};
Account::Account(double Balance)
{
  balance=Balance;
}
void Account::credit()
{
int save;
 cout<<"您的银行可用余额为:"<<balance<<endl;
 cout<<"请输入您要存入的金额:"<<endl;
 cin>>save;
 balance=balance+save;
 cout<<"存入后的余额为:"<<endl;
 cout<<balance<<endl;
}
int Account::debit()
{
 int demand;int flag=1;
 cout<<"请输入您要取出的金额:"<<endl;
 cin>>demand;
 if(demand>balance)
 {balance=balance;
 cout<<"对不起!您的余额不足,请充值:"<<endl;
 }
 else
 { balance=balance-demand;
   cout<<"您已成功取出"<<demand<<"元现金"<<endl;
   cout<<"您的余额为"<<getBalance()<<endl;;
   //cout<<"您的余额为"<<balance<<endl;
   flag=0;//表示钱已被取走
 }
  return flag;
}
int Account::getBalance()
{
 return balance;
}
class SavingAccount:public Account
{
friend class CheckingAccount;//下面的CheckingAccount中会用到//SavingAccount中的caclculateInterest
private:
//double balance;
double interestrate;//账户的比例
public:
SavingAccount(double Balance,double Interestrate);
int caclculateInterest();
};
SavingAccount::SavingAccount(double Balance,double Interestrate):Account(Balance)
{
balance=balance;
 interestrate=Interestrate;
 //credit();//存
 //debit();//取
}
int SavingAccount::caclculateInterest()
{
double money;
money=balance*interestrate;
return money;//利息
}
class CheckingAccount:public SavingAccount
{
private:
double fare;//表示每笔的费用
public:
CheckingAccount(double Balance,double Interestrate,double Fare);
void rescredit();
int resdebit();
};
CheckingAccount::CheckingAccount(double Balance,double Interestrate,double Fare):SavingAccount(Balance,Interestrate)
{
balance=Balance;
interestrate=Interestrate;
  fare=Fare;
}
/*void CheckingAccount::rescredit()
{
 credit();
 //caclculateInterest();
 int save;
 cout<<"请输入您要存入的金额:"<<endl;
 cin>>save;
 balance=balance+save;
}*/
int CheckingAccount::resdebit()
{bool flag;
 //credit();
 //debit();
 if(debit()==0)
 {
cout<<"您已成功提出钱!:"<<endl;
balance=balance-fare;
cout<<"取钱收取费用!"<<endl; 
 cout<<"收取的费用后余额产生的利息:"<<caclculateInterest()<<endl;
 }
 else
cout<<"收费不成功:"<<endl;
 return balance;
}
void main()
{
cout<<"************欢迎您使用张新华银行系统************"<<endl;
cout<<"***********************************"<<endl;
 Account A1(100);
 A1.credit();A1.debit();A1.getBalance();
 cout<<"***********************************"<<endl;
 SavingAccount S1(A1.getBalance(),0.2);
 S1.credit();
 S1.debit();
 S1.getBalance();
 cout<<"账户的利息:"<<S1.caclculateInterest()<<endl;
  cout<<"***********************************"<<endl;
  CheckingAccount C1(S1.getBalance(),0.2,30);
 C1.credit();
 //C1.debit();
 cout<<"收取费用后的余额:"<<C1.resdebit();
}

转载地址:http://cvevz.baihongyu.com/

你可能感兴趣的文章
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>