It's an April Fools Day Test

Note:  The programs and the grammer are four points, the other questions are one point each.

1) Suppose that the following relations hold true.  Write me a Prolog program that allows me to discover who is who's a-uncle (a parent's sibling), and who is who's cousin (a parent's siblings child).  It's O.K. if I'm my own cousin.

father(chris, randy)
mother(beverly, randy)
father(chris, scott)
mother(beverly, scott)
father(randy, gabe)
mother(meg, gabe)
father(george, chris)
mother(lois, chris)
father(george, leslie)
mother(lois, leslie)
mother(leslie, sybl)
2) Write me a Perl program that reads data from the keyboard (<STDIN>).  When the input it over, print the lines in sorted order.  If the line "Perl is Gawd" was entered, print "Ya Baby" at the end of the list.

3) Write me a Lisp program that given a bit vector, prints the number of ones.  For example, (countones `(1 0 1 1 0 0 0 0 0 1)) should return 4.

4) Write me a Microsoft Word compatible word processor.  All features of Microsoft Word must be present.  You may use any programming language.  You may only use 4 lines.   It should be safe from  the Melissa virus, but otherwise run all Visual Basic macros.  And it should pass the Turing Test.  You may use any genetic algorithm you wish.  No partial credit allowed.

5) Write me a grammar that captures the idea of 'dollar amount'.  For example, all amounts should start with a dollar sign.  There should either be no decimal point or two digits after it.  There should only be one decimal point.  Negative amounts are possible (you're in debt).  Examples are shown below.
 
Is Valid Not Valid
$10.02 10.02
$12 $12.0345
$16.70 $16.7
$-12.30 $12.30-

6) Here is a grammar.  Show the parse tree for the two input strings
 
complaint <- article noun is adj-phrase
article -< the | this | these
noun <- test | quiz | program | teacher
adj-phrase <- adj-phrase and adj-phrase
adj-phrase <- hard | stupid | evil
This test sucks This teacher is evil and stupid and hard
 
 
 
 
 
 
 
 
 
 

 

7) When do C++ objects need a virtual function table?
 

8) Write me a Python program that has a scale and a label.  Whatever value the scale shows, the label should show the square of that value.

9) What algorithm or concept did you find most cool in class.  What exciting you intellectually the most (in class).
 
 

 
11) Pascal for loops look like the left hand side below, and C/Java loops look like the right hand side.  When is the Pascal way better, and when is the C/Java way better.
 
for i = 1 to 10 do
begin
    ....
end
for (i = 1; i < 11, i++) 
{
     ....
}

12) What is the best way for the compiler to implement the case statement shown below.  'X is an integer.

switch (x) {
    case 1:
        ....
    case 17:
        ....
    case 1083:
        ....
    default:
        ....
}
13) Under what situations can an interpreter be faster than compiling and then running.  Under what conditions is it slower?
 
 

14) Given the following class declarations, does an instance of class C named 'fred' have a member variable named a?  Is so, what line of Java/C++ would assign a 12 to it? _______________________________   Does it have a member variable named d?  If so, what line would assign a 12 to it? ______________________
 
class A {
    public int a;
    private float b;
    protected char c;
}
class B {
    public int x;
    private int y;
}
class C extends A {
    private int d;
    protected float e;
}

15) Given an instance 'fred' of the class C above, what member variables are accessible by member functions of C?  In other words, list all the member variables a function of class C can use.
 
 

16) What part of this class was most valuable to you.  What part could you have done without.