c17su99f

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

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

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.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern