c17f98f - CSc 17 Page 1 Final Examination Monday 14...

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

CSc 17 Final Examination Monday 14 December 1998 Page 1 1. ( pts) Assume the declarations of class biNode and of rt below. Write a function "zero" such that the call "zero(rt)" stores a 0 in each leaf of the tree whose root is rt. The function assumes that rt is indeed the root of a properly defined tree. That is, rt either points to NULL or to a biNode, and the children of each biNode in the tree are either NULL or a biNode. class biNode{ public: int key; biNode *left,*right; } biNode *rt; ------------- void zero(biNode *rt){ if(rt!=NULL) if(rt->left==NULL && rt->right==NULL) rt->key=0; else { zero(rt->left); zero(rt->right); } } 2. ( pts) Write a function DIGITS which makes a copy of a file of text which is identical to the original file, except that any line which has at least one digit has an asterisk (*) appended to it. So, for example, if the file consists of 7 lines of text for this question, the new file would be identical, except that the first and fourth lines would have an asterisk at the end. Assume the call is DIGITS(in,out) where we have ofstream out; ifstream in; void DIGITS(istream &in,ostream &out){ char ch; bool foundDigit; in.get(ch); while(!in.eof()){ foundDigit=false; while(ch!='\n' && !in.eof()){ if(ch>='0' && ch<='9') foundDigit=true; out.put(ch); in.get(ch); } if(foundDigit) out.put('*'); out.put('\n'); in.get(ch); } } 3. ( pts) Suppose we have the following prototypes and declarations.
Image of page 1

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

Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '08
  • varies
  • Recursion, #, 10 pts, 25 pts

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern