c17su99f

c17su99f - CSc 17 Final Examination Friday 2 July 1999 Page...

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

View Full Document Right Arrow Icon
CSc 17 Final Examination Friday 2 July 1999 Page 1 >>>>>>>>>>>>>>ANSWERS>>>>>>>>>>>>>>>>>>>>>>>>. 1. (25 pts) Call an array of ints with one entry "balanced" if the entry is 9. Call an array of ints with two entries "balanced" if the sum of the two entries is 9. Call an array of ints with more than two entries "balanced" if the sum of the first and last entry is 9 and the rest of the array between the first and last entries is balanced. Use this recursive definition (and do not change it) to write a recursive function "balanced" which is called as follows, balanced(x,first,last), where x is an array of ints and first and last are ints giving the locations of the first and last entries in the array. The call "balanced(x,first,last)" should return true when the array is balanced and false otherwise. bool balanced(int x[],int first,int last){ if(first>last) return true; if(firts==last) return x[first]==9; return( x[first]+x[last]==9 & balanced(x,first+1,last-1)); } 2. (10 pts) Assume the class IntStack is defined as follows: class IntStack{ public: IntStack(int n); IntStack(IntStack & stk); ~IntStack(); bool empty(); bool full(); int pop(); void push(int x); int peek(); private: IntStack(); //Don't allow use int size, top, //top points to the first free location *stk; void error(char *mess); }; Also assume that the class IntQueue has been similarly defined. What is the output of the following code?
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

c17su99f - CSc 17 Final Examination Friday 2 July 1999 Page...

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

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