|
1
|
- Instructor: Brian M. Dennis
- Teaching Assistants:
- Tom Lechner, Bin Lin
- http://www.cs.northwestern.edu/~bmd/cs211/
|
|
2
|
- #include <iostream>
- using namespace std;
- main() {
- int integer_temp = 1 + 1;
- cout << "1 + 1 =
" << integer_temp << "\n";
- float floating_point_temp;
- floating_point_temp = 1.414f;
- cout << "Root 2 =
" << floating_point_temp
- << "\n";
- }
|
|
3
|
- #include <cmath>
- #include <iostream>
- using namespace std;
- main() {
- double two = 2.0;
- cout << "Root 2.0 is: " << sqrt(two) <<
"\n";
- }
|
|
4
|
- #include <cmath>
- #include <iostream>
- using namespace std;
- main() {
- double two = 2.0;
- cout << "Root 2.0 squared is: "
- << sqrt(two) *
sqrt(two) << "\n";
- }
|
|
5
|
- #include <cmath>
- #include <iostream>
- using namespace std;
- main() {
- }
- // Coming from a Schemish perspective
- square(x) {
- x * x;
- }
|
|
6
|
- #include <cmath>
- #include <iostream>
- using namespace std;
- main() {
- }
- double square(double x) {
- return x * x;
- }
|
|
7
|
- #include <cmath>
- #include <iostream>
- using namespace std;
- main() {
- cout << "2.11 squared is: " << square(2.11)
- << "\n";
- }
- double square(double x) {
- return x * x;
- }
|
|
8
|
- #include <cmath>
- #include <iostream>
- using namespace std;
- double square(double x);
- main() {
- cout << "2.11 squared is: " << square(2.11)
- << "\n";
- }
- double square(double x) {
- return x * x;
- }
|
|
9
|
- #include <cmath>
- #include <iostream>
- using namespace std;
- double square(double x);
- int main() {
- double foo = 2.11;
- cout << "2.11 squared is: " << square(foo)
- << "\n";
- }
- double square(double x) {
- return x * x;
- }
|
|
10
|
- (define (fib n)
- (cond ((= n 0) 0)
- ((= n 1) 1)
- (else
- (+ (fib (- n 2))
- (fib (- n 1))))
- ))
|
|
11
|
- #include <iostream>
- using namespace std;
- int fib(int n) {
- if (n == 0) return 0;
- if (n == 1) return 1;
- return fib(n-2) + fib(n-1);
- }
- int main() {
- // call fib
- }
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
- C++ procedures
- Automatic storage
- Is automatically reclaimed after procedure returns
|
|
19
|
- Take aways
- Procedure invocation
- Procedure definition
- Procedure declaration
- Variables
- Scoping rules
- Storage rules
|