c109s00t1

c109s00t1 - CSc 109 Test 1 1 March 2000 >[SUGGESTED...

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

View Full Document Right Arrow Icon
CSc 109 Test 1 1 March 2000 >>>>>>>>>>>>>>[SUGGESTED ANSWERS]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1. Class Rect below is meant to represent a rectangle. Write the declaration and definition of a subclass of Rect called Box, which represents a 3-dimensional box. You should note that Rect has no protected members and that Box should have only one more data member beyond those it inherits (len, wid). Including your declaration and definition (code) should allow the following statement to compile. cout<<"The volume of the 2x3x4 box is "<<box(2,3,4).volume()<<endl; class Rect{ public: Rect(); Rect(double le,double wi); //create a box of length le and width wi Rect(const Rect & r); double area(); private: double len, wid; }; class Box : public Rect{ public: Box(const Box & b); Box(double le,double wi, double ht); double volume(); private: double high; }; Box::Box(double le, double wi, double ht):Rect(le,wi){ high=ht; } high=b.high; } double Box::volume(){ return area()*high; } 2. For the Simpletron program below, fill in the values in the table for PC and Accumulator for the first 20 steps or until a halt, when the program executes. Indicate undefined values with ????. List the initial memory. When memory changes, indicate the new value and the value of the program counter in parentheses (e.g., if location 5 changes to 84 when the
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 / 4

c109s00t1 - CSc 109 Test 1 1 March 2000 &gt;[SUGGESTED...

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