-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo10.cpp
67 lines (53 loc) · 1.12 KB
/
demo10.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
using namespace std;
// 全局变量
//double interestRate;
class Dog
{
private:
static double interestRate; // 类作用域的 interestRate
};
class Account
{
public:
Account(const string name, double money):
owner(name), amount(money)
{}
double getAmount() const
{
return this->amount;
}
void applyint() { amount += amount * interestRate; }
void deposit(double money)
{ this->amount += money; }
static double rate() { return interestRate; }
static void rate(double newRate)
{ interestRate = newRate; }
private:
string owner;
double amount;
// double interestRate;
static double interestRate; // 只有一个
};
double Account::interestRate = 0.015;
int main()
{
// interestRate = 0.0015;
Account::rate(0.026);
Account a("张三", 1000);
a.deposit(500);
Account b("李四", 2000);
b.deposit(600);
cout << a.getAmount() << endl;
cout << b.getAmount() << endl;
cout << a.rate() << endl;
a.rate(0.018);
cout << b.rate() << endl;
Account::rate(0.02);
a.applyint();
b.applyint();
cout << a.getAmount() << endl;
cout << b.getAmount() << endl;
return 0;
}