SYSC2002_2004_Fall - Question 1(8 marks Suppose that...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Question 1 (8 marks) Suppose that somebody owes X dollars. At the end of every year the debt is recalculated as explained here: 1. First the debt is increased by X * (R / 100), where R is the interest rate. 2. Secondly, the debt is then reduced by the annual payment of Y dollars. Write a RECURSIVE function that, given X, R, and Y, returns the number of years it will take to pay off the debt. You may assume that the values are such that the debt will eventually get paid off. Hint: How much debt remains after one year? How many years will it take to pay off this debt? Question 2 (28 marks) A student database is organized as a binary tree SORTED BY STUDENT NAME ("aardvark" < "betty" < "zirconda"). Some of the students in the database are on the university swim team. An auxiliary linked list is used to keep track of which students are on the swim team. The head pointer for this linked list points to the tree node for the first student on the swim team, and so on. The linked list is doubly linked, and there is also a tail pointer. The diagram below should make things clear. The essential elements of the header for the database class are given on the next page. Note that elements that are not relevant to this question have been omitted. Note: The students currently on the swim team are: Anne, Fred, Joe, Lucy, Paul and Ted. root pointer for student database Paul Sue Mike Ed Doug Fred Keith Lucy Anne Joe head pointer for swimmer list tail pointer for swimmer list Ruth Yvonne Ted Will
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
class StudentDB { private: class TNode { public: string name; int number; bool onSwimTeam; TNode *priorSwimmer, *nextSwimmer; // both NULL if student not on swim team TNode *left, *right; }; TNode *root, // root pointer for tree *head, *tail; // head and tail pointers for linked list of swimmers
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 4

SYSC2002_2004_Fall - Question 1(8 marks Suppose that...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online