c109f06t2 - CSE 109 Test 2 Wednesday 29 November 2006...

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

View Full Document Right Arrow Icon
CSE 109 Test 2 Wednesday 29 November 2006 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<SUGGESTED ANSWERS>>>>>>>>>>>>>>>>>>>>>>>>> 1. Consider the abstract data type of an ordered pair and label the elements of the pair x and y. We should be able to create an ordered pair, get the entries in the pair, and print it out. Write the template for the OrdPair class so that the following code will compile and produce the indicated output. OrdPair<int,double> a(7,3.2); cout<<a.getX()<<" "<<a.getY()<<" "<<a<<endl; // 7 3.2 (7, 3.2) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #include <iostream> using namespace std; template <class A, class B> class OrdPair {public: OrdPair(const A &a, const B &b); A getX()const; B getY()const; template <class X, class Y> friend ostream & operator & op); private: A x; B y; }; } template <class A, class B> O template <class A, class B> A OrdPair<A,B>::getX()const{return x;}
Background image of page 1

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

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

This note was uploaded on 03/09/2008 for the course CSE 109 taught by Professor Kay during the Spring '08 term at Lehigh University .

Page1 / 3

c109f06t2 - CSE 109 Test 2 Wednesday 29 November 2006...

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