Name ___________________
CPTR246 Spring '99 (
100 total points) Exam 3
(picture won't display - substitute any old tree with integers labeling the nodes.)
Write a template function called displayArray that displays arrays of objects. It should take two parameters: the array of objects and the number of objects in the array. Examples of its use would be as follows:
int testScores[100];
int numberOfScores;
double monthlyAverages[12];
printArray(testScores, numberOfScores);
printArray(monthlyAverages, 12);
Below is the definition for the employee structure along with the definitions for two employee objects. We want to be able to "compare" two employee objects to see which is "less" using the '<' operator. You are to give the necessary C++ code to overload the '<' operator - but YOU define what is means for one employee to be less than another.
struct employee { // defines employee "type"
int ID; // employee id number
double hourlyRate; // pay rate
char name[30]; // employee's first name
double hoursThisWeek; // hours this week
};
employee emp1;
employee emp2;
. . .
if (emp1 < emp2){ . . . .
Fib(0) = 0
Fib(1) = 1
Fib(2) = 1 (It is 0 + 1)
Fib(3) = 2 (It is 1 + 1)
Fib(4) = 3 (It is 1 + 2)
Fib(5) = 5 (It is 2 + 3)
Fib(6) = 8 (It is 3 + 5)
Fib(7) = 13 (It is 5 + 8)
Fib(8) = 21 (It is 8 + 13)
and so on ....
If you don't see that the next two Fibonacci numbers are 34 and 55, ASK!!! In order to answer this question correctly, you must understand the series.
Write a recursive function called Fib that takes one integer parameter n and returns Fib(n). For example, Fib(8) should return 21. (HINT: There are two base cases.) (15 points)
You have been given a copy of the code that defines the BinaryTree class. What modifications would be necessary to the code for the BinaryTree class to include a recursive member function SumOfEvenNodes that returns the sum of all nodes in the tree whose integer value is an even number. (NOTE: An integer object x is even if the following condition is true: (x % 2 == 0))
Changes to the public section:
Changes to the private section:
Code for the function definitions:
int BinaryTree::InTree(int x){
// pre: none
// post: return true if x is in the tree, false if not
}