c17f00t2 - CSc 17 Test 2 20 November 2000 >SUGGESTED...

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

View Full Document Right Arrow Icon
CSc 17 Test 2 20 November 2000 >>>>>>>>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<<<, 1. (20 pts) Assume the class LinkList below. Write a member function of LinkList called same() which returns true if and only if two linked lists have the same data in the same order. Given the declaration LinkList a,b;, the call to same() would be a.same(b); (or b.same(a);). (You need not provide the prototype for same()) class LinkList{ private: class Link{ public: Link(); Link(int x); int key; Link *next; }; Link *root; public: ... ... }; bool LinkList::same(LinkList &list){ Link *one,*two; one=root; two=list.root; while(one!=NULL && two!=NULL && one->key==two->key){ one=one->next; two=two->next; } return one==NULL && two==NULL; } 2. (25 pts) For the class X below overload the operators "+" and "<<". When we have the declaration X a,b; a+b should return an instance of X whose data member x contains the sum of the x's of a and b, and if a.x=4, cout<<a; should display a in the form "X(4)". Provide both the prototypes and the definitions of the two operators.
Image of page 1

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

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

{[ 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