c109f03t2

c109f03t2 - CSE 109 Test 2 Wednesday 19 November 2003

Info iconThis preview shows pages 1–2. 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: 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 from2....
View Full Document

Page1 / 3

c109f03t2 - CSE 109 Test 2 Wednesday 19 November 2003

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online