Final Exam Review for CS 2390 Fall '96


For each scenario described below, tell me (a) whether the bold-faced data or function should be declared public, private, or protected in C++ and (b) why. Discuss Answers Here

(a) You have an account_balance in an Account class, and you've already defined protected accessor functions.

(b) You have a timer integer in a class that you want to be easily and rapidly accessed in a real-time system.

(c) You have a getNextID() function which will return a unique identifier for the next instance of the class or its subclasses.

(d) You have a change_Channel() function in a Television class, and you don't want to let anyone else change the channel.

(e) You have a display_image() function which your WebBrowser class needs and wants to make available to plug-ins (which will be derived classes from the WebBrowser class.)

(f) You have a currentUser String which you want any function to be able to set and access.

(g) You have a list of items in a Dispensing_Holder.


Fill in what happens in the below Model-View interaction (Four parts): Discussion


You are building a simulation of a shipping port where boats are entering and leaving, docking at a given dock, unloading and re-loading cargo, and trucks are taking the cargo in and out of the port. The following components will be part of your simulation: Discussion

(a) Of the following questions, which call for a discrete simulation and which call for a continuous simulation? And WHY?

(b) For these questions, which of the following should be modelled as resources and which as simulation objects? And WHY?


For the below features of object-oriented programming languages, describe how each of Smalltalk, C++, Java, and Python provides (or does not provide) the feature. Discussion


This is the story of a small bookshop that grew into a large bookshop, and the problems that they have had with their inventory system.

In the beginning, the bookshop only dealt in books, so their inventory system had only a single class in it. (You can assume that a String class and a Boolean class has been #include'd somewhere.)


class Book { 
	String title; 
	String author; 
	String publisher; 
	int year; 
	int pages; 
	float cost; 
	float price;}

But later, the bookshop decided to carry magazines, so the inventory system class structure was updated. Since magazines don't really have single authors, a constructor was added to set a flag value.


class Magazine: Book { 
	Magazine() {author="*MAGAZINE*";}
	String month; 
	String article_titles[MAX_NUMBER_ARTICLES]; 
	String article_authors[MAX_NUMBER_ARTICLES];}

And finally, the bookstore decided to start carrying records, casettes, and CDs, and the inventory system was again extended. But now, of course, it made almost no sense at all - they had to use "author" when they meant "artist", there are no pages in a recording, and they had to use "publisher" for "recording company". And the hierarchy itself didn't make much sense: A magazine isn't a kind of book, nor is a recording.


class Recording: Book { 
	Recording() {pages = -1;} 
	String song_titles[MAX_NUMBER_SONGS]; 
	Boolean group;} 
class Record: Recording { float speed;}
class Cassette: Recording { int length;}
class CD: Recording { 
	String type; // CD-ROM, DVI, etc.
}

Below (and on the back, if necessary): DISCUSS YOUR ANSWERS HERE


VisualWorks uses a system called BOSS (Binary Object Storage System) for storing the VisualWorks Image out to disk. BOSS writes out all of the objects in binary from VisualWorks when executing, such that all objects are reloaded with even such details as window position preserved.

Discussion


You are working on a project using Smalltalk where you need linked lists, but you've decided that you don't like the implementation of linked lists provided in the Smalltalk image. You decide to implement your own class MyLinkedList. You need the following functions in your implementation:

Object subclass: #MyLinkedList
        instanceVariableNames: YOU FILL IN HERE
        classVariableNames: 
        poolDictionaries: 
        category: 'My-Data-Structures'

Discussion of Linked Lists in Smalltalk


Below is the definition in C++ of the class Count.

template<class Count_Type>
class Count { 
public:
//Constructors/destructors
        Count() { } 
        virtual ~Count() { } 
//Implementors
        virtual void decrement() =0;
        virtual void increment() =0;
        void reset() {  value = reset_value; } 
//Accessors
        Count_Type get_value() {  return value; } 
        void set_value(Count_Type new_value) {  value = new_value; } 
        Count_Type get_reset_value() {  return reset_value; } 
        void set_reset_value(Count_Type new_value) {  value = new_value; } 
protected:
//Data members
        Count_Type value;
        Count_Type reset_value;} ;




(a) In terms of inheritance, does this definition differ from the definition of the class Count in Smalltalk? Can subclasses of Count in Smalltalk access anything more or less than derived class of Count in C++? Can external classes that use Count in Smalltalk access anything more or less than external classes that use Count in C++?

(b) Why are the data members declared protected in the class above? Why not declare them private?

(c) Why are ~Count(), increment(), and decrement() declared virtual? What does that mean?

(d) Suppose that we don't want to allow the data members of Count to be arbitrarily manipulated from outside of this class or classes derived from Count. What would you change in the above definition? Why?

Discuss C++ vs. Smalltalk Count here


Please answer the following questions:

Discuss implementation inheritance here