-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec5-practice.cpp
167 lines (120 loc) · 2.69 KB
/
lec5-practice.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
#include <iostream>
#include <cmath>
using namespace std;
int main(){
cout << "----------------" << endl;
//=================
// Variables
//=================
// Which is valid?
// Integer weight; // => good or bad?
// int weight; // => good or bad?
// weight int; // => good or bad?
// Int weight; // => good or bad?
// Are they all valid integers?
int weight2;
// weight2 = 3;
// weight2 = 0;
// weight2 = 1;
// weight2 = -1;
// weight2 = 169;
// weight2 = 1000;
// cout << weight2 << endl;
// => ?
// int weight3 = 'too heavy';
// cout << weight3 << endl;
// => ?
// int weight4 = 1000000000000000000000000000000000;
// cout << weight4 << endl;
// => ?
// int weight5 = 3.09;
// cout << weight5 << endl;
// => ?
// double weight6 = 3.09;
// cout << weight6 << endl;
// => ?
//=================
// Arithmetic
//=================
//
// How can we calculate BMI?
//
int weight = 70;
int height = 180;
double bmi; // = ?
// How can we calculate compound interest?
double balance_0 = 1000;
double rate = 0.05;
// Year 1
double balance_1 = balance_0 * (1 + rate);
// Year 2
double balance_2 = balance_0 * (1 + rate) * (1 + rate);
// Year 3
double balance_3 = balance_0 * (1 + rate) * (1 + rate) * (1 + rate);
// Year N
// double balance_n = balance_0 * (1 + rate) ^ n;
// => ?
// how can we write to the n'th power?
int n = 20;
double balance_n; // = ?
// cout << balance_n << endl;
double bal0 = 1000;
double bal1 = bal0 + bal0 * (rate);
double bal2 = bal0 + 2 * bal0 * (rate);
double baln = bal0 + n * bal0 * (rate);
//cout << baln << endl;
// => ?
//=================
// Math Functions
//=================
// where are the documentation?
// http://cplusplus.com/reference/cmath
// pow()
// how can we write 2*2*2*2*2?
// cout << ? << endl;
// => ?
// exp()
// how can we write 'e to the (0.07 * t) power'?
double t = 10;
double e = 2.71828;
// cout << exp(?) << endl;
// cout << pow(?, ?) << endl;
// => ?
// how can we compute the square root of 12345?
// cout << sqrt(12345) << endl;
// => ?
// how can we use PI?
// my_PI = 3.14159;
// => ?
// int my_PI = 3.14159;
// => ?
// double my_PI = 3.14159;
// => ?
// const double my_PI = 3.14159;
// => ?
// what is M_PI?
// cout << M_PI << endl;
// => ?
// how can we compute the square root of PI?
// cout << sqrt(M_PI) << endl;
// => ?
//=================
// Division
//=================
// cout << 7 / 3 << endl;
// => ?
// cout << 7.0 / 3 << endl;
// => ?
// cout << 7 / 3.0 << endl;
// => ?
// cout << 7 / 0 << endl;
// => ?
//=================
// Input / Output
//=================
int bottles;
// cout << "how many bottles of vokda did you drink?" << endl;
// cin >> bottles;
// cout << bottles << ' bottles' << endl;
cout << "----------------" << endl;
}