123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include <iostream>
- using namespace std;
- //Bank的定义
- 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 / 100.0; // 将百分比转换为小数
- }
- static double getRational() {
- return Rational;
- }
- void display() {
- double interest = Balance * Rational;
- cout << "账号:" << ID << "; 存款:" << Balance << "; 利息:" << interest << endl;
- }
- };
- double Bank::Rational = 0;
- int main()
- {
- Bank c;//系统缺省账户
-
- double rate;
- cout << "请输入利率:";
- cin >> rate;
- Bank::setRational(rate);
- Bank defaultAccount;
- Bank accounts[3];
- long id;
- double balance;
- cout << "请输入3个账号及对应的存款:" << endl;
- for (int i = 0; i < 3; ++i) {
- cin >> id >> balance;
- accounts[i].setID(id);
- accounts[i].setBalance(balance);
- }
- defaultAccount.display();
- for (int i = 0; i < 3; ++i) {
- accounts[i].display();
- }
- double totalInterest = defaultAccount.getBalance() * Bank::getRational();
- for (int i = 0; i < 3; ++i) {
- totalInterest += accounts[i].getBalance() * Bank::getRational();
- }
- double totalPrincipal = defaultAccount.getBalance();
- for (int i = 0; i < 3; ++i) {
- totalPrincipal += accounts[i].getBalance();
- }
- cout << "3个账户的本息:" << totalPrincipal + totalInterest << endl;
- return 0;
- }
|