c109s03t1

# c109s03t1 - CSE 109 Test 1 Wednesday 19 February 2003...

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

CSE 109 Test 1 Wednesday 19 February 2003 ===================SUGGESTED ANSWERS==================================== 1. Consider an ADT, Tally, for tallying votes for a referendum. It can record a yes or a no and returns the number of yeses and noes. Further, one can add two to get a third Tally which has the sums of the yeses and noes from the first two. Write the declaration and the definitions (code) for a class Tally, which implements this ADT and for which the following code will compile and behave "reasonably." Tally a,b,c; a.yes(); a.yes(); b.no(); a.no(); c=a+b; cout<<"Noes: "<<c.noes()<<", yeses: "<<c.yeses()<<endl; ======================================================================== #include <fstream.h> class Tally {public: Tally(); void yes(); void no(); int yeses(); int noes(); Tally operator +(const Tally &t); protected: int yesCt,noCt; }; } Tally::Tally():yesCt(0),noCt(0) {} { void Tally::yes(){yesCt++;} v void Tally::no(){noCt++;} v int Tally::noes(){return noCt;} i int Tally::yeses(){return yesCt;}

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

View Full Document
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

c109s03t1 - CSE 109 Test 1 Wednesday 19 February 2003...

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

View Full Document
Ask a homework question - tutors are online