c17su02f

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

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

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 \ \ \

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

View Full Document
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 ".
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