Advanced Placement Computer Science AB:
Quiz 6
    Sewickley Academy, 2000-2001

See Course Home Page.

This is a programming quiz.  You must use Visual C++.  You may not use any notes and you may not start from a preexisting VC++ project (you must only use newly-created files in a newly-created project).

0.  NOTE:  This quiz has two parts -- an in-class part and a take-home part.  The rules for the take-home part are the same as in-class quizzes:  you may not use your notes, you may not use the book, you may not discuss this with other people.  You must turn in the take-home quiz before 8:15am tomorrow morning -- no late quizzes will be accepted.  You must also certify that you did not use notes, books, or discuss it with others.



1.  NOTE:  THIS PROBLEM IS THE TAKE-HOME PORTION OF THE QUIZ
Write a program to use Monte Carlo methods to determine how many people must be in a room together before it is likely that *3* of them all have the same birthday.


2.  Write the function apply() which makes the following code work properly.  Note that this function takes another function as an argument:
     #include <stdio.h>
     #include <iostream.h>

     int square(int x)
     {
      return x*x;
     }

     int cube(int x)
     {
      return x*x*x;
     }

     // WRITE THE FUNCTION apply() HERE
     // This function takes two arguments -- another function,
     // such as square(), and an integer, and it returns the
     // result of calling that function with the integer as
     // its only argument.

     void main()
     {
      cout << "apply(square,5) = " << apply(square,5) << endl;
      cout << "apply(cube,5) = "   << apply(cube,5) << endl;
      getchar();
     }

3.  Recall that the fibonacci sequence is defined as:  1, 1, 2, 3, 5, 8, 13, 21,...  -- that is, the first two numbers are each 1, then each subsequent number is the sum of the preceding two numbers.  Write the functions IterativeFib(n) and RecursiveFib(n), which iteratively and recursively compute the nth fibonacci number.

4.  Very briefly explain what a pure virtual function is, how to declare one, and why you might want one.

Good luck.

DK


See Course Home Page.