c17f00f - CSc 17 Final Examination Tuesday 19 December 2000...

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

View Full Document Right Arrow Icon
Tuesday 19 December 2000 >>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<< 1. Write the declaration for a class FlipFlop and then write the definition of its member functions and operators. Instances of class FlipFlop store either the value of 0 or 1. If two instances of FlipFlop are added the result is a FlipFlop which has the value 0 if both the instances being added are storing the number 0; otherwise the resulting FlipFlop has the value 1. You need only declare and implement enough functions and operators so that the following code would compile. FlipFlop a,b(0); a.set(1); cout<<"The FlipFlop has the value "<<a.get()<<endl; cout<<a<<" + "<<b<<" = "<<(a+b)<<endl; class FlipFlop{ public: FlipFlop(); FlipFlop(int n); void set(int n); int get(); FlipFlop operator+(const FlipFlop&a); friend ostream & operator private: int value; }; FlipFlop::FlipFlop(){ value=0;} FlipFlop::FlipFlop(int n) {set(n);} void FlipFlop::set(int n){if(n<0 || n>1) n=0; value=n; } int FlipFlop::get(){ return value;} return FlipFlop(0); return FlipFlop(1); } out<<"FlipFlop("<<a.value<<")"; return out; } 2. Write a recursive function MATCH. It is used to determine whether entries in two arrays of ints are identical. Given int a[20],b[30]; the call MATCH(a,b,2,10) returns true if and only if the entries a[2] through a[10] are identical to and in the same order as the entries b[2] through b[10]. You MUST use the following recursive algorithm. If the two sets of entries to compare have indices between n and m inclusive, the arrays match if the mth entries are the same and the rest of the two arrays match. bool MATCH(int a[],int b[], int low, int high){
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 17 taught by Professor Varies during the Spring '08 term at Lehigh University .

Page1 / 5

c17f00f - CSc 17 Final Examination Tuesday 19 December 2000...

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