Object-Oriented Systems Fall 1993 COM 3360 Prof. Karl Lieberherr --------------------------------------------------------------------------- Midterm Nov. 2, 1993 --------------------------------------------------------------------------- 130 points total Q1: 14 unknowns, 3 points each 42 Q2: 17 unknowns, 2 points each 34 Q3: 18 unknowns, 3 points each 54 --------------------------------------------------------------------------- Open book and open notes. To make the grading easier, please put your values for the unknowns on the enclosed answer sheet. THE GAME OF REDUNDANCY AND UNKNOWNS ----------------------------------- Most of the questions in this exam ask you to determine unknowns of the form UNKNOWN1, UNKNOWN2, ... This makes it easier for you to answer the questions, since you get extra context information. Yet you need to master the behavioral objectives of the course to answer the questions. Guessing an answer is not a successful strategy and therefore a "game of redundancy" test is more interesting than a multiple choice test. The questions have the following pattern: I show you several artifacts which are related by the theory of object-oriented design and programming. Because of the dependencies between the artifacts, some of the information is redundant and can be recovered from the context by applying the objectives covered in the course. The information which you should discover is marked UNKNOWNx. If an unknown is not uniquely determined, mark the answer with *CHOICE*. An unknown may be anything, e.g., a number, an identifier, a character, two identifiers with a blank between them, a string etc. If an unknown is the empty string, give NOTHING as answer, e.g., UNKNOWN = NOTHING. Example: 5 + UNKNOWN1 = 8 UNKNOWN1 = 3 --------------- UNKNOWN2 * UNKNOWN3 = 20 UNKNOWN2 = 4 *CHOICE* UNKNOWN3 = 5 *CHOICE* At the beginning of a question we give the number of points per unknown. Question 1: 3 points per UNKNOWN ---------------------- Consider the following propagation pattern and the output which it produced. At the end you find the cd which was used for customization. Find the UNKNOWNs. Propagation pattern: *operation* void x(int& h1) *traverse* *from* Experiment *to* Measurement *wrapper* Measurement *prefix* (@ h1 += 1; @) *suffix* (@ cout << endl << h1 << endl; @) *operation* void y(float& h2) *traverse* *from* Experiment *to* Measurement *wrapper* Measurement *prefix* (@ h2 += *get_v(); @) *suffix* (@ cout << endl << h2 << endl; @) *operation* void z() *wrapper* Experiment *prefix* (@ int h1 = 0; this -> x(h1); @) *suffix* (@ cout << endl << "h1 " << h1 << endl; @) *wrapper* Experiment *prefix* (@ float h2 = 0; this -> y(h2); @) *suffix* (@ cout << endl << "h2 " << h2 << endl; @) *wrapper* Experiment *suffix* (@ float h3 = h2 / h1; cout << endl << "h3 " << h3 << endl; @) Input object (as sentence) 4.0 5.0 3.0 Output trace: IN Experiment::z IN Experiment::y IN Measurement_List::y IN Measurement::y UNKNOWN1 OUT Measurement::y IN Measurement::y UNKNOWN2 OUT Measurement::y IN Measurement::y UNKNOWN3 OUT Measurement::y OUT Measurement_List::y OUT Experiment::y IN Experiment::x IN Measurement_List::x IN Measurement::x UNKNOWN4 OUT Measurement::x IN Measurement::x UNKNOWN5 OUT Measurement::x IN Measurement::x UNKNOWN6 OUT Measurement::x OUT Measurement_List::x OUT Experiment::x h1 UNKNOWN7 h2 UNKNOWN8 h3 4 OUT Experiment::z Guess the class dictionary which was used for customization by filling in the following unknowns: // Parameterization-expanded class dictionary. UNKNOWN9 = UNKNOWN10 . UNKNOWN11 = DemReal . UNKNOWN13 ~ { UNKNOWN14 } . Question 2: 2 points per UNKNOWN. ============================================== Consider the same propagation patterns as in question 1. Find the UNKNOWNs in the following C++ program which is the result of customizing the propagation patterns with the class dictionary: Experiment = Plant [ Plant]. Plant = List(Equipment). Equipment : Oven | Mixer *common* Measurement. Oven = "oven". Mixer = "mixer". Measurement = DemReal. List(S) ~ {S}. void UNKNOWN1::x( int& h1 ) { UNKNOWN2 ->x( h1 ); if ( UNKNOWN3 != UNKNOWN4 ) { UNKNOWN5 ->UNKNOWN6( h1 ); } } void UNKNOWN7::x( int& h1 ) { UNKNOWN8 ->x( h1 ); } void Equipment::x( int& h1 ) { UNKNOWN9 ->x( h1 ); } void UNKNOWN10::x( int& h1 ) { UNKNOWN11->UNKNOWN12::x( h1 ); } void UNKNOWN13::x( int& h1 ) { UNKNOWN14->UNKNOWN15::x( h1 ); } void Measurement::x( int& h1 ) { // prefix blocks h1 += 1; // suffix blocks cout << endl << h1 << endl; } void Equipment_List::x( int& h1 ) { Equipment_list_iterator next_Equipment(*this); Equipment* each_Equipment; UNKNOWN16 ( each_Equipment = next_Equipment() ) { each_Equipment->x( h1 ); } } // part of program omitted------------------ void Measurement::y( float& h2 ) { // prefix blocks UNKNOWN17 cout << endl << h2 << endl; } // part of program omitted------------------ void Experiment::z( ) { // prefix blocks float h2 = 0; this -> y(h2); int h1 = 0; this -> x(h1); // suffix blocks cout << endl << "h1 " << h1 << endl; cout << endl << "h2 " << h2 << endl; float h3 = h2 / h1; cout << endl << "h3 " << h3 << endl; } Question 3: 3 points per UNKNOWN -------------------------------------------- Consider the following class dictionary, propagation pattern, propagation graph and trace output. Find the UNKNOWNS. Class dictionary: Cd_graph = List(Adjacency). Adjacency = Vertex Neighbors ".". Neighbors : Construct_ns | Alternat_ns *common* List(Labeled_vertex). Labeled_vertex = "<" DemIdent ">" Comma_list(Vertex). // vertex plays double role: // in cd: Part class (only one element in list) // in PartCluster: Cluster Alternat_ns = ":" Bar_list(Vertex) [ Common]. Common = "*common*". Construct_ns = "=". Vertex = DemIdent [ "*mark*" DemIdent ]. // parameterized classes List(S) ~ {S} . Nlist(S) ~ S {S}. Comma_list(S) ~ S {"," S}. Bar_list(S) ~ S {"|" S}. Cluster = "*clusters*" List(PartCluster) . PartCluster = "*source*" Vertex "(" List(Labeled_vertex) ")". Dummy = List(Vertex). Propagation Pattern: // computes the set of construction classes which are alternation- // reachable from vertex v in class dictionary graph cd. // alternation-reachable means by following only alternation edges. *operation* Vertex_Comma_list* find_assoc (Vertex* v, Cd_graph* cd) *init* (@ new Vertex_Comma_list(); @) *traverse* *from* UNKNOWN1 *bypassing* -> *,construct_ns,* , -> *,UNKNOWN2,* *to* {UNKNOWN3, UNKNOWN4} *wrapper* Cd_graph *suffix* (@ cout << "\n assoc " << v << " is " << return_val << "\n"; @) *wrapper* Adjacency *prefix* (@ if (source->g_equal(v)) { @) *suffix* (@ } @) *wrapper* UNKNOWN5 *prefix* (@ return_val -> append((Vertex *)(v -> g_copy())); cout << "\n Vertex appended in find_assoc " << v << "\n"; @) *wrapper* UNKNOWN6 *prefix* (@ cout << "\n alternative of " << v << " is " << this << "\n"; return_val -> concatenate(cd -> find_assoc(this, cd)); @) // concatenate combines two lists Propagation schema for traversal: Cd_graph = UNKNOWN7 . Adjacency = UNKNOWN8 . Neighbors : UNKNOWN9 . Alternat_ns = UNKNOWN10 . Construct_ns = UNKNOWN11 . Vertex = . UNKNOWN12 ~ { UNKNOWN13 } . UNKNOWN14 ~ UNKNOWN15 { UNKNOWN16 } . ///////////////////////////////////////////////////////////////// // There are 17 classes in total // There are 8 classes in the propagation schema // There are 9 classes not in the propagation graph ///////////////////////////////////////////////////////////// Trace output: IN Cd_graph::find_assoc IN Cd_graph::find_assoc IN Adjacency_List::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc IN Alternat_ns::find_assoc IN Vertex_Bar_list::find_assoc IN Vertex::find_assoc alternative of O is A IN Cd_graph::find_assoc IN Cd_graph::find_assoc IN Adjacency_List::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc IN Construct_ns::find_assoc Vertex appended in find_assoc A OUT Construct_ns::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc OUT Adjacency_List::find_assoc assoc A is A OUT Cd_graph::find_assoc OUT Cd_graph::find_assoc OUT Vertex::find_assoc OUT Vertex_Bar_list::find_assoc OUT Alternat_ns::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc IN Adjacency::find_assoc OUT Adjacency::find_assoc OUT Adjacency_List::find_assoc assoc O is A OUT Cd_graph::find_assoc OUT Cd_graph::find_assoc Operation find_assoc has two arguments: v and cd To produce the output above, how many classes does cd contain? cd contains UNKNOWN17 classes. What is the object v in sentence form (printed by g_print). v has external representation UNKNOWN18.