CSc
12: Introduction to Computing
Sample 6 Weeks Exam
1.
Which of the following were great ideas of Babbage’s Analytical Engine that
anticipated modern computers? Write a
short explanation for each one, explaining why or why not.
_____
It was a general purpose device.
_____
It was compact.
_____ It had a separate mill and store.
_____
It was electro-mechanical.
_____
It had a branch instruction.
2. Below is a Knobby's World program that adds 2 + 3.
//Knobby
adder program, by Robert Barnes and Glenn Blank
//Add
2+3 as two strings of marks: XX XXX => XXXXX
define
right as
{ //Turn Knobby's to the right
left left left
}
define getAMark as
{ //read
a mark ('X') from next corner to the right
right move read
}
define goToBlank as
{ //go to
blank past first two marks
move move
}
define fillItIn as
{ //put a
mark in blank between strings of marks
write
}
define fillBlank as
{ //get a
mark and put it in the space between strings of marks
getAMark
goToBlank fillItIn
}
define goToEnd as
{ //go
the end of the second string of three marks
move move move move
}
define getABlank as
{ //read
a blank (empty corner) and turn around
read left left
}
define
erase as
{ //erase
a mark (with a blank)
move write
}
define eraseEnd as
{ //erase
mark at the end of concatenated string of marks
goToEnd
getABlank erase
}
define goHome as
{ //go
back to starting position
move move move move move move right
}
define
main as
{ //2+3
(XX XXX) == 5 (XXXXX)
fillBlank //put a mark between the XX and the XXX
eraseEnd //erase the mark at the end of the XXX
goHome //tada!
}
A)
What problem solving strategy did I probably use to design my solution? Why do you think so?
B)
What problem solving strategy would you use to write a Knobby program that adds
1+2? Why?
C)
Modify the Knobby program above so that it adds 1+2. Comment your code!
D)
In what way could this program be made more general? What construct of the Knobby’s World programming
language might you use to achieve this generality?
3. Why is it a good idea to analyze a problem in terms of use cases before designing a solution or writing code? Give at least two reasons.
4.
Given the following class interface:
class Circle
{ public Circle(double radius); //create a Circle with radius in inches
public double
perimeter(); //computes perimeter in
inches
public double area(); //computes
area of circle in inches
private double _radius; //radius is half diameter, in inches
} //Circle
a)
Write a snippet of Java code that creates a Circle
object, c, whose radius is 2 inches,
then produces its perimeter.
b)
What would happen if you tried to write a snippet of code that displayed the _radius of c? Why?
Are
the following statements true or false? Explain
why or why not.
___
a) Java operators can mean different things depending on the types of their
operands.
____b)
Java comments cannot contain any Knobby’s World code.
___
c) Compiled code runs faster than equivalent interpreted code.
___
d) A blind hacking approach can get blind-sided by a
combinatorial explosion.
(See
end of review questions at end of each chapter in the book for more of these
questions.
Answers
supplied in http://www.cse.lehigh.edu/~glennb/um/book/exsolnew.htm.)