CS midterm Flashcards
1
Q
algorithm
A
- Specific set of instructions for carrying out a procedure or for solving a problem (anything trying to solve)
- Must produce a result
- Must be achievable/possible
- Must be expressed clearly
2
Q
algorithms typically (qualities)
A
Algorithms typically… • Make some assumptions • Have multiple solutions • Include decisions • Are expressed in modular pieces
3
Q
is ordering Chinese take-out an algorithm?
A
yes
4
Q
computer algorithm
A
“An algorithm is a well-ordered collection of unambiguous and effectively computable operations that when executed produces result and halts in a finite amount of time.”
- Algorithms are well ordered
- Have unambiguous operations
- Effectively computable operations
- Produce a result
- Finish in a finite amount of time
5
Q
programming errors
A
- Syntax Errors – spelled words wrong
- Runtime Errors – program error that occurs when program is running
- Logic Errors – something wrong with logic, produces the wrong output
6
Q
specify a location
A
- point(x, y)
* line x1, y1, x2, y2)
7
Q
function call statement
A
- point(40, 77); = statement
- Point = function name
- (40, 77) = arguments
- ; = terminator
8
Q
Coding Style when Calling Functions
A
- One space after commas in function arguments
- No space between function name and opening bracket
- No space before the semicolon at the end of a statement
- No space after opening bracket or before closing bracket
- point(10, 20);
9
Q
shapes
A
- triangle(x1, y1, x2, y2, x3, y3);
- 6 arguments
- quad(x1, y1, x2, y2, x3, y3, x4, y4);
- 8 arguments
- rect(x, y, width, height)
- ellipse(x, y, width, height)
- point xy in middle
- eg. ellipse(50, 50, 15, 15);
10
Q
commenting code
A
- Code comments provide information that is not otherwise available from reading from the code
- Often a message to your “future self”
- // comment
11
Q
bezier curves
A
•
bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2)
• eg. bezier(10, 10, 90, 20, 30, 80, 90, 90);
12
Q
attributes
A
- Eg. Once you set strokeWeight to 10, everything you draw after will have a strokeWeight of 10 until you change it again
- Order matters (Sequential Control flow)
- CMD + t will format code correctly
• size(); o changes size of drawing • noStroke(); o no border • noFill(); o nothing in the middle
13
Q
stroke weight
A
• strokeWeight(weight); o Effects everything that comes after the code • strokeJoin(join); o join = BEVEL, MITER, or ROUND • strokeCap(cap); o cap = SQUARE, PROJECT, or ROUND o Project extends stroke
14
Q
color
A
- Additive (“mixing all colours makes white”)
- RGB – used to specify colour on computer displays
- HSB – used to describe colour
- Subtractive (“mixing al colours makes black”);
- CMY/CMYK – common in printing
15
Q
active code
A
change things actively (draw)