CSE 109 Test 2 FALL 2006

CSE 109 Test 2 FALL 2006 - CSE 109 Test 2 Wednesday 29...

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<<(ostream &out,const OrdPair & op); private: A x; B y; }; template <class A, class B> 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.

Page1 / 3

CSE 109 Test 2 FALL 2006 - CSE 109 Test 2 Wednesday 29...

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