c109s04t1 - CSE 109 Test 1 Wednesday 25 February 2004 8:10...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: CSE 109 Test 1 Wednesday 25 February 2004 8:10 AM >>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<< 1. Assume the class A below. Write the declaration and code for the subclass, B, of A, which enables a user to set the value of k with setK() and to get the value of k with getK(). In particular, the following code should produce the output "The value is 6". B x(2,3); x.setK(6); cout<<"The value is "<<x.getK()<<endl; class A {public: A(int n=0,int p=0):k(n),q(p){} protected: int k,q; };----------------------------------- class B:public A {public: B(int n=0,int p=0); void setK(int p); int getK(); }; B::B(int n=0,int p=0):A(n,p){} void B::setK(int p){k=p;} int B::getK(){return k;} 2. Assume class A above. Add the declaration(s) and code needed to implement the operator +=, which increments k by some amount. In particular the code B x(10,3); x+=5; cout<<"The value is "<<x.getK()<<endl; would produce the output "The value is 15"....
View Full 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

c109s04t1 - CSE 109 Test 1 Wednesday 25 February 2004 8:10...

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