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.
#include <stdio.h>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.
#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();
}
4. Very briefly explain what a pure virtual function is, how to declare one, and why you might want one.
Good luck.
DK