c109f05t1

c109f05t1 - CSE 109 Test 1 Friday 7 October 2005...

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

View Full Document Right Arrow Icon
CSE 109 Test 1 Friday 7 October 2005 <<<<<<<<<<<<<<<<<<<<<SUGGESTED ANSWERS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. 1. The class Counter below is meant to model a hand held counter. It starts out at 0 and can be reset to 0. Each "click" increments the count by 1. Write a subclass XCounter which adds some functionality by allowing it to be incremented or decremented by numbers other than 1, using the += and -= operators. First I show the class Counter, and then I show how the code for XCounter could be used. class Counter {public: Counter(); void click(); //increment counter by 1 void reset(); //set counter to 0 int getCount()const; //return the count on the counter private: int count; }; //Sample code for XCounter XCounter ct; ct+=5; //increment counter by 5 ct-=3; //decrement counter by 2 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< class XCounter : public Counter {public: XCounter(){} XCounter& operator+=(int n); XCounter& operator-=(int n); private: static void check(bool b, char *mess); }; {check(n>0,"Can't increment with 0 or negative n");
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

c109f05t1 - CSE 109 Test 1 Friday 7 October 2005...

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