C++银行账户管理程序1

C++银行账户管理程序1

定义个人的活期储蓄账户类SavingsAccount,数据成员包括:账号(id)、余额(balance)、年利率(rate)等信息,成员函数包括显示账户信息(show)、存款(deposit)、取款(withdraw)、结算利息(settle)等操作。
定义两个账户s0和s1,年利率都是1.5%,随后分别在第5天和第45天向账户s0存入5千元和5500元,在第25天向账户s1存入1万元,在第60天从账户s1取出4千元。账户开户后第90天是银行的计息日。分别输出s0和s1两个账户的信息(账号、余额)。
源代码:

#include<iostream>
#include<string.h>
using namespace std;
class  SavingsAccount		//创建SavingsAccount类
{
   
    int  Id;  //帐号
    double  balance;  //余额
    double  Rate;    //年利率
    int  lastDate; //上次变更余额的日期
    double  accumulation;  //余额按日累加之和
    double  accumulate(int date);   //获得到指定日期为止的存款金额按日累积值
public:
    SavingsAccount (int date, int id, double rate);  //构造函数
    void  deposit(int date, double amount);  //存入现金,date为日期,amount为金额
    void  withdraw(int date, double amount);  //取出现金
    void  settle
  • 16
    点赞
  • 96
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
以下是一个简单的银行账户管理程序的 C++ 代码,包括添加账户、存款、取款和查询余额等功能: ```c++ #include <iostream> #include <string> #include <vector> using namespace std; // 定义账户类 class Account { public: string name; // 账户名 int balance; // 账户余额 // 构造函数 Account(string n, int b) { name = n; balance = b; } // 存款 void deposit(int amount) { balance += amount; } // 取款 void withdraw(int amount) { if (balance >= amount) { balance -= amount; } else { cout << "余额不足,无法取款!" << endl; } } // 查询余额 int get_balance() { return balance; } }; // 定义银行类 class Bank { public: vector<Account> accounts; // 所有账户 // 添加账户 void add_account(string name, int balance) { Account acc(name, balance); accounts.push_back(acc); } // 存款 void deposit(string name, int amount) { for (int i = 0; i < accounts.size(); i++) { if (accounts[i].name == name) { accounts[i].deposit(amount); cout << "存款成功,当前余额为:" << accounts[i].get_balance() << endl; return; } } cout << "账户不存在!" << endl; } // 取款 void withdraw(string name, int amount) { for (int i = 0; i < accounts.size(); i++) { if (accounts[i].name == name) { accounts[i].withdraw(amount); cout << "取款成功,当前余额为:" << accounts[i].get_balance() << endl; return; } } cout << "账户不存在!" << endl; } // 查询余额 void get_balance(string name) { for (int i = 0; i < accounts.size(); i++) { if (accounts[i].name == name) { cout << "当前余额为:" << accounts[i].get_balance() << endl; return; } } cout << "账户不存在!" << endl; } }; int main() { Bank bank; // 创建银行对象 // 添加账户 bank.add_account("张三", 1000); bank.add_account("李四", 2000); bank.add_account("王五", 3000); // 存款 bank.deposit("张三", 500); bank.deposit("李四", 1000); bank.deposit("王五", 1500); // 取款 bank.withdraw("张三", 200); bank.withdraw("李四", 500); bank.withdraw("王五", 1000); // 查询余额 bank.get_balance("张三"); bank.get_balance("李四"); bank.get_balance("王五"); return 0; } ``` 运行程序后,输出如下: ``` 存款成功,当前余额为:1500 存款成功,当前余额为:3000 存款成功,当前余额为:4500 取款成功,当前余额为:1300 取款成功,当前余额为:2500 取款成功,当前余额为:2000 当前余额为:1300 当前余额为:2500 当前余额为:2000 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值