Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Week 1

Q1
1/1 point (graded)

Change the "print" code below so it produces the following output when
run:

1 2 hello

Q2
1/1 point (graded)

Change the "print" code below so it produces the following output when
run:

1
12
123

print(1)

print(1,2)

print(1,2,3)

Q1
1/1 point (graded)

Change just one line of the code below so it produces the following output
when run.

xyz123
xyz123 xyz123
xyz123 xyz123 xyz123
print("xyz123")

print("xyz123","xyz123")

print("xyz123","xyz123","xyz123")

Q1
1/1 point (graded)
How many colors can a single pixel show at one time?

correct
1
Q2
1/1 point (graded)
In the RGB scheme, what are the RGB numbers to make pure white?
Please type in the red, green, and blue numbers separated by spaces like
this: 100 126 255

255 255 255

Q3
1/1 point (graded)
What are the RGB numbers to make bright yellow? (Please type in the red,
green, and blue numbers separated by spaces like this: 100 126 255)

255 255 0

Q1
1/1 point (graded)
Write code to set the pixel at (0, 0) to blue (i.e. blue value is 255, red and green
are left at 0).

image = new SimpleImage("x.png");

image.setZoom(20);

pixel = image.getPixel(0, 0);

pixel.setRed(0);

pixel.setGreen(0);

pixel.setBlue(255);

print(image);

Q2
1/1 point (graded)
Write code to set the pixel at (0, 0) to be violet (i.e. red and blue both 255,
green left at 0).

image = new SimpleImage("x.png");

image.setZoom(20);

pixel = image.getPixel(0, 0);

pixel.setRed(255);

pixel.setGreen(0);

pixel.setBlue(255);

print(image);

Q3
1/1 point (graded)
Write code to set the pixel at (1, 0) to be red.

image = new SimpleImage("x.png");

image.setZoom(20);
pixel = image.getPixel(1, 0);

pixel.setRed(255);

pixel.setGreen(0);

pixel.setBlue(0);

print(image);

Week 2:
Q1
1/1 point (graded)

Add code inside the loop to modify flowers.jpg like this: set each pixel to
have green of 0, leaving the red and blue values unchanged. The result
should be that the flowers look red, since the yellow was made of
red+green light.

image = new SimpleImage("flowers.jpg");


for (pixel: image) {
// Your code here
pixel.setGreen(0);
}
print(image);
Q2
1/1 point (graded)
Add code inside the loop to modify flowers.jpg like this: set each pixel to have
red 255, green 0, blue 0.

image = new SimpleImage("flowers.jpg");


for (pixel: image) {
// Your code here
pixel.setRed(255);
pixel.setGreen(0);
pixel.setBlue(0);
}
print(image);

Q1
1/1 point (graded)

Write code to fix the 51020-poppy.png image which should show an


orange California Poppy in the foreground (the California state flower!).
The background is mostly green with some in the upper-right.
image = new SimpleImage("51020-poppy.png");

