aa
#include <iostream>
#include <string>
using namespace std;
class Account {
friend void update(Account& a);
private:
static float count; // 账户总余额
static float interestRate;
string accno, accname;
float balance;
public:
Account(string ac, string na, float ba); // 构造函数
~Account(); // 析构函数
void deposit(float amount); // 存款
void withdraw(float amount); // 取款
float getBalance(); // 获取账户余额
void show(); // 显示账户所有基本信息
friend void update(Account& a); // 友元函数:结息
static float getCount(); // 获取账户总余额
static void setInterestRate(float rate); // 设置利率
static float getInterestRate(); // 获取利率
};
float Account::count = 0;
float Account::interestRate = 0;
Account::Account(string ac, string na, float ba):accno(ac),accname(na),balance(ba){}
Account::~Account() {
count -= balance;
}
void Account::deposit(float amount) {
balance += amount;
count += balance;
cout << " " << balance;
}
void Account::withdraw(float amount) {
balance -= amount;
count -= amount;
cout << " " << balance;
}
float Account::getBalance() {
return balance;
}
void Account::show() {
cout << accno << " " << accname;
}
void update(Account& a) {
a.count += a.balance * a.interestRate;
a.balance += a.balance * a.interestRate;
cout << " " << a.balance;
}
float Account::getCount() {
return count;
}
void Account::setInterestRate(float rate) {
interestRate = rate;
}
float Account::getInterestRate() {
return interestRate;
}
int main() {
float rate;
cin >> rate;
Account::setInterestRate(rate);
int n;
cin >> n;
Account** accounts = new Account*[n];
for (int i = 0; i < n; i++) {
string no, na;
float ba, cun, qu;
cin >> no >> na >> ba >> cun >> qu;
accounts[i] = new Account(no, na, ba);
accounts[i]->show();
accounts[i]->deposit(cun);
update(*accounts[i]);
accounts[i]->withdraw(qu);
cout << endl;
}
cout << Account::getCount() << endl;
for (int i = 0; i < n; i++) {
delete accounts[i]; // 释放动态分配的内存
}
return 0;
}