1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #include <iostream>
- using namespace std;
- class Bank {
- private:
- long ID;
- double Balance;
- static double Rational;
- public:
- Bank() : ID(10000), Balance(0) {} // 默认构造函数
- Bank(long id, double balance) : ID(id), Balance(balance) {} // 带参数构造函数
- void setID(long id) {
- ID = id;
- }
- void setBalance(double d) {
- Balance = d;
- }
- double getBalance() {
- return Balance;
- }
- static void setRational(double r) {
- Rational = r;
- }
- static double getRational() {
- return Rational;
- }
- void display() {
- cout << "账号:" << ID << "; 存款:" << Balance << "; 本息:" << Balance * ( Rational / 100) << endl;
- }
- };
- double Bank::Rational = 0; // 初始化静态数据成员
- int main() {
- double rate;
- cout << "请输入利率:";
- cin >> rate;
- Bank::setRational(rate); // 设置利率
- long id;
- double balance;
- cout << "请输入3个账号及对应的存款:" << endl;
-
- c.display(); // 输出系统缺省账户信息
-
- double totalInterest = 0;
- for (int i = 0; i < 3; ++i) {
- cin >> id >> balance;
- Bank account(id, balance);
- account.display(); // 输出新建账户信息
- totalInterest += balance * (1 + Bank::getRational() / 100);
- }
- cout << "3个账户的本息:" << totalInterest << endl;
- return 0;
- }
|