-
Notifications
You must be signed in to change notification settings - Fork 1
/
Course4_week2_codes.cpp
219 lines (168 loc) · 4.91 KB
/
Course4_week2_codes.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
Exercise-1
//DO NOT EDIT//////////////////////////////
class Satellite : public CelestialBody { //
///////////////////////////////////////////
public:
Satellite(double s, double m, string c, string n, string hp) : CelestialBody(s, m, c, n) {
host_planet = hp;
}
string GetHostPlanet() {
return host_planet;
}
void SetHostPlanet(string new_host_planet) {
host_planet = new_host_planet;
}
private:
string host_planet;
};
//DO NOT EDIT///////////////////////////
class Planet : public CelestialBody { //
////////////////////////////////////////
public:
Planet(double s, double m, string c, string n, string hs) : CelestialBody(s, m, c, n) {
host_star = hs;
}
string GetHostStar() {
return host_star;
}
void SetHostStar(string new_host_star) {
host_star = new_host_star;
}
private:
string host_star;
};
============================
Exercise-2
//DO NOT EDIT////////////////////
class BlogPost : public Book { //
/////////////////////////////////
public:
BlogPost(string t, string a, string g, string w, int wc, int pv) : Book(t, a, g) {
website = w;
word_count = wc;
page_views = pv;
}
string GetWebsite() {
return website;
}
void SetWebsite(string new_website) {
website = new_website;
}
int GetWordCount() {
return word_count;
}
void SetWordCount(int new_word_count) {
word_count = new_word_count;
}
int GetPageViews() {
return page_views;
}
void SetPageViews(int new_page_views) {
page_views = new_page_views;
}
private:
string website;
int word_count;
int page_views;
};
==============================
Exercise-3
class Child : public Parent2 {
public:
string Identify() {
return "This function is called from Child";
}
string Identify2() {
return Parent2::Identify();
}
string Identify3() {
return Parent1::Identify();
}
};
==========================
Exercise-4
//DO NOT EDIT/////////////////////
class Cash : public PiggyBank { //
//////////////////////////////////
public:
Cash(int o, int f, int tn, int tw) : PiggyBank(o, f, tn, tw) {}
void DisplayBills() {
cout << "One-dollar bill: " << GetOnes() << endl;
cout << "Five-dollar bill: " << GetFives() << endl;
cout << "Ten-dollar bill: " << GetTens() << endl;
cout << "Twenty-dollar bill: " << GetTwenties() << endl;
}
void DisplayCashTotal() {
cout << "Total amount: ";
cout << GetOnes() + GetFives() * 5 + GetTens() * 10 + GetTwenties() * 20;
cout << endl;
}
};
========================
Exercise-5
//DO NOT EDIT/////////////////////////////////////////////////
class CardHolder : public Person { //
public: //
CardHolder(string n, string a, int an) : Person(n, a) { //
account_number = an; //
balance = 0; //
credit_limit = 5000; //
} //
//////////////////////////////////////////////////////////////
int GetAccountNumber() {
return account_number;
}
void SetAccountNumber(int new_account_number) {
account_number = new_account_number;
}
double GetBalance() {
return balance;
}
void SetBalance(double new_balance) {
balance = new_balance;
}
int GetCreditLimit() {
return credit_limit;
}
void SetCreditLimit(int new_credit_limit) {
credit_limit = new_credit_limit;
}
void Sale(double price) {
balance += price;
}
void Payment(double amount) {
balance -= amount;
}
private:
int account_number;
double balance;
int credit_limit;
};
//DO NOT EDIT/////////////////////////////////////////////////////////////
class PlatinumClient : public CardHolder { //
public: //
PlatinumClient(string n, string a, int an) : CardHolder(n, a, an) { //
cash_back = 0.02; //
rewards = 0; //
} //
//////////////////////////////////////////////////////////////////////////
double GetCashBack() {
return cash_back;
}
void SetCashBack(double new_cash_back) {
cash_back = new_cash_back;
}
double GetRewards() {
return rewards;
}
void SetRewards(double new_rewards) {
rewards = new_rewards;
}
void Sale(double price) {
rewards += cash_back * price;
SetBalance(GetBalance() + price);
}
private:
double cash_back;
double rewards;
};