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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

algorithms typically (qualities)

A
Algorithms typically…
•	Make some assumptions
•	Have multiple solutions
•	Include decisions
•	Are expressed in modular pieces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

is ordering Chinese take-out an algorithm?

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.”

  1. Algorithms are well ordered
  2. Have unambiguous operations
  3. Effectively computable operations
  4. Produce a result
  5. Finish in a finite amount of time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

specify a location

A
  • point(x, y)

* line x1, y1, x2, y2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

function call statement

A
  • point(40, 77); = statement
  • Point = function name
  • (40, 77) = arguments
  • ; = terminator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

bezier curves

A

bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2)

• eg. bezier(10, 10, 90, 20, 30, 80, 90, 90);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

active code

A

change things actively (draw)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

functions

A
•	Code that is “packaged” so it can be run “by name”
•	Often performs some computation and returns a value (but not always)
•	We used functions all the time in Processing…
o	noFill();
o	ellipse(75, 50, 23, 52);
17
Q

function defintion

A
•	void draw() {
•	ellipse(moouseX, mouseY, 30, 30);
•	}
o	void = function return type
o	draw = function name
o	() function parameters
o	{} code block
18
Q

active vs static mode

A

• We have been writing code in static mode:
o Our drawing is only shown when the program finishes
o There is no user input
o We can’t define any functions
• From now on, we’re using active mode:
• “active mode” is also called “dynamic mode”
o People can interact with our program
o Drawings can be “updated” to make animation
o We can define functions
o With setup() and draw() functions

19
Q

set up

A
  • void setup() {
  • size(200, 200);
  • backround(255); // white
  • noStroke();
  • }
20
Q

static mode

A
  • size(200, 200);

* ellipse(mouseX, mouseY, 30, 30);

21
Q

active mode

A
  • void setup() {
  • size(200, 200);
  • }
  • void draw() {
  • ellipse(mouseX, mouseY, 30, 30);
  • }
22
Q

other functions

frame rate

A
•	frameRate(1); // 1 frame per second
o	Draws very slow
•	printLn(“setup”)
o	Prints lines in the bottom of Processing in Console
o	Used to find errors
23
Q

event

A
  • An observable occurance, phenomenon, or an extraordinary occurrence
  • A message to notify an application that something happened
  • Ex. Keyboard (key press, key release), Mouse Events (button press, button release, moved)
24
Q

setup and draw are events

A
•	The setup event happens when the program is first run
o	setup() is a built-in function that represents this event
•	The draw event happens 60 times per second (by default)
o	draw() is a built-in function that represents this event
25
Q

mousePressed event

A

• A mousePressed event happens when a mouse button is pressed/touch pad tapped
o void mousePressed() {
o }
• Also a mouseReleased event

26
Q

keyPressed event

A

• A keyPressed event happens when a key is pressed
o void keyPressed() {
o }
• Also a keyReleased event

27
Q

variables

A

• Symbolic name used to reference an “unknown” value
• Value may change, but the symbolic name doesn’t
• Kinds of Variables:
o Built-in variables (eg. mouseX, width)
o Constants (CENTER, BEVEL)
o User defined variables

28
Q

useful processing built in variables

A
•	Mouse X, mouse Y
•	pmouseX, pmouseY (p = previous)
•	width, height
•	frameCount, framerate
•	key, keyCode
•	mouseButton
o	keyPressed, mousePressed
o	NOTE: different than the event functions with the same names!!!!