Lecture 6/10: Wrap-up with CS 107 Preview


June 10, 2020

đź“‚Associated files

Course Wrap-up and CS 107 Preview

CS 106B: Programming Abstractions

Spring 2020, Stanford University Computer Science Department

Lecturers: Chris Gregg and Julie Zelenski

The Stanford Campus


Slide 2

Today's Topics


Slide 3

Where we have been


Slide 4

Where we have been

animation of BFS search on maze

Stand by while building index...
Indexed 50 pages containing 5595 unique terms.

Enter query sentence (RETURN/ENTER to quit): llama
Found 1 matching pages 
{"http://cs106b.stanford.edu/assignments/assign2/searchengine.html"}

Enter query sentence (RETURN/ENTER to quit): suitable +kits
Found 2 matching pages 
{"http://cs106b.stanford.edu/assignments/assign2/searchengine.html", "http://cs106b.stanford.edu/qt/troubleshooting.html"}

Slide 5

Where we have been

sierpinski triangles of orders 0 -4


Slide 6

Where we have been

Block Block Count
Lions 50
Tigers 49
Bears 1

Slide 7

Where we have been

                   8 
             /            \ 
            9               11     
        /      \         /      \
      12       10       13       14 
     /  \      /  \    /  \     /   \
    22   43   __  __  __  __   __   __

Slide 8

Where we have been

A labyrinth diagram consisting of 16 cells arranged in a 4 by 4 grid. The cells from left to right and top to bottom have the following locations contents and links:  r0c0-empty-(link to south) r0c1-empty-(link to south and east) r0c2-wand-(link to west) r0c3-empty-(link to south) r1c0-empty-(link to north) r1c1-empty-(links to north,west,south) r1c2-empty-(link to south) r1c3-empty-(link to north and south) r2c0-spellbook-(link to south) r2c1-empty-(link to north and east) r2c2-smiley face-(links in all directions) r2c3-empty-(links to north,west,south) r3c0-empty-(links to north and east) r3c1-empty-(links to east and west) r3c2-empty-(links to north and west) r3c3-potion-(link to north)


Slide 9

Where we have been


Slide 10

I briefly showed you this program in the first lecture:

// Populate a Vector

// headers:
#include <iostream>
#include "console.h" // Stanford library
#include "vector.h" // Stanford library

using namespace std;

const int NUM_ELEMENTS = 100000;

// main
int main()
{
    Vector<int> myList;
    cout << "Populating a Vector with even integers less than "
         << (NUM_ELEMENTS * 2) << endl;

    for (int i=0; i < NUM_ELEMENTS; i++){
        myList.add(i*2);
    }

    for (int i : myList) {
        cout << i << endl;
    }
    return 0;
}

Slide 11

The Importance of Data Structures


Slide 12

The Importance of Data Structures

Computer Science is embarrassed by the computer.
– Alan Perlis

Structure         Overall(s)
Unsorted Vector:  1.45973
Linked List:      8.17542
Binary Tree:      0.02734
Hash Table:       0.01316
Sorted Vector:    0.22202

Slide 13

The Importance of Data Structures

Structure         Overall(s)    Insert(s)     Search(s)     Delete(s)
Unsorted Vector:  1.45973       0.00045       0.92233       0.53694
Linked List:      8.17542       0.00688       5.92075       2.24779
Binary Tree:      0.02734       0.02415       0.00199       0.00120
Hash Table:       0.01316       0.01116       0.00088       0.00112
Sorted Vector:    0.22202       0.14747       0.00206       0.07248

Slide 14

Where to from here?


Slide 15

CS 103


Slide 16

CS 107


Slide 17

How to Prepare for CS107


Slide 18

How to log into the myth machines


Slide 19

Editor Choices


Slide 20

How to prepare for CS107: Pointers


Slide 21

C / C++ Differences


Slide 22

Going from C++ to C


Slide 23

From C++ to C


Slide 24

From C++ to C

malloc() and free(), and sizeof(): used for memory management instead of new and delete

malloc() is used to reserve memory from the heap. You must pass it the size in bytes of the amount of memory you want. How do you know the size in bytes? You use sizeof():


Slide 25

Pointer arithmetic


Slide 26

printf

d or i Signed decimal integer 392
u Unsigned decimal integer 7235
o Unsigned octal 610
x Unsigned hexadecimal integer 7fa
X Unsigned hexadecimal integer (uppercase) 7FA
f Decimal floating point, lowercase 392.65
F Decimal floating point, uppercase 392.65
e Scientific notation (mantissa/exponent), lowercase 3.9265e+2
E Scientific notation (mantissa/exponent), uppercase 3.9265E+2
g Use the shortest representation: %e or %f 392.65
G Use the shortest representation: %E or %F 392.65
a Hexadecimal floating point, lowercase -0xc.90fep-2
A Hexadecimal floating point, uppercase -0XC.90FEP-2
c Character a
s String of characters sample
p Pointer address b8000000
n Nothing printed.
The corresponding argument must be a pointer to a signed int.
The number of characters written so far is stored in the pointed location.
 
% A % followed by another % character will write a single % to the stream. %

Slide 27

More printf examples

#include <stdio.h>
int main()
{
   printf ("Characters: %c %c \n", 'a', 65);
   printf ("Decimals: %d %ld\n", 1977, 650000L);
   printf ("Preceding with blanks: %10d \n", 1977);
   printf ("Preceding with zeros: %010d \n", 1977);
   printf ("Radices: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
   printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
   printf ("Width trick: %*d \n", 5, 10);
   printf ("%s \n", "A string");
   return 0;
}

Output:

Characters: a A
Decimals: 1977 650000
Preceding with blanks:       1977
Preceding with zeros: 0000001977
Radices: 100 64 144 0x64 0144
floats: 3.14 +3e+000 3.141600E+000
Width trick:    10
A string

Slide 28

Going from C++ to C (example from before)


Slide 29

Other courses to consider taking: CS107e

An image of a project from CS107e


Slide 30

Other courses to consider taking: CS109

An image of a robot reading a book, and an image of Asst. Professor Chris Piech


Slide 31

Computer Science Affects Every Field

Six images: a doctor performing surgery, a satellite, Elsa from Frozen, a self-driving car, and a contact lens with a circuit built into it


Slide 32

Courses aren't necessary to continue your learning!


Slide 33

It is the time and place for computer science

Self driving Delorean from Stanford Source


Slide 34

Thank you!