c17su02f - CSc 17 Final Examination 28 July 2002 1. (25...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: CSc 17 Final Examination 28 July 2002 1. (25 pts) Write a function numberLines() which reads text from a file and faithfully echoes it to the screen, except that it appends the line number at the end of each line in the form [xx]. For example, if the file containing the text is stored in "final.txt", the first two line of output produced by the code below would be: CSc 17 Final Examination 28 July 2002 [1] [2] ifstream out("final.txt"); numberLines(out);--------------------------------------------------- void nextCh(istream &inp,char &ch) {inp.get(ch); if(!inp.good()) ch='\n'; } void numberLines(istream &inp) {int count; char ch; nextCh(inp,ch); count=0; while(inp.good()) {while(ch!='\n') {cout<<ch; nextCh(inp,ch); } count++; cout<<" ["<<count<<"]\n"; nextCh(inp,ch); } } 2. (25 pts) Suppose you have a stack and that every time an item is popped from the stack the item is added to a binary tree constructed so that an in-order search of the tree lists the numbers in ascending order. Show the binary tree after each item is popped from the stack given that you start witn an empty tree and given the following sequence of stack operations: push 8, push 10, push 19, push 15, pop, pop, push 12, pop, pop, pop Answer the above question again, this time assuming that you have a queue rather than a stack: enqueue 8, enqueue 10, enqueue 19, enqueue 15, dequeue, dequeue, enqueue 12, dequeue, dequeue, dequeue--------------------------------------------------------------------- 15 15 15 15 15 \ / \ / \ / \ 19 12 19 12 19 12 19 / / 10 10 / / 8 8 8 8 8 8 8 \ \ \ \ 10 10 10 10 \ \ \ 19 19 19 / / 15 15 / 12 3. (25 pts) Write a template for a function posArray() which returns 'true' if and only all entries in the array between two indices inclusive are >=0. For example, for the following code, the output would be "no yes no "....
View Full Document

This note was uploaded on 03/09/2008 for the course CSE 17 taught by Professor Varies during the Spring '08 term at Lehigh University .

Page1 / 6

c17su02f - CSc 17 Final Examination 28 July 2002 1. (25...

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