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

Similar documents
Chapter 5 Object-Oriented Programming

Inheritance, and Polymorphism.

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

Passing arguments to functions by. const member functions const arguments to a function. Function overloading and overriding Templates

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

What are the characteristics of Object Oriented programming language?

Polymorphism Part 1 1

Lecture-5. Miscellaneous topics Templates. W3101: Programming Languages C++ Ramana Isukapalli

SDV4001 Object Oriented Programming with C++ and UI Midterm 2013

This examination has 11 pages. Check that you have a complete paper.

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

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

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

Exam Duration: 2hrs and 30min Software Design

CS250 Final Review Questions

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

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

COMP322 - Introduction to C++

Inheritance, Polymorphism and the Object Memory Model

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

C++ Important Questions with Answers

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

CGS 2405 Advanced Programming with C++ Course Justification

CE221 Programming in C++ Part 1 Introduction

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

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Object Oriented Programming. Solved MCQs - Part 2

CS250 Final Review Questions

Inheritance and Polymorphism

IS 0020 Program Design and Software Tools

Polymorphism. Zimmer CSCI 330

Inheritance and Polymorphism

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Advanced Systems Programming

CS 376b Computer Vision

Come and join us at WebLyceum

Introduction to Programming Using Java (98-388)

University of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections

Inheritance and Polymorphism

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

Object Oriented Programming. Java-Lecture 11 Polymorphism

G Programming Languages - Fall 2012

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

Chapter 1: Object-Oriented Programming Using C++

CS260 Intro to Java & Android 03.Java Language Basics

Final Exam. Name: Student ID: Section: Signature:

ECE Fall 20l2, Second Exam

UNIVERSITY OF SWAZILAND

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example

Overview. C++ Tutorial. Arrays. Pointers. Strings. Parameter Passing. Rob Jagnow

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

Polymorphism. Arizona State University 1

CS304 Object Oriented Programming Final Term

CS 211 Winter 2004 Sample Final Exam (Solutions)

Prelim 1. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

OVERRIDING. 7/11/2015 Budditha Hettige 82

CS 251 Intermediate Programming Inheritance

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Chapter 3 Function Overloading

CS250 Final Review Questions

G52CPP C++ Programming Lecture 13

1. the base class s (default) constructor is executed first, 2. followed by the derived class s constructor

CS11 Introduction to C++ Fall Lecture 7

Common Misunderstandings from Exam 1 Material

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

CSE351 Winter 2016, Final Examination March 16, 2016

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

VALLIAMMAI ENGINEERING COLLEGE

CSc 328, Spring 2004 Final Examination May 12, 2004

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

C++ Crash Kurs. Polymorphism. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck

CS201 Some Important Definitions

a data type is Types

COP 3330 Final Exam Review

CS304 Object Oriented Programming

Lecture 10: building large projects, beginning C++, C++ and structs

Programming, numerics and optimization

Object-Oriented Design (OOD) and C++

Cmpt 135 Assignment 2: Solutions and Marking Rubric Feb 22 nd 2016 Due: Mar 4th 11:59pm

STRUCTURING OF PROGRAM

Final CSE 131B Winter 2003

C++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

C++ Mini-Course. Part 1: Mechanics Part 2: Basics Part 3: References Part 4: Const Part 5: Inheritance Part 6: Libraries Part 7: Conclusion. C Rulez!

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

Chapter 2. Procedural Programming

Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name:

CS201- Introduction to Programming Current Quizzes

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Chapter 15: Inheritance, Polymorphism, and Virtual Functions

Transcription:

Ministry of Higher Education Colleges of Applied Sciences Final Exam Academic Year 2009/2010 Course Number/Name: SFDV4001 Object-Oriented Programming & U.I. Date: Time: College: Sohar[ ] Ibri[ ] Rustaq[ ] Nizwa[ ] Sur[ ] Salalah[ ] Student s Name Group No. ID: Student Instructions for students This exam lasts for 2 hours and is worth 50% to your final mark for NETW3005 Please place all bags/folders etc at the front or back of the room. TURN OFF all mobile phones DO NOT TALK during the exam without permission from the invigilator Hand the exam paper back to your invigilator at the end of the exam For Lecturer use only Question Section A Multiple Choice (15 x 1) Section B Short Answer (10 x 2) Marks allotted 15 20 Marks scored A-Total B1 B2 B3 B4 B5 B6 B-Total B7 B8 B9 B10 Section C Long answers (3 x 5) 15 C1 C2 C3 C-Total Total 50 Exam Total Examiner: Checked by: Signature. Signature. Colleges of Applied Sciences Final Exam SFDV4001 Page 1 of 12

Section A: Multiple Choice Questions (1 mark each) 1. The following preprocessor directive is used #ifndef #define... #endif A. To replace identifier B. To avoid multiple inclusion of the declaration C. To include the specified file D. None of the above 2. Heap memory is allocated in C++ using A. delete B. new C. free D. malloc 3. The UML diagram that shows how objects interact via messages is called A. Use case diagram B. Sequence diagram C. Activity diagram D. Class diagram 4. The private members of a class can be accessed A. By members of any class B. Only by members of the same class C. Only by members of the parent class D. Only by members of the child class Colleges of Applied Sciences Final Exam SFDV4001 Page 2 of 12

5. Languages such as Java and C# can simulate multiple inheritance using A. Virtual function tables B. Pure virtual functions C. Pointers to functions D. Inner classes 6. Which of the following are stored in objects? A. Methods only B. Data only C. Both the data and methods D. Virtual function table 7. Which of the following are examples of deferred methods? A. Interfaces B. Virtual methods C. Abstract methods D. (A) & (C) 8. In a derived class, the abstract methods defined in an abstract base class A. Should be left as they are. B. Should be overridden in the derived class. C. Should be overloaded in the abstract base class itself D. None of the above 9. Correctness formula is of the form, A. P{B P{A B. {PA{Q, where A is an execution. C. {PQ D. None of the above 10. In C++, some of the possibilities for error handling include: A. Terminate the program B. Return a value representing an error C. (A) and(b) only Colleges of Applied Sciences Final Exam SFDV4001 Page 3 of 12

D. Call an error-handling routine, and(a) and(b) 11. The term that is not closely associated with Cohesion A. Coincidental B. Parameter C. Logical D. Functional 12. One of the following is not an intermediary class between client and workers A. Prototype B. Adapter C. Façade D. Proxy 13. One of the following is the style of user interface: A. Direct conversion B. Direct manipulation C. Direct overriding D. Direct overloading 14. Figure 1 shows the second version of Model-View-Controller. This figure implies that Controller is not responsible for Fig. 1: The second version of Model-View-Controller. A. Adding an observable to its model. B. Adding observers to its model. C. Initiating all state changes to its model. D. Instantiating a model. 15. The role of user interfaces in respect to a user and a domain model is to A. Allow the user to control the response of the domain model. Colleges of Applied Sciences Final Exam SFDV4001 Page 4 of 12

B. Connect the domain model to some platform specific codes. C. Represent some platform specific codes to the user. D. Represent the domain model to the user. Section B: Short Answer (2 marks each) 1. Write a C++ header which defines both the copy constructor and assignment operator of class X! class X { X(const X&); X&operator= (const X&); 2. What is the output of the following program? void foo( int ) { int e = 9; cout << d= << <<endl; int main( int argc, char * argv[]) { int a= 1; int = &a; int &e = a; d = 7; e = 8; cout << a= << a << endl; foo(d); return 0; a=8 d=8 Colleges of Applied Sciences Final Exam SFDV4001 Page 5 of 12

3. Consider the following classes. class AudioPlayer { virtual void play(); class VideoPlayer { virtual void play(); class AudioVideoPlayer : public AudioPlayer, public VideoPlayer { void play() { Find and explain the problem in the AudioVideoPlayer class! Solve the problem by using explicit disambiguation! The problem is name ambiguity. Explicit disambiguation: class AudioVideoPlayer : public AudioPlayer, public VideoPlayer { void play() { AudioPlayer::play(); VideoPlayer::play(); 4. What are the similarity and difference between overloading and overriding? Similarity: Both overloading and overriding use the same method name for different method bodies. Difference: Which actual method to call is determined at compile time for overloading and runtime for overriding. 5. What are polymorphic variables? Colleges of Applied Sciences Final Exam SFDV4001 Page 6 of 12

What is needed (or required), in order for you to be able to use polymorphic variables in C++? Polymorphic variables: a variable that can reference more than one type of object. Inheritance is needed for using polymorphic variables. For Example: Parent*p = new Child(); Here, Child is a derived class of Parent. 6. Based on the following codes, write a function operator, which can be used to multiply two objects of class Frac! class Frac { int b; int t; Frac( int top, int bottom) {t=top; b=bottom; Frac( int top) {t=top;b= 1; Frac operator (const Frac &right) { return Frac( t right.t, b right.b); 7. In the context of Design by Contract, when is a class said to be correct? A classis correct if and only if its implementation is consistent with the preconditions, post conditions and invariants. 8. Observe the following code. class MyClass { Colleges of Applied Sciences Final Exam SFDV4001 Page 7 of 12

void dosomething(set aset) { where MyClass and Set are two classes. Name the type of the coupling used, and justify your answer! The coupling used is parameter coupling. Here, aset, anobject invoked by MyClass, facilitates MyClass to invoke Set routines, i.e., one class invokes routines from another class via parameters. 9. All user interfaces must be interactive. Explain the meaning of this statement in terms of user action and feedback! Answer must contain at least two of the following. Allow a user to take actions. Present feedback on actions. Present feedback on the state of the system. 10. State two requirements for user interface that are pertinent to object, control and model! Answer must contain at least two of the following. User interface must Represent objects of interest. Provide alternative representations. Allow control via different mechanisms. Imply that the user interface must be loosely-coupled to the application model. Colleges of Applied Sciences Final Exam SFDV4001 Page 8 of 12

Section C: Long Answer (5 marks each) 1. Based on the class diagram depicted in Figure2, write three C++ headers which must show an inheritance for specification! c l a s s Shape { publ ic : v i r tua l void draw( )=0 ; ; c l a s s Ci r c l e : publ ic Shape { publ ic : void draw ( ) { ; c l a s s Square : publ ic Shape { publ ic : void draw ( ) { ; Colleges of Applied Sciences Final Exam SFDV4001 Page 9 of 12

2. Based on the following class, rewrite the ArraysMaxMin class as a template class using only one template method that can handle any type of array, such as int, float, double, long, etc! c l a s s ArrayMaxMin { / / find the maximum number in an integer array int findmax ( int arr[ ], int arrsize ) { int largest = arr [ 0 ] ; for ( int i = 0 ; i < arrsize; i ++) { i f (arr [ i ] > largest ) largest = arr [ i ] ; return largest ; / / find the maximum number in a float array float findmax ( f l o a t arr [ ], int arrsize ) { float largest = arr [ 0 ] ; for ( int i = 0 ; i < a r r s i z e ; i ++) { if (arr [ i ] > largest ) largest = arr [ i ] ; return largest ; ; template <c l a s s T> c l a s s Ar rayut i ls { publ ic : T findmax (T array [ ], int s i z e ) ; ; template <c l a s s T> T Ar rayut i ls<t>: : findmax (T array [ ], int s i z e ) { T largest = array [ 0 ] ; for ( int i = 0 ; i <s i z e ; i ++) { i f ( ar ray [ i ] > largest ) largest = array [ i ] ; return largest; Colleges of Applied Sciences Final Exam SFDV4001 Page 10 of 12

3. Explain internal data coupling, control coupling, and subclass coupling! Explain logical and temporal cohesion! Internal data coupling: the internal data of an object, A is accessed by other objects through the reference of A. Control coupling: when an object must perform operations in a fixed order, but the order is controlled elsewhere. Subclass coupling: the strength of association between a class and its parent. Logical cohesion: occurs when there is logical connection among the elements of the class but no actual connection in either data or control. Temporal cohesion: elements are bound together because they all must be used at approximately the same time. Colleges of Applied Sciences Final Exam SFDV4001 Page 11 of 12