CS246 Software Abstraction and Specification Final Examination

Similar documents
CS 122/132 Midterm Exam Winter 2003

Principles of Software Construction: Objects, Design, and Concurrency

CS 247 Software Engineering Principles Midterm Examination **Solutions** Spring 2017

CSE 70 Final Exam Fall 2009

CS 132 Midterm Exam Winter 2002

CS 132 Final Exam Winter 2005

Why Design by Contract! CS 619 Introduction to OO Design and Development. Design by Contract. Fall 2012

SDC Design patterns GoF

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

COURSE 2 DESIGN PATTERNS

CS 132 Midterm Exam Fall 2004

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Design patterns. Jef De Smedt Beta VZW

Today's Agenda. References. Open Closed Principle. CS 247: Software Engineering Principles. Object-Oriented Design Principles

Software Engineering I (02161)

EINDHOVEN UNIVERSITY OF TECHNOLOGY

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

CS 132 Midterm Exam Spring 2004

CS 349 Midterm Exam Spring 2014

Design Patterns. "Gang of Four"* Design Patterns. "Gang of Four" Design Patterns. Design Pattern. CS 247: Software Engineering Principles

CS 247: Software Engineering Principles. Design Patterns

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CSc 328, Spring 2004 Final Examination May 12, 2004

May Comp-B 11, Advanced Software Design. 3 hours duration

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

C++ (Non for C Programmer) (BT307) 40 Hours

The Strategy Pattern Design Principle: Design Principle: Design Principle:

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

MSO Exam November 7, 2016, 13:30 15:30, Educ-Gamma

Principles of Software Construction: Objects, Design, and Concurrency

Chapter 1: Principles of Programming and Software Engineering

In this Lecture you will Learn: Object Design. Information Sources for Object Design. Class Specification: Attributes

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

CSCI 102 Fall 2010 Exam #1

Exam in TDDB84: Design Patterns,

CSC 210, Exam Two Section February 1999

Principles of Software Construction: Objects, Design, and Concurrency

Chapter 5 Object-Oriented Programming

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

CPSC 310: Sample Final Exam Study Questions 2014S1 (These are in addition to the Study Questions listed at the end of some lectures)

Software Engineering I (02161)

Ministry of Higher Education Colleges of Applied Sciences Final Exam Academic Year 2009/2010. Student s Name

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

Dr. Manal Helal CC316:Object Oriented Programming, Fall 2015 AASTMT College of Engineering & Technology

LABORATORY 1 REVISION

Software Engineering

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7

COEN244: Class & function templates

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Object Oriented Paradigm

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

CS304 Object Oriented Programming

CSCI-1200 Data Structures Fall 2009 Lecture 25 Concurrency & Asynchronous Computing

download instant at The Relational Data Model

Final Exam. Final Exam Review. Ch 1: Introduction: Object-oriented analysis, design, implementation. Exam Format

Welcome to Design Patterns! For syllabus, course specifics, assignments, etc., please see Canvas

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT. Object Oriented Programming

C++ Inheritance and Encapsulation

EXAMINATION INSTRUCTIONS

Object Oriented Programming

Release Notes Build 395

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING

CS 162, Lecture 25: Exam II Review. 30 May 2018

CS 240 Final Exam Review

Problem Solving with C++

Object-Oriented Design

CS304 Object Oriented Programming Final Term

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Practice Problems. Review, with SOME solutions

SE 2 [CS 446, CS 646, ECE 452, SE 464] Software Design & Architecture Spring 2011 MIDTERM

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

JAVA MOCK TEST JAVA MOCK TEST II

What are the characteristics of Object Oriented programming language?

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Software Engineering I (02161)

CSSE 220. Interfaces and Polymorphism. Check out Interfaces from SVN

CMPE/SE 135 Object-Oriented Analysis and Design

Introduction to Design Patterns

CS 520 Theory and Practice of Software Engineering Fall 2018

Short Notes of CS201

PART A : MULTIPLE CHOICE Circle the letter of the best answer (1 mark each)

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University

CAS 703 Software Design

CMSC 331 Second Midterm Exam

CS 2505 Computer Organization I

Credit where Credit is Due. Lecture 4: Fundamentals of Object Technology. Goals for this Lecture. Real-World Objects

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

CS201 - Introduction to Programming Glossary By

Object-Oriented Design