for (pixel: image) {

// Your code here

pixel.setRed(pixel.getRed()*10);

pixel.setGreen(pixel.getGreen()*5);

pixel.setBlue(pixel.getBlue()*20);

print(image);

Q2
1/1 point (graded)

Write code to fix the 51020-stop-sky.png image which should show a red
stop sign front with a background of a light blue sky and green tree
leaves.

image = new SimpleImage("51020-stop-sky.png");

for (pixel: image) {


// Your code here
pixel.setRed(pixel.getRed()*20);
pixel.setGreen(pixel.getGreen()*10);
pixel.setBlue(pixel.getBlue()*5);

print(image);
Q3
1/1 point (graded)
Write code to fix the 51020-oranges.png image which should show a box of
oranges. The box itself is dull gray. The sign on the box is black, with "organic"
written in light orange, and the rest of the letters in white.
image = new SimpleImage("51020-oranges.png");

for (pixel: image) {


// Your code here
pixel.setRed(pixel.getRed()*20);
pixel.setGreen(pixel.getGreen()*5);
pixel.setBlue(pixel.getBlue()*10);

print(image);

Q1 Iron Puzzle
1/1 point (graded)
Write code to fix the puzzle-iron.png image. The red and green values in the
image are random noise, so they should be set to 0. The real image is in the
blue values, which have been divide by 10. The "solution" image will look blue,
since it is exclusively in the blue values, so don't worry about that. We'll see a
way to fix that blueness in a later section.
image = new SimpleImage("puzzle-iron.png");

for (pixel: image) {


// Your code here
pixel.setGreen(0);
pixel.setRed(0);
pixel.setBlue(pixel.getBlue()*10);

print(image);
Q2 Copper Puzzle
1/1 point (graded)
Write code to fix the puzzle-copper.png image. The red values in the image are
random noise, so they should be set to 0. The real image is in the blue and
green values, which have been divide by 10.
image = new SimpleImage("puzzle-copper.png");

for (pixel: image) {


// Your code here
pixel.setGreen(pixel.getGreen()*10);
pixel.setRed(0);
pixel.setBlue(pixel.getBlue()*10);
}

print(image);
Q1
1/1 point (graded)
The image below, golden-gate-red.jpg, shows the golden gate bridge, but all of
the data is in the red values.
Write code that for each pixel copies the red value over to be the green and blue
value. The result will be to change the image to grayscale which will look better.
image = new SimpleImage("golden-gate-red.jpg");

for (pixel: image) {


// Your code here
pixel.setGreen(pixel.getRed());
pixel.setBlue(pixel.getRed());

}
print(image);
Q2
1/1 point (graded)
Here is the banana.jpg image:

Write code to change the banana.jpg image to be grayscale. Reminder:


here is the line used in the loop to compute the average of the
red/green/blue values and store that value in a variable named "avg".

avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;


image = new SimpleImage("banana.jpg");

for (pixel: image) {


// Your code here
avg=(pixel.getRed()+pixel.getGreen()+
pixel.getBlue())/3;
pixel.setGreen(avg);
pixel.setBlue(avg);
pixel.setRed(avg);

week 3
Q1
1/1 point (graded)

Here is the fence-ivy.jpg image:

Write code that picks out the pixels of the green leaves in the image (using the
> avg * factor technique, as in lecture). For each green pixel identified, set its
green value to 0. The result is that the green leaves are changed to a sort of
weird purple color, since setting green to 0, we just have red and blue
contributing.

image = new SimpleImage("fence-ivy.jpg");

for (pixel: image) {

// Your code here

avg=(pixel.getRed()+pixel.getGreen()+

pixel.getBlue())/3;

if(pixel.getGreen()>avg*1.1){

pixel.setGreen(0);

print(image);

Q2
1/1 point (graded)

Here is the stop.jpg image:

For the stop.jpg image, write code that picks out the blue sky (using the > avg *
factor technique, as in lecture). Change the blue pixels to be red=20 green=20
blue=20 .. so it looks like nighttime. Adjust your code so it changes the sky, but
not the white letters in the sign (which are technically a little blue).

image = new SimpleImage("stop.jpg");

for (pixel: image) {

// Your code here


avg=(pixel.getRed()+pixel.getGreen()+

pixel.getBlue())/3;

if(pixel.getBlue()>avg*1.1){

pixel.setBlue(20);

pixel.setGreen(20);

pixel.setRed(20);

print(image);

Q3
1/1 point (graded)

Here is the curb.jpg image:

The goal for this problem is to change the curb to look blue. Detect the red
pixels of the curb using the avg technique. For each pixel, change its red and
green values to be half the average value, and change its blue value to 1.2 times
the average value. In effect, this sets red and green low and blue high, making it
look kind of blue. Note that the blue effect will apply to the reddish plants off to
the right as well -- now they are blueish plants.

image = new SimpleImage("curb.jpg");

for (pixel: image) {

// Your code here

avg=(pixel.getRed()+pixel.getGreen()+

pixel.getBlue())/3;

if(pixel.getRed()>avg*1.1){

pixel.setBlue(1.2*avg);

pixel.setGreen(0.5*avg);

pixel.setRed(0.5*avg);

Q1
1/1 point (graded)
Here is the striped-fish-green.jpg image:
Write bluescreen code to place this fish in front of the yosemite.jpg background.
The fish has bits of blue on it, but that's ok since we're using a green
background in this case. Adjust the code so that all of the green towel below the
fish disappears. Little flecks of white will appear in the blue middle section of the
fish; we're stuck with those with our current technique.

image = new SimpleImage("striped-fish-green.jpg");


back = new SimpleImage("yosemite.jpg");
back.setSameSize(image);

for (pixel: image) {


avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;
// your code here
avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;
// your code here
if (pixel.getGreen() > avg * 1.00) {
x = pixel.getX();
y=pixel.getY();
newPixel=back.getPixel(x,y);
pixel.setRed(newPixel.getRed());
pixel.setGreen(newPixel.getGreen());
pixel.setBlue(newPixel.getBlue());
}
}
print(image);

Q2(wrong)
0/1 point (graded)
Write bluescreen code to modify the redwood.jpg image, replacing the trunk and
some of the branches of the tree with pixels from pebbles.jpg. The result is a
sort of fanciful looking stone-tree image. Adjust the code so the lower trunk is
changed to pebbles, but not too much of the greenery next to the trunk.

image = new SimpleImage("redwood.jpg");


back = new SimpleImage("pebbles.jpg");
back.setSameSize(image);

for (pixel: image) {


avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;
//if (pixel.getRed() >avg*1.1) {
newpx=back.getPixel(pixel.getX(), pixel.getY());
pixel.setBlue(newpx.getBlue());
pixel.setRed(newpx.getRed());
pixel.setGreen(newpx.getGreen());
}
print(image);

Multiple Choice
1/1 point (graded)
What does Moore's law say?
The number of texts sent by a teenager doubles every 18-24 months.

Transistors approximately double in cost every 18-24 months.

The number of platters in a hard drive doubles every 18-24 months.

The number of transistors which can fit on a chip doubles every 18-
24 months.

The speed of a transistor in gigahertz doubles every 18-24 months.


Which one of the following hardware components provides persistent
storage (i.e. maintained when the power is off)?
CPU

Hard Drive

RAM

Heat Sink
Which one of the following hardware components is the active "brain" doing
the computation in the computer?

CPU

Hard Drive

RAM

Heat Sink

Which one of the following hardware components provides temporary byte storage during a
computation, but is erased when the power is turned off?

CPU
Hard Drive

RAM

Heat Sink
Q1
1/1 point (graded)
How many different values can be stored in 1 bit? correct
2

Q2
1/1 point (graded)
How many bits are there in one byte? correct

Q3
1/1 point (graded)
One byte can hold a value from 0 up to what maximum value? correct

255

Q1
1/1 point (graded)
4000 kilobytes (KB) is approximately equal to how many megabytes (MB)?
(For all the problems in this section, just type in a number. The unit (MB or
GB or whatever) is always specified in the problem text.) correct
4

Q2
1/1 point (graded)
Suppose you have 10 image files, each taking up 300 KB. About how many
MB of space do they take up overall? correct

Submit
3

Q3
1/1 point (graded)
Suppose you have four 500 MB hard drives plus one 2 GB flash drive. How
many GB of capacity is this overall? correct

Submit
4

Q4
1/1 point (graded)
Suppose we have a video camera that produces video data at the rate of 2
GB per hour. Recording for 15 minutes creates about how many MB of
data? (Note that the answer is in MB) correct

Submit
512

Week 4
Q1
1/1 point (graded)
The CPU in the computer directly "runs" a sequence of what type of
instruction?

Java Code

Machine Code
C++ Code

Javascript Code
correct
Q2
1/1 point (graded)
After a CPU runs an instruction, what does it most often do next?

Erases the instruction from RAM

Runs the previous instruction in the sequence of instructions

Runs the next instruction in the sequence of instructions

Writes the instruction to disk


Q3
1/1 point (graded)
Suppose you double click Firefox.exe on a computer to run it. Which one of
the following best describes what happens?

The operating system copies the instructions for Firefox


from disk to RAM and then the CPU runs the instructions
in RAM.

The instructions for Firefox are translated into Javascript and then run by
the browser.

The operating system copies the instructions for Firefox into RAM and then
the RAM runs the instructions.
The operating system copies the instructions for Firefox from RAM to disk
and then deletes the copy in RAM.
correct
Q1
1/1 point (graded)
Which one of the following best describe what a C++ compiler does?

Translates machine code into Javascript code.

Translates C++ source code into Javascript code.

Translates machine code into C++ code.

Translates C++ source code into machine code.


Q2
1/1 point (graded)
The CPU's machine code has only simple, low-level instructions. A
computer language (such as Javascript) adds high-level features, such as
the for-loop we have used. Which one of the following is a low-level
instruction?

Loop over all the pixels in in image.

Append two strings together.

Print a string to the screen.

Add two numbers together.


Q3
1/1 point (graded)
Firefox is an open source program, so anyone can get access to the source
code. Which one of the following is something that is possible because
Firefox is open source?

Someone can run Firefox and note with a stopwatch about how quickly it
can draw different web pages.

Anyone is free to run the compiler to produce and


distribute their own version of Firefox.exe.
Someone can double click Firefox.exe to run it on their computer.

A $5 fee is required to use Firefox.


correct
Q1
1/1 point (graded)
Suppose a computer wants to send a packet on ethernet, as shown in
lecture. The computer first waits for what?

Waits for its scheduled time in the predetermined transmission schedule.

Waits for the recipient computer to signal that it is ready.

Waits for the central ethernet controller to signal that transmission is now
permitted.

Waits for the ethernet wire to be quiet.


correct
Q2
1/1 point (graded)
Suppose we are using the same checksum scheme as in lecture: add up all
the bytes, and take just the last two digits of the sum. What is the
checksum of the following bytes: 101, 202, 103, 100, 210, 120 correct

Submit
36
Q3
1/1 point (graded)
What is the purpose of a packet checksum?

Duplicate bytes to RAM to speed up the sending process on ethernet.

Compress sent bytes so they take up less space.

Encrypt bytes on the wire so they cannot be read by others.

Allow the recipient to detect if bytes received were


corrupted in transit.
Q1
1/1 point (graded)
Which one of the following is not a valid IP address?

42.257.99.11

11.250.3.4

45.67.212.100

1.2.3.4
Q2
1/1 point (graded)
Which one of the following is generally not true about routers?

Routers get packets from computers, forward them on

Routers check the central internet-map which shows


routes for all packets

Routers continuously monitor the status of their connections

Routers forward each packet one hop closer to its final destination
Q3
1/1 point (graded)
What does ping do?

Sends a "who is there" packet, getting back a detailed description of the


recipient

Notifies the local router that the computer does not want any more packets

Notifies the local router that the computer wants more packets

Sends a "are you there" packet to a computer, getting back a "yes"


packet
Q1
1/1 point (graded)
Write code to print the row for the name "Atticus".

table = new SimpleTable("baby-2010.csv");


for (row: table) {
// your code here
if(row.getField("name") =="Atticus")
{
print(row) ;
}

Q2
1/1 point (graded)
Write code to print the rows for the name "River". In this case, there are two
such rows, but the same basic code pattern as for question 1 works. This shows
how the loop really is just testing every row.

table = new SimpleTable("baby-2010.csv");


for (row: table) {
// your code here
if(row.getField("name")=="River")
{
print(row) ;
}
}
Q3
1/1 point (graded)

Write code to print the rows where the rank is less than (<) 10, i.e. ranks
1 through 9.

table = new SimpleTable("baby-2010.csv");


for (row: table) {
// your code here
if(row.getField("rank")<10)
{
print(row);
}
}
Q4
1/1 point (graded)
Write code to print the rows where the rank is greater than 950.

table = new SimpleTable("baby-2010.csv");


for (row: table) {
// your code here
if(row.getField("rank")>950)
{
print(row);
}
}
WEEK 5

You might also like