this is cs 50. harvard college’s introduction to computer ... · variables scratch v. c. z 35...

36
z This is CS 50. COMPUTER SCIENCE 50 Harvard College’s Introduction to Computer Science I 1 DAVID J. MALAN ’99 [email protected] WEEK 0

Upload: others

Post on 01-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

zThis is CS 50.

COMPUTER SCIENCE 50Harvard College’s Introduction to Computer Science I

1

DAVID J. MALAN ’[email protected]

WEEK 0

Page 2: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

2

Algorithms1 let socks_on_feet = 02 while socks_on_feet != 23 open sock drawer4 look for sock5 if you find a sock then6 put on sock7 socks_on_feet++8 look for matching sock9 if you find a matching sock then10 put on matching sock11 socks_on_feet++12 close sock drawer13 else14 remove first sock from foot15 socks_on_feet--16 else17 do laundry and replenish sock drawer

Page 3: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

3

#include  <stdio.h>

intmain(int  argc,  char  *argv[]){        printf("O  hai,  world!\n");}

O hai, C!hai.c

Page 4: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

4

O hai, C!

10000011 00000001 00010001 00000000 00111101 11111100 01110100 0011110100000000 01000000 00000000 00000000 00000000 00000000 00000000 0000000010010000 00000000 00000000 00000000 01010000 00000000 00000111 0011000000001011 00000001 00001011 00000011 00001010 00000000 00000000 0000000000000000 00100000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00100000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 00000000 0000000001110000 00010000 00000000 00100000 00000001 00000000 00000000 0000000000000000 00000000 00000000 00100000 00000001 00000000 00000000 0000000000000000 00000000 00000000 01000000 00000001 00000000 00000000 0000000000000000 00100000 00000000 01000000 00000001 00000000 00000000 0000000011111111 11111111 11111111 11111111 11111111 11111111 11111111 1111111110010000 10000000 00000000 01000000 00000001 00000000 00000000 0000000000101110 01100100 01111001 01101110 01100001 01101101 01101001 0110001110110000 00000100 00000000 00100000 00000001 00000000 00000000 0000000010110000 00000100 00000000 00100000 00000001 00000000 00000000 0000000010100000 00000001 00000000 00000000 00000000 00000000 00000000 0000000010110000 00000100 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00100000 00000000 00000000

[...]

#include  <stdio.h>

intmain(int  argc,  char  *argv[]){        printf("O  hai,  world!\n");}

Page 5: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

5

O hai, Scratch!Hai1.sb

Page 6: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

6

Statements

...

Page 7: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

7

StatementsHai{2,3}.sb

Page 8: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

8

Boolean Expressions

...

Page 9: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

9

Conditions

...

Page 10: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

10

ConditionsHai{4,5}.sb

Page 11: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

11

Loops

Page 12: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

12

LoopsHai{6,7,8}.sb

Page 13: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

13

VariablesCount{1,2}.sb

Page 14: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

14

Arrays

Page 15: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

15

ArraysFruitcraftRPG.sb

Page 16: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

16

ThreadsMove1.sb

Page 17: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

17

ThreadsMove2.sb

Page 18: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

18

ThreadsHai10.sb

Page 19: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

19

ThreadsDavid.sb

Page 20: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

20

EventsMarco.sb

Page 21: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

21

Sensorssinger.sb, Masquerade.sb, davidwu.sb

Page 22: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

22

OscartimeOscartime.sb

Page 23: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

23

OscartimeDisplaying the instructions

Page 24: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

24

OscartimeMaking trash fall

Page 25: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

25

OscartimeImplementing dragging

Page 26: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

26

OscartimeImposing a time limit

Page 27: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

27

OscartimeKeeping score

Page 28: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

28

OscartimeRaising Oscar’s lid

Page 29: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

29

intmain(int  argc,  char  *  argv[]){        printf("O  hai,  world!\n");}

Scratch Meets C

Page 30: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

30

printf("O  hai,  world!\n");

StatementsScratch v. C

Page 31: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

31

(x  <  y)((x  <  y)  &&  (y  <  z))

Boolean ExpressionsScratch v. C

Page 32: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

32

if  (x  <  y){        printf("x  is  less  than  y\n");}else  if  (x  >  y){        printf("x  is  greater  than  y\n");  }else{  printf("x  is  equal  to  y\n");}

ConditionsScratch v. C

Page 33: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

33

while  (1){        printf("O  hai!\n");}

for  (int  i  =  0;  i  <  10;  i++){        printf("O  hai!\n");}

LoopsScratch v. C

Page 34: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

34

int  counter  =  0;while  (1){        printf("%d\n",  counter);        counter++;}

VariablesScratch v. C

Page 35: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

z

35

char  *inventory[SIZE];inventory[i]  =  "Orange";

ArraysScratch v. C

Page 36: This is CS 50. Harvard College’s Introduction to Computer ... · Variables Scratch v. C. z 35 char*inventory[SIZE]; inventory[i]="Orange"; Arrays Scratch v. C. 36 kthxbai. Created

36

kthxbai