-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCourse3_week3_codes.cpp
162 lines (114 loc) · 2.74 KB
/
Course3_week3_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
Exercise-1
#include <iostream>
using namespace std;
//add class definitions below this line
class PracticeClass {
public:
string name;
};
//add class definitions above this line
int main() {
PracticeClass obj;
obj.name = "Class Object";
cout << obj.name;
return 0;
}
===================
Exercise-2
class Cat {
public:
string breed;
string color;
string name;
Cat() {
breed = "American Shorthair";
color = "black";
name = "Kiwi";
}
};
=========================
Exercise-3
#include <iostream>
#include <vector>
using namespace std;
//add class definitions below this line
class Superhero {
public:
string name;
string identity;
vector<string> powers;
Superhero(string n, string i, vector<string> p) {
name = n;
identity = i;
powers = p;
}
};
//add class definitions above this line
int main() {
Superhero iron_man("Iron Man", "Tony Stark", {"armored suit", "laser beams", "flight"});
cout << iron_man.name << endl;
cout << iron_man.identity << endl;
for (auto a : iron_man.powers) {
cout << a << endl;
}
return 0;
}====================
Exercise-4
#include <iostream>
using namespace std;
//add class definitions below this line
class Observation {
public:
string date;
int temperature;
double elevation;
int penguins;
double precipitation;
Observation(string d, int temp, double elev, int peng) {
date = d;
temperature = temp;
elevation = elev;
penguins = peng;
precipitation = 0;
}
};
//add class definitions above this line
int main() {
Observation o("October 26, 2019", -47, 329.4, 3);
cout << "Today is " << o.date << "." << endl;
cout << "Temperature: " << o.temperature << endl;
cout << "Elevation: " << o.elevation << endl;
cout << o.penguins << " penguins observed with " << o.precipitation << " precipitation." << endl;
return 0;
}
==========================
Exercise-5
#include <iostream>
#include <vector>
using namespace std;
class BigCat {
public:
string species;
string common_name;
vector<string> habitat;
string genus = "panthera";
BigCat(string sp, string cn, vector<string> h) {
species = sp;
common_name = cn;
habitat = h;
}
};
int main() {
//add code below this line
BigCat snow_leopard("uncia", "snow leopard", {"Himalaya mountains", "Siberian mountains"});
//add code above this line
cout << "A " << snow_leopard.common_name;
cout << " is part of the " << snow_leopard.species << " species." << endl;
cout << "Their genus class is " << snow_leopard.genus << "." << endl;
cout << "Some of their habitats include: ";
for (auto a : snow_leopard.habitat) {
cout << a << ", ";
}
cout << "etc." << endl;
return 0;
}