CS50 Week 0
What is computer science?
Computer science is fundamentally problem solving, but we’ll need to be precise and methodical.
We can think of problem solving as the process of taking some input (a problem we want to solve) and generate some output (the solution to our problem).
Representing numbers
Decimal system: 10 digits, 0 through 9
Binary system: two digits, 0 and 1 (computer using)
- Each binary digit is also called a bit.
- In binary, with just two digits, we have powers of two for each place value:
- Most computers use 8 bits at a time
- 8 bits = 1 byte
Text
The standard mapping, ASCII
Unicode: uses more bits than ASCII to accommodate characters, such as letters with accent marks and symbols in other languages.
emoji: based on the Unicode standard
different companies that create software for their devices will have slightly different images that represent each emoji, since only the descriptions have been standardized.
- For example, the “face with medical mask” 11110000 10011111 10011000 10110111
- For example, the “face with medical mask” 11110000 10011111 10011000 10110111
Images, video, sounds
We just came up with some convention for representing.
Color: RGB( common system that we are using)
Image: made up of many thousands or millions of pixels( The dots, or squares, on our screens)
three bytes to represent the color for each pixel
Video:sequences of many images, changing multiple times a second to give us the appearance of motion, as a flipbook might.
Music: represented by MIDI format.
Algorithms
- The black box that transforms inputs to outputs contains algorithms, step-by-step instructions for solving problems:
Pseudocode
Pseudocode: a representation of our algorithm in precise English (or some other human language):
- Pick up phone book
- Open to middle of phone book
- Look at page
- If person is on page
- Call person
- Else if person is earlier in book
- Open to middle of left half of book
- Go back to line 3
- Else if person is later in book
- Open to middle of right half of book
- Go back to line 3
- Else
- Quit
Functions: actions or verbs that solve smaller problems
- Pick up phone book
- Open to middle of phone book
- Look at page
- If person is on page
- Call person
- Else if person is earlier in book
- Open to middle of left half of book
- Go back to line 3
- Else if person is later in book
- Open to middle of right half of book
- Go back to line 3
- Else
- Quit
Conditionals: branches that lead to different paths, like forks in the road.
- Pick up phone book
- Open to middle of phone book
- Look at page
- If person is on page
- Call person
- Else if person is earlier in book
- Open to middle of left half of book
- Go back to line 3
- Else if person is later in book
- Open to middle of right half of book
- Go back to line 3
- Else
- Quit
Boolean expressions:the questions that decide where we go, which eventually result in answers of yes or no, or true or false.
- Pick up phone book
- Open to middle of phone book
- Look at page
- If person is on page
- Call person
- Else if person is earlier in book
- Open to middle of left half of book
- Go back to line 3
- Else if person is later in book
- Open to middle of right half of book
- Go back to line 3
- Else
- Quit
Loops:words that create cycles, where we can repeat parts of our program.
- Pick up phone book
- Open to middle of phone book
- Look at page
- If person is on page
- Call person
- Else if person is earlier in book
- Open to middle of left half of book
- Go back to line 3
- Else if person is later in book
- Open to middle of right half of book
- Go back to line 3
- Else
- Quit
Scratch
- Scratch: graphical programming language, where we’ll drag and drop blocks that contain instructions.
- Scratch categorizes its pieces, each of which might be a function, conditional, or more:
- Motion: move
- Events: blocks will activate when something happens
- Control: only do something if the Boolean expression inside is true
- Sensing: includes those Boolean expressions, or questions like whether the sprite is touching the mouse pointer
- Operators: contains blocks that let us do math or pick random numbers, or combine multiple Boolean expressions
- Variables: will let us store values like words or numbers, and save them with names like x, y, or other full words to describe them.
- My Blocks: combine multiple blocks ourselves into a new puzzle piece, or function
本博客所有文章除特别声明外,均采用