c109f03t2 - CSE 109 Test 2 Wednesday 19 November 2003...

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

View Full Document Right Arrow Icon
CSE 109 Test 2 Wednesday 19 November 2003 >>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<, 1. Write a template for a class Between. Instances of Between are created with two values and respond to the message good() by returning true if and only if good()'s argument lies between the two values (inclusive). For example, given Between <Word> a("good","bad"); a.good("cool") returns true, while a.good("man") returns false. For another example, given Between <int> b(12,18); b.good(18) returns true, while b.good(21) returns false. >>>>>>>>>>>>>>>>>>>>>>>>. template <class T> class Between {public: Between(const T &a, const T&b); bool good(const T &t); private: T low,high; }; } template <class T> Between<T>::Between(const T&a,const T&b) {if(a<b) {low=a; high=b; } else {low=b; high=a; } } template <class T> bool Between<T>::good(const T&t) {return low<=t && t<=high;} <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 2. Assume that you are writing a program to read a single line of text from cin, where the text should have no blanks and should have the syntax given by <A>::=<number> { < | <= } <number> <number>::= <digit> <digit>* <digit>::= 0 | 1 (basically the comparison between two binary numbers).
Image of page 1

Info icon This 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