Studying for the Midterm

< CS101

This page has information about the midterm exam and some sample problems to work. There are several old midterms linked off our course page as a source of practice problems. The exam will be in our regular room Thu April 28th at our regular class time. The exam will be 50 minutes. (Previously it was 60 minutes, but everyone left early, so I'm taking back 10 minutes.)

Midterm TA hours: if you have any questions, Sarah Sterman has special midterm hours this week: Wed 3:00-5:00 Lathrop Library Tech Lounge, instead of her regular Fri hours.

The exam will be closed-note, closed everything: no notes, no computer, no cell phone, no calculator. Just bring yourself and a pen or pencil and that's it.

Closed note exams sound scary, but actually they are great, provided the instructor does not ask lame questions. The nice thing about closed note exams is that they do not require weird questions. CS101 exam questions will be variations of the homework problems. If you do not want to do the arithmetic for an short-answer question, you can write an answer as an expression like "5.5 * 100 / 2" and we will do the arithmetic for you when grading. That said, the arithmetic will tend to be easy enough that you can do it in your head anyway.

The exam will have a few short answer questions from the lecture topics we have had this far: hardware, software, analog-digital. Last year there was some networking on the exam, but we have not covered that this year yet. The rest of the exam will have questions where you write code to solve something, very much like the homeworks. Indeed, when creating the exam, I will start with the homework and lecture problems for inspiration.

Writing code on a piece of paper is different from typing code into the computer, and our grading criteria take that into account. We do not grade off for trivial syntax errors that you would easily catch when running on the computer. So if you write poxel.setReed(4); or omit one parenthesis or comma or something, you'll still get full credit, so long as the key ideas of the solution are there and we can see what you meant. You can omit the bluescreen "* 1.1" factors we had for real code, since those make no sense on paper.

The exam will contain the "cheat sheet" below listing the major phrases of syntax we have used, so you don't need to memorize those details. The points on the exam will come from using the syntax to solve little problems, just like the homework. If a question requires a little boilerplate code at the start, often the question will include that code already done, and the points will be from writing the rest of the required code (as on the homework).

How To Study

It's too easy to just sweep your eye over the solution. That's not the way to study. You need to actively try to do the problems starting with a blank piece of paper.

You should practice enough to be comfortable writing code starting with a blank piece of paper for all the homework problems and all the lecture code examples we have run (all on the course page). You should be able to scroll down to a lecture example or homework problem, and type in a pretty good solution just from reading the description, without needing to refer to any example code. This is a higher bar than the homeworks, where you very likely scrolled back to remind yourself from earlier examples. Though the exam problems are non-trivial, they are well structured for practice.

Code Reference

Code reference "cheat sheet" to be printed with exam:

// Basic image for-loop example
image = new SimpleImage("something.jpg");
for (pixel: image) {
  pixel.setRed(0);
}
print(image);


// If-Statement example:
if (100 > 50) {
  // body lines
}

Functions:
-pixel.setRed(val)  // likewise for green and blue
-pixel.getRed()     // likewise for green and blue
-pixel.getX(), pixel.getY()
-image.getWidth(), image.getHeight()
-image.getPixel(x, y)
-image.setAsBig(other_image)
 

The lecture example and homework problems are an excellent source of practice problems. Here are some sample problems that cover some of the techniques we have seen.

Practice Short Answer

Number of bits in a byte: _______

Sally has 2.8 gigabytes. Bobby has 500 megabytes. Added together they have about how much in GB? : _________

Machine code is a language implemented by what piece of hardware:_____

Problem 1

Write code that prints the following with your name.

My name is Alice
Alice is in this class

Rather than mentioning your name directly, assign a variable to hold your name (i.e. name = ... ; ), then use that name variable within the print statements to insert your name.

Problem 2

This is a 10-20-30 puzzle. Write code to solve this puzzle -- for each pixel, multiply red by 20, green by 10, and blue by 30. You may omit the final print().

Problem 3

This is a bluescreen problem. Write code that for each pixel, in "image", if the red value is greater than 100, copy over the analogous pixel from the "back" image. Note that we are not using the more sophisticated "avg" technique here. You may omit the final print().

Problem 4

Write code to make the following changes to an image, such as "flowers.jpg". For each pixel, if the green value is more than double the blue value, double the blue value, and set the red value to 100. The standard line to load the image is provided. You may omit the final print().

Solutions

Short answer: 8 bits in a byte.
2.8 GB + 500 MB is about 3.3 GB.
Machine code is implemented by the CPU.

1.
x = "Alice";
print("My name is", x);
print(x, "is in this class");


2.
for (pixel: image) {
  pixel.setRed(pixel.getRed() * 20);
  pixel.setGreen(pixel.getGreen() * 10);
  pixel.setBlue(pixel.getBlue() * 30);
}

3.
for (pixel: image) {
  if (pixel.getRed() > 100) {
    pixel2 = back.getPixel(pixel.getX(), pixel.getY());
    pixel.setRed(pixel2.getRed());
    pixel.setGreen(pixel2.getGreen());
    pixel.setBlue(pixel2.getBlue());
  }
}


4. 
for (pixel: image) {
  if (pixel.getGreen() > pixel.getBlue() * 2) {
    pixel.setBlue(pixel.getBlue() * 2);
    pixel.setRed(100);
  }
}