UNIVERSITY OF SWAZILAND

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

Object-Oriented Design (OOD) and C++

ADTs & Classes. An introduction

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

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

CS304 Object Oriented Programming Final Term

Abstraction in Software Development

CS304 Object Oriented Programming

CMSC 202 Final May 19, Name: UserID: (Circle your section) Section: 101 Tuesday 11: Thursday 11:30

Ch02. True/False Indicate whether the statement is true or false.

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

Launchpad Lecture -10

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.

An Introduction to C++

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING

Object Oriented Design

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009

CS201 Latest Solved MCQs

C++ Programming: Polymorphism

Exam 3 Chapters 7 & 9

And Even More and More C++ Fundamentals of Computer Science

Lecture 7. Log into Linux New documents posted to course webpage

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

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

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

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

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

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

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

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

Padasalai.Net s Model Question Paper

Introduction to Classes

CSI33 Data Structures

Midterm Examination. Instructor: Gary Chan Date: Saturday, 23 October 2010 Time: 2:30pm 4:00pm Venue: LTC

Object-Oriented Programming

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

/************************************************ * CSC 309/404 Review for Final -- Solutions * ************************************************/

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University

CS201- Introduction to Programming Current Quizzes

Interview Questions of C++

Object Oriented Paradigm

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

What does it mean by information hiding? What are the advantages of it? {5 Marks}

Chapter 13: Introduction to Classes Procedural and Object-Oriented Programming

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

Pointers, Dynamic Data, and Reference Types

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

An Object Oriented Programming with C

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

C++_ MARKS 40 MIN

Fast Introduction to Object Oriented Programming and C++

CE221 Programming in C++ Part 1 Introduction

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

Absolute C++ Walter Savitch

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

Introduction to Programming Using Java (98-388)

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

CS 247: Software Engineering Principles. ADT Design

Object Oriented Programming with c++ Question Bank

Abstract Data Types (ADT) and C++ Classes

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

BEng (Hons) Telecommunications. Examinations for 2016 / Semester 2

COEN244: Class & function templates

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

COP 3330 Final Exam Review

Advanced Systems Programming

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

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

Lab 2: ADT Design & Implementation

Implementing an ADT with a Class

Come and join us at WebLyceum

PIC 10A. Lecture 17: Classes III, overloading

Object Oriented Programming. Solved MCQs - Part 2

AN OVERVIEW OF C++ 1

Praktikum: Entwicklung interaktiver eingebetteter Systeme

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

2. It is possible for a structure variable to be a member of another structure variable.

University of Swaziland Department Of Computer Science Supplementary Examination JULY 2012

Computer Science 306 Study Guide

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

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

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

Variables. Data Types.

