Computer Science I: guide to midterm quiz

  1. Draw a diagram for a standard computer (CPU, main memory, etc.).
  2. Draw a diagram showing layers of software for Processing (PDE, Java, etc.).
  3. Sketch the results of the following code (label coordinates, colors):
    void setup() {
    size(900,600); }
    void draw() {
    fill(0,250,0);
    rect(200,400,100,150);
    fill(0,0,250);
    ellipse(10,10,300,200); }
  4. What does the following line of code do (describe and sketch):
    arc(100,200,50,50,QUARTER_PI,PI);
  5. Write an assignment statement and describe what an assignment statement does.
  6. Contrast what a single = sign does versus what == does.
  7. What does the following code do (what are the values of eyeleftx and eyerightx)?
    int facex = 100;
    int eyeXoffset = 20;
    int eyeleftx = facex – eyeXoffset;

int eyerightx = facex+eyeXoffset;

  1. Sketch the results of the following code (label coordinates, colors):
    int rect1x = 210;
    int rect1y = 500;
    int ellipsew = 350;
    int ellipseh = 180;
    void setup() {
    size(600,400); }
    void draw() {
    fill(0,250,0);
    rect(rect1x,rect1y,100,150);
    fill(0,0,250);
    ellipse(10,10,ellipsew,ellipseh); }
  2. Sketch the results of the following code (label coordinates, colors);
    grade = 88;
    if (grade >65) {
    fill(200,0,200);
    ellipse(100,100,200,200); }
    else {
    fill(0,250,0);
    ellipse(500,10,100, 400); }
  3. What are datatypes? Describe at least 3 different datatypes, with examples.
  4. What is the binary number 111 in decimal? What is the decimal number 512 in binary?
  5. Look at the following code. Assume coinh and coint hold images of head and tail coin faces. There are errors in the code. Indicate the errors and describe which are syntactic errors and which are semantic errors.
    void mouseReleased() {

background(255,); //change background to white

if (.5<random(1)){

image(coinh,mouseX,mouseY,100,100);

tailc = headc+1;

}

else {

image(coint,mouseX,mouseY,100,100);

tailc = tailc+1;

}

fill(0,0,240); //change color of text to blue

text("Heads ",1020);

text(headc,10,50);

text(" Tails ",80,20);

text(tailc,80,50);

}

  1. What does frameRate(30); do?
  2. What is the use of a tolerance or margin variable in an application?
  3. Describe two ways to speed up an animation involving moving an object deltax and deltay each frame.
  4. What does random(n); do?
  5. When is the built-in method mouseReleased invoked?
  6. Describe what each line of code does and describe what is printed.
    int[] grades = {70,88,94};

void setup(){

size(500,400);

noLoop();

}

void draw(){

println(grades[1]);

}

  1. What does a class definition do? Describe the role of constructor methods and other methods.
  2. Describe (briefly) Charles Babbage and Ada Lovelace, Alan Turing, or Grace Murray Hopper. When did they live and what is their significance in the history of computing?