Notes
Slide Show
Outline
1
CS 211:
Introduction to Computer Programming II
  • Instructor: Brian M. Dennis
  • Teaching Assistants:
  • Tom Lechner, Bin Lin
  • http://www.cs.northwestern.edu/~bmd/cs211/


2
A Simple C++ program
  • #include <iostream>
  • using namespace std;


  • // HelloWorld programs originated with the
  • // book “The C Programming Language”


  • main() {
  • cout << “Hello, World\n”;
  • }


3
Scheme Equivalent
  • ;; HelloWorld programs originated with the
  • ;; book “The C Programming Language”
  • (display “Hello World”)
  • (newline)



4
 
5
 
6
 
7
 
8
Slightly More Complex
  • #include <iostream>
  • using namespace std;


  • main() {
  • cout << “The answer to the universe\n”
  • << 42;
  • }
9
A New Literal Datatype
  • #include <iostream>
  • using namespace std;


  • main() {
  •   cout << “Pi is: “ << 3.14159f << “\n”;
  • }
10
Some Arithmetic
  • #include <iostream>
  • using namespace std;


  • main() {
  •  cout << “1 + 1 = “ << 1 + 1 << “\n”;
  •  cout << “2 * 2 = “ << 2 * 2 << “\n”;
  •  cout << “3 – 5 = “ << 3 – 5 << “\n”;
  •  cout << “11 / 2 = “ << 11 / 2 << “\n”;
  • }
11
Conditional
  • #include <iostream>
  • using namespace std;


  • main() {
  •   if ((10 % 2) == 0)
  •     cout << “10 is even\n”;


  •   if (5 % 2)
  •     cout << “5 is odd\n”;


  •   if ((5 % 2) != 0)
  •    cout << “5 is odd\n”;
  • }
12
Variables
  • #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”;
  • }
13
Scheme Equivalent
  • (let ((integer_temp (+ 1 1))
  •       (floating_point_temp 1.414))
  •   (display “1 + 1 = “)
  •   (display integer_temp)
  •   (newline)
  •   (display “Root 2 = “)
  •   (display floating_point_temp)
  •   (newline)
  • )
14
Slightly tweaked
  • (let ((temp (+ 1 1)))
  •   (display “1 + 1 = “)
  •   (display temp)
  •   (newline)
  •   (set! temp 1.414)
  •   (display “Root 2 = “)
  •   (display temp)
  •   (newline)
  • )


15
Variables
  • #include <iostream>
  • using namespace std;


  • main() {
  •  int temp =  1 + 1;
  •  cout << “1 + 1 = “ << temp << “\n”;


  •  temp = 1.414;
  •  cout << “Root 2 = “ << temp << “\n”;
  • }
16
That’s a Wrap
  • Reading
  • SICP
    • CH 1
    • D&D Ch1
      • 1.14, 1.19 – 1.25