Determine a word is a palindrome? bool ispalindrome(string word, int front, int back) { Search if a number is in an array

Chapter 15: Object Oriented Programming

Special Member Functions

0. Overview of this standard Design entities and configurations... 5

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

Reference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that

Tokens, Expressions and Control Structures

III. Classes (Chap. 3)

Object Orientated Analysis and Design. Benjamin Kenwright

CS250 Final Review Questions

Transcription:

UNIVERSITY OF SWAZILAND DEPARTMENT OF COMPUTER SCIENCE CSC242 - OBJECT ORIENTED PROGRAMMING FINAL EXAMINATION MAY 2017 Instructions 1. The time allowed is THREE (3) H0URS. 2. Read all the questions in Section A and Section B before you start answering any question. 3. Answer all questions in Section A. Answer any two questions of Section B. Maximum mark is 100. 4. Use correct notation and show all your workon the answer script. DO NOT OPEN THIS PAPER UNTIL YOU ARE INSTRUCTED TO DO SO BY THE INVIGILATOR 1

Section A Question 1 [25] i What is a class? What is an object? And what is the relationship between a class and an object? [3] ii Name four differences between a class and a structure? [4J iii What is the default access specifier of a class? [1J iv What is a function call by reference? [2J v What are the properties of a constructor?[4] vi What is the difference between overload and override? [2] vii Name and explain three basic concepts of object oriented programming (OOP) [6]. viii What is a ternary (conditional) operator? With a suitable example statement to demonstrate how it is used in C++. [2] ix What is a precondition of a function? [1] Question 2 [25] a Explain the following function prototype. [5] char get(const int & x, int y) const; b Given the following constructor implemention of the class Car Carint x = 0, char y = 't', bool z = 0) / / class member variables initializing code added here Which object decleration statement is legal? [3] (a) Car thiscar(); 2

(b) Car thiscar; (c) Car thiscar(4); c Name 2 built in operations on classes. [2] d Using a suitable example, draw a UML diagram to demonstrate composition and inheritance. You may add explanations where neccessary.[6] e Given the following BASE class. class BASE private: int x protected: float y public: bool z; We are also given the following class called DERIVED defined as follows. class DERIVED: public BASE State whether each of the Base class member variables, x, y and z are accessible in following scopes? [9] (a) in objects of DERIVED type at the DERIVED class scope (b) in objects of DERIVED type, neither the DERIVED class scope nor the BASE class scope. (c) in objects of BASE type, that are neither the DERIVED class scope nor the BASE class scope. 3

Section B Question 3 [25] a Given the following declaration: int numj int *ptr1, *ptr2; double *ptr3; Mark the following statements as valid or invalid. If a statement is invalid, explain why. [10] i ptrl = ptr2; ii num ptrl; iii *ptr3 = *ptr2; iv ptrj = &ptr2 v num = *ptr2; vi ptr1 = num; vii num = &ptrl; b Write down 3 operators that cannot be overloaded in C++.[3] c Consider the following declaration: class stranger ; i Write a statement that shows the'declaration in the class stranger to overload the operator». [2] ii Write a statement that shows the declaration in the class stranger to overload the binary operator + as a member function. [2] 4

iii Write a statement that shows the declaration in the class stranger to overload the operator <= as a friend. [2] d With suitable code examples, demonstrate the difference between deep copy and shallow copy of data. [4] e Name two situations in which a copy constructor executes. [2] Question 4 [25] a Explain the following: [6] i pointer this ii friend function iii operator overloading b Write down the syntax for function t~mplate declaration and for class template decleration. [2] c Consider the following declaration: template <class type> class stranger private: type aj type b ; i Write a statement that declares sobj to be an object of type strange such that the private member variables a and b are of type into [2] ii Write a statement that shows the declaration in the class strange to overload the operator = = for the.,::lass strange as a member function. [2] iii Assume two objects of type strange are equal if their corresponding member variables are equal. Write the definition of the function operator for the class stranger, which is overloaded as a member function. [4] 5

d Consider the following statement: int * num; i Write the C++ statement that dynamically create an array of 10 components of type int and num contains the base address of the array. [2] ii Write a C++ code that inputs data into the array num from the standard input device.[4] iii Write the C++ statement that deallocates the memory space of array of which num points. [3] Question 5 [25] a Give two rea.."lons why do we place the cla.."ls definition file in the header file, and the definition of member functions in the implementation file? [2] b For class templates, why does the mechanism of separation of header files and implementation file not working? [2] c A class definition is sometimes written as follow: #ifndef H_LIST / /First Line #define H_LIST / /Second line class LIST ; #endif / / Last Line Explain the role played by the inclusion of the commented 3 lines. [3] d In C++, what isthe notation for the scope resolution operator? [1] e What is a mutator function? And what is an accessor junction? [2] f Consider the following base class definition. 6

class Base double bx; char ex; public: Base(char c = 'a', double b = 0.0 ); ; The defintion of Base constructor is as follows; Base::Base(char c, double u) bx = u; cx = Cj Let Derived be a class derived from Base. Assume Derived inherits all members from Base, and Derived has a single member variable dx which is not inherited from Base. i Write down a class definition of Derived. [3] ii Write a constructor function definition (implementation) for the class Derived. [4] g Mark the following statement as true or false. [4] i The order in which catch blocks are listed is not important. ii All exceptions need to be reported to avoid compilation errors. iii One way to handle an exception is to print an error message and exit the program. iv An exception can be caught either in the function where it occured or in any of the functions that led to the invocation of this method. h Explain the following function prototype, for a method in a class called Object. [3J *Object Comp(const Object & obj); 7