Computer Science 50 Introduction to Computer Science I Harvard College

Walkthrough 2 Marta Bralic [email protected]

1

Design and Style Design •  • 

What is good design? Questions: •  •  • 

Is my code straightforward to read? Am I wasting CPU cycles unnecessarily? Is my code more complicated than it need be?

2

Design and Style Style •  • 

What is good style? Questions: • 

Comments • 

• 

Variable names • 

• 

Is it clear what I am doing at each major step? Is it clear what each variable represents?

Prettiness •  • 

Is no line longer than 80 characters? Did I indent uniformly? 3

Problem Set 2 Standard Edition • 

Old Man song • 

• 

Caesar cipher •  • 

• 

Repetition…design decisions galore Command line arguments Arrays

Vigenère cipher • 

Arrays of arrays

4

Old Man’s Song The Lyrics

This old man, he played one He played knick-knack on my thumb Knick-knack paddywhack, give your dog a bone This old man came rolling home This old man, he played two He played knick-knack on my shoe Knick-knack paddywhack, give your dog a bone This old man came rolling home
 5

oldman.c – several ways • 

printf the entire song • 

• 

loop •  • 

• 

bad design good design what kind?

how do we store changing parts? •  •  • 

array function + conditions other ways? 6

Caesar Cipher ci = (pi + k)% 26 p k c

7

Command Line Arguments • 

argc •  • 

• 

when is it 1? when is it 2?

argv[] •  • 

argv[0] argv[1]

8

caesar.c • 

ci = (pi + k)% 26 •  •  •  • 

what is p? what is k? what is % 26? what is c?

9

Tools •  •  •  •  •  •  •  • 

isdigit atoi GetString() strlen loop conditions ascii printf 10

Challenges • 

how do we preserve case?

• 

how do we leave spaces unchanged?

11

Vigenère Cipher ci = (pi + kj) % 26 H E L L O ,

W O

R

L

D

+ + + + +

+

+

+

+

+

k

F O O B A

R

F

O O

B

c

↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ MS Z MO , N

↓ T

↓ F

↓ E

p

↓ Z

12

Differences • 

key is alphabetical • 

•  • 

find key’s numerical value must know when to advance key • 

• 

use isalpha instead of isdigit

not on spaces

must worry about wrapping around key

13

Computer Science 50 Introduction to Computer Science I Harvard College

Walkthrough 2

Marta Bralic [email protected]

14

Computer Science 50 Walkthrough 2

This old man, he played one. He played knick-knack on my thumb. Knick-knack paddywhack, give your dog a bone. This old man came rolling home. This old ...

163KB Sizes 1 Downloads 335 Views

Recommend Documents

Computer Science 50 Walkthrough 2
This old man, he played one. He played knick-knack on my thumb. Knick-knack paddywhack, give your dog a bone. This old man came rolling home. This old man, he played two. He played knick-knack on my shoe. Knick-knack paddywhack, give your dog a bone.

Computer Science 50 Walkthrough 2
Computer Science 50. Introduction to Computer Science I. Harvard College. Marta Bralic [email protected]. Walkthrough 2 ...

CS 50 Walkthrough 5
A bitmap is a series of consecuûve pixels described after each other. • Also has “metadata” in first 54 bytes consisûng of two headers.

CS 50 Walkthrough 5
Data structures, hexadecimal, and pointers. • Programs: – whodunit. – resize. – recover ... Image recovery! ... Go through each block in the disk image and: 1.

CS 50 Walkthrough 5
Image recovery - Steps. • Steps: Go through each block in the disk image and: 1. If we find a JPEG signature, start wriûng the bytes out to another file. 2. If we find a new JPEG signature, close that old file and go back to 2. 3. If we find the E

CS 50 Walkthrough 6
Topics: – More data structures, more pointers. – More File I/O. • You implement: ... convert each le›er of word tolower. • hash word and go to that place in array.

CS 50 Walkthrough 6
create nodes for them. – put these nodes ... store each le›er i of the word in that node. • fgetc(dptr) is that ... put a pointer to your node that you just malloced there.

CS 50 Walkthrough 5 - CS50 CDN
A bitmap is a series of consecuûve pixels described after each other. • Also has “metadata” in first 54 bytes consisûng of two headers.

CS 50 Walkthrough 6 - CS50 CDN
Slow but simple: Linear search every fme. – don't do this! • Hash tables. • Tries ... easy if you've kept a counter that you increment every fme you load a word.

Computer Science 50 Fall 2010 Scribe Notes Week 0 Wednesday ...
Sep 1, 2010 - the order of a web search engine), how many steps would it take to find that one page we're looking for? Not as many as you might think: only.

Computer Science 50 Fall 2010 Scribe Notes Week 0 Wednesday ...
Another more intelligent approach would be to flip to the middle of the phonebook to ... oped by MIT's Media Lab to teach programming to children. ... flash drive.

Computer Science 50 Fall 2010 Scribe Notes Week 0 Wednesday ...
Sep 1, 2010 - the order of a web search engine), how many steps would it take to find that one page we're looking for? Not as many as you might think: only.

Computer Science 50 Fall 2010 Scribe Notes Week 1 Friday ...
links in the ncurses.h library, a graphic library for C. In step 3, we actually .... a problem in industries like finance or biology. ... Conditions take the following form in C: ..... Linux command called man that provides a manual page for any func

Computer Science 50 Fall 2010 Scribe Notes Week 2 ... - CS50 CDN
wrap around to positive 2 billion as it overflows its storage and the critical bit that designates its sign gets flipped. At that point, the program will stop executing ...

Computer Science 50 Fall 2010 Scribe Notes Week 2 ... - CS50 CDN
Terminal on a Mac or PuTTY on a PC. On a Mac, you'll type ssh [email protected],1 enter your password, and you'll be connected. On a PC, you'll open a ...

Computer Science 50 Fall 2010 Scribe Notes Week 3 Monday ...
David recently got an e-mail requesting that he provide his FAS username and password due to a server upgrade. He clicked on the link to do so and, to his ...

Computer Science 50 Fall 2010 Scribe Notes Week 3 Monday ...
Almost 200 of you have so-called normal phones (i.e. non-smartphones). By the way ... is for Android, BlackBerry, and iPhone apps come semester's end when.

Walkthrough 8
index.html – homepage. ▫ buildings.js – buildings in the game. ▫ houses.js – Harvard houses + locations. ▫ math3d.js – movement math. ▫ passengers.js – all the people in the game. ▫ service.css – appearance of the homepage. ▫

Walkthrough 8
Agenda. ▫ Distribution Code. ▫ HTML + CSS. ▫ Javascript. ▫ API's: Google Earth and Google Maps. ▫ Pickup. ▫ Dropoff. ▫ Choice of feature ...

Walkthrough 8
index.html – homepage. ▫ buildings.js – buildings in the game. ▫ houses.js – Harvard houses + locations. ▫ math3d.js – movement math. ▫ passengers.js – all the ...

CS50 Walkthrough 4
To Do. ▫ distribution code. ▫ ncurses. ▫ move cursor. ▫ allow changing user-added ... Allows you to change colors, ... g.board[g.y][g.x] is spot on board where.

Computer Science SQP (2015-16) Set 2 MS.pdf
Computer Science SQP (2015-16) Set 2 MS.pdf. Computer Science SQP (2015-16) Set 2 MS.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying ...

2 weeks 50% 2500 - Firebase
analyze that data in the cloud and deliver the analytics instantly to coaches. They originally ... Amazon Web Services (AWS), with Android and Node.js to deliver their analytics. This required ... testing software on the market. Thanks to Cloud ...

2 weeks 50% 2500 - Firebase
analyzed and made accessible in mobile and web apps in real time. The company serves customers in the NHL, NCAA, EPL and other leagues. Challenge ... With Firebase Realtime Database, we felt we had built the best force-plate.