INTERNAL ASSESSMENT TEST III Answer Schema

CS365 Midterm -- Spring 2019

Design patterns. OOD Lecture 6

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Exam Duration: 2hrs and 30min Software Design

During the first 2 weeks of class, all students in the course will take an in-lab programming exam. This is the Exam in Programming Proficiency.

A formal design process, part 2

Introduction to OO Concepts

Transcription:

CS246 Software Abstraction and Specification ination Spring 2007 Date: 04-Aug-2007 Time: 4.00 6.30pm Permitted Aids: None 14 pages Student Name: UW Student ID: Instructions: (Read carefully before the exam begins): 1. Before you begin, make certain that you have one Exam Booklet with pages numbered 1 14 printed double-sided. 2. The marks assigned to each question are shown at the beginning of the question; use this information to organize your time effectively. Question out of 1 10 2 15 mark marker s initials 3. Place all your answers in the spaces provided on these pages. 4. You do not need to write comments in your code unless it is specifically required by the question. 3 4 10 10 5. Questions will not be interpreted. Proctors will only confirm or deny errors in the questions. If you consider the wording of a question to be ambiguous, state your assumptions clearly and proceed to answer the question to the best of your ability. You may not trivialize the problem in your assumptions. 6. Cheating is an academic offense. Your signature on this exam indicates that you understand and agree to the University s policies regarding cheating on exams. 5 20 6 10 7 20 Total 95

Question 1. (10 marks) General Read each of the following statements carefully. For each statement, circle T if the statement is true and circle F if the statement is false. T / F In UML, a subclass inherits all of its parent class's OCL constraints. T / F In C++, if a class has pointer data members, then the class's destructor method should always delete those members' referenced objects. T / F In C++, all calls to virtual methods are resolved, to the specific function called, at runtime. T / F In C++, a const function is a function that does not modify any of its parameter variables. T / F In C++. nonmember functions are defined outside of any class definition. T / F In object-oriented programming, inheritance and object composition both promote code reuse. T / F In object-oriented programming, language constructs such as classes and objects realize designs that have good cohesion and loose coupling. T / F The primary purpose of Design Patterns is to ease the task of implementing a program. T / F In interface specifications, adding a precondition weakens a specification. T / F In general, the ideal program is one in which all packages are completely stable (i.e., have a stability measure of 1). Aug 4, 2007 Page 2 of 14 CS 246 S07

Question 2. (15 marks) C++ 2a. (10 marks) Pointers Provide a C++ implementation that satisfies the following function interface and specification. Be sure to avoid potential memory leaks and segmentation faults. The Supplemental Materials sheets includes a list of operations on STL vector containers. #include <vector> void DeepCopyVector (const std::vector<int*> *v1, std::vector<int*> *v1copy) // modifies: contents of vector *v1copy // ensures: vector *v1copy is a vector of pointers to new integer variables. Each element in // *v1copy points to a new integer variable whose value is the same as the variable // pointed to by the corresponding element in v1. The size of *v1copy equals the // size of *v1. Aug 4, 2007 Page 3 of 14 CS 246 S07

Question 2. [continued] 2b. (5 marks) Polymorphism The following set of program fragments define a base class, a derived class, and a main program that uses both classes. The main class includes 10 method calls. For each method call, indicate in the comment following the call how that call is resolved: 1. Base::aMethod() 2. Base::bMethod() 3. Base::cMethod() 4. Derived::aMethod() 5. Derived::bMethod() 6. Derived::cMethod() 7. Derived::dMethod() 8. none of the above - compiler error 9. none of the above - runtime error Each method call is followed by a comment and label, where you should write your answer. In your answers, you may simply use the above number labels rather than writing out the entire answer. For each method call, assume that all previous statements were successful (i.e., did not result in compiler or runtime errors). class Base { public: void amethod(); virtual void bmethod(); virtual void cmethod(); } class Derived : public Base { public: void amethod(); virtual void bmethod(); virtual void dmethod(); private: virtual void cmethod(); } int main (void) { Base *b = new Derived(); b->amethod(); b->bmethod(); b->cmethod(); b->dmethod(); Derived d; d.amethod(); d.cmethod(); d.dmethod(); Base b1 = d; b1.amethod(); b1.bmethod(); b1.cmethod(); // (a) // (b) // (c) // (d) // (e) // (f) // (g) // (h) // (i) // (j) Aug 4, 2007 Page 4 of 14 CS 246 S07

Question 3. (10 marks) UML This question asks you to evaluate a UML class diagram and to enhance the model with appropriate UML structural constructs. The class diagram models key parts of an inventory and transactions system for a small coffee and doughnut shop called the C&D. The C&D sells a number of different types of Products. Each Product is identified by a unique product number (prodid). Product numbers are automatically generated when new Products are added to the inventory (via method newprodid()). The inventory system keeps track of how many items of each Product the C&D currently has in stock; it also is responsible for notifying the C&D manager when the instock quantity of a Product falls below a specified threshold, so that the manager can order more. The C&D buys its products from Suppliers. For each Product, the inventory system keeps track of all the Suppliers from which the shop can buy that Product. Some Products can be purchased from more than one Supplier. The inventory maintains a record of each PurchaseOrder that is made, including the Supplier, the quantities of Products ordered, their costs, taxes on the order (PST and GST), and the total cost of the order. The C&D sells food to customers who walk in the door. There is no attempt to keep records of customers. But the system does maintain a record of each Sales transaction, including the Products purchased, the taxes on the Sale, and the total bill of the Sale. The Sale of a Product causes the system to immediately update its record of how many items of that Product the C&D has in stock. Supplier 1..* 1 prodid 1 C&D + order (prodid, int) - newprodid : prodid 1 * Sale PST : double GST : double total cost : double 1 * * prodid 1 1 * 1..* PurchaseOrder PST : double GST : double total cost : double * Product instock : integer saleprice : double threshold : integer + sale (int) + delivery (int) * quantity : integer purchaseprice : double 3a. (5 marks) UML Structures, Navigability Based on the above description of the program and what information needs to be recorded and maintained, detail each of the association ends in the above model with structure (composition, aggregation) and with navigability. (There is only one C&D shop, so all multiplicities on associations to the C&D class are 1). Aug 4, 2007 Page 5 of 14 CS 246 S07

Question 3. [continued] The UML model given on the previous page is not necessarily the best model of the C&D inventory and sales transaction system. Below are questions about two different modelling decisions that need to be made. For each question, say which modelling decision is better and explain why. For your convenience, the UML model is duplicated in the Supplemental Materials sheets. 3b. (3 marks) Association Classes In the model on the previous page, a PurchaseOrder is modelled as an ordinary class. Alternatively, we could have modelled PurchaseOrder as an association class of the relationship between the C&D and a Supplier. Supplier 1..* 1 prodid C&D + reorder (prodid, int) PurchaseOrder PST : double GST : double total cost : double Which modelling decision is better for this program and why? (Hint: think about the definition of an ordinary association.) 3c. (2 marks) Qualifiers In the model on the previous page, product numbers are modelled as association qualifiers. Alternatively, we could have modelled product numbers as attributes of the Product and Supplier classes. Which modelling decision is better for this program and why? Aug 4, 2007 Page 6 of 14 CS 246 S07

4. (10 marks) Implementing UML Associations This question is based on the annotated UML model that you created in Question 3a, including navigation and structure. 4a. (5 marks) Provide a partial C++ class declaration for the C&D class that realizes the class's associations with Product and Supplier. The class declaration must be complete in declaring all data members, function members, and access specifiers that are needed to implement the class and the two associations to Product and Supplier (do not include data or function members to realize the class's other associations). 4b. (5 marks) Provide a C++ definition for the C&D method to add a new Product. The definition of the method addproduct(...) must realize the two associations' multiplicity and navigation constraints. Use representative names in your declarations. The Supplemental Materials sheets includes partial lists of operations for several STL containers. If you need to, you can assume that the type prodid supports comparison with operator<. Aug 4, 2007 Page 7 of 14 CS 246 S07

Question 5. (20 marks) Exceptions and Specifications The following question refers to the IntVector class defined (partially) on the last page of the Supplemental Materials sheets for this exam. In this question, you are to rewrite the class declaration for IntVector to include declarations of the exceptions that might be thrown by the IntVector's methods and to include a proper interface specification. For each condition that could cause a run-time error in one of IntVector's methods, identify the likely standard library exception that would be raised when that condition occurs. (Don't worry about identifying which of two similar exceptions might be thrown for a particular condition. Simply state your assumptions). All exceptions that are raised in the IntVector class will be passed back to the calling code; none will be handled in the IntVector class. Rewrite below the C++ class declaration for the IntVector, so that (10 marks) Each method declaration specifies the exceptions that can be raised in that method, and (10 marks) The class declaration includes as comments an interface specification (contract) Aug 4, 2007 Page 8 of 14 CS 246 S07

Question 6. (10 marks) Design Patterns (multiple choice) 6a. (4 marks) (match each Design Pattern on the left with its description on the right) (a) Composite Pattern (b) Decorator Pattern (c) Strategy Pattern (d) Template Pattern 1. Creates a single interface for a collection of objects 2. Creates a single interface for a collection of operations that can operate on specific types of objects. 3. Creates a single interface for a collection of algorithms that access the members of a collection of objects. 4. Creates a single interface for a collection of algorithms that can be used interchangeably to "implement" an object's method. 5. Create a single interface for a collection of features (extra functionality) that can be added to an object 6. Modifies the interface of an object (without adding functionality) 7. Creates interfaces for steps of an algorithm (ensures that subclasses execute the same algorithm, but can specialize the steps) 6b. (2 marks) (circle the most relevant answer) The Factory Method is useful for (a) encapsulating the construction of a concrete object. (b) constructing decorated objects with the right decorators. (c) constructing the appropriate iterator for a composite object. (d) all of the above 6d. (2 marks) (circle the two most relevant answers) The Observer Pattern promotes which of the following design principles: (a) program to an interface, not to an implementation (b) Liskov substitutability principle (c) dependency inversion (d) principle of least knowledge (e) don't repeat yourself (f) open-closed principle 6e. (2 marks) (circle the two most relevant answers) The Visitor Pattern promotes which of the following design principles: (a) program to an interface, not to an implementation (b) Liskov substitutability principle (c) dependency inversion (d) principle of least knowledge (e) don't repeat yourself (f) open-closed principle Aug 4, 2007 Page 9 of 14 CS 246 S07

Question 7. (20 marks) Design Patterns (application) This question asks you to use two design patterns to extend the following UML design. For your convenience, the model below is duplicated in the Supplemental Materials sheets. InternetFlix is an internet-based DVD rental company. Customers can ask about the availability of movies and can request to borrow movies (up to 2 movies at a time). The company mails the DVDs out to the customer, and the customer mails the DVDs back when he is done with them. The rental period is four weeks. There is a fee for renting a particular movie (movies have different fees based on whether they are new releases). There is a late fee (assessed daily) for not returning a movie before the end of the rental period. InternetFlix checkavail(movie) : boolean checkout(movie) checkin(move) 1 0..1 * Movie title : string onloan : boolean rentalfee: Money latefee: Money loanperiod: duration 1 * Account balance : Money borrow (Movie) return (Movie) 0..1 0..2 0..1 Loan duedate: Date Aug 4, 2007 Page 10 of 14 CS 246 S07

Question 7. [continued] 7a. (10 marks) Decorator Pattern Use the Decorator Pattern to revise the UML model to offer a Subscription service. If a customer subscribes to this service, then instead of asking to borrow movies one at a time, the customer, as part of this service, maintains a queue of movies that he is interested in renting. Whenever the customer has fewer than two movies out on loan (e.g., whenever a movie is returned), the company finds an available movie that is on the customer's request queue and sends the movie to the customer. With this service, there is no rental fee per loan, no loan period, no late fee. Instead, the customer pays a fixed monthly fee for the privilege of always having two movies out on loan. Your revisions to the UML model should include any new classes, data members, and methods to (1) realize the Decorator Pattern and (2) realize the new Subscription decorator. Aug 4, 2007 Page 11 of 14 CS 246 S07

Question 7. [continued] 7b. (10 marks) Visitor Pattern Use the Visitor Pattern to revise the original UML model to allow for the easy addition of operations that operate over all the loans. Include in your revised model a new visitor operation OutstandingFines that computes the total amount of outstanding fines for all overdue movies. Your revisions to the UML model should include any new classes, data members, and methods to (1) realize the Visitor Pattern and (2) realize the new OutstandingFines operation. Aug 4, 2007 Page 12 of 14 CS 246 S07

Extra Space for Any Question Aug 4, 2007 Page 13 of 14 CS 246 S07

Extra Space for Any Question Aug 4, 2007 Page 14 of 14 CS 246 S07