DUBLIN CITY UNIVERSITY

Similar documents
DUBLIN CITY UNIVERSITY

EE219 Object Oriented Programming I (2007/2008) REPEAT SOLUTIONS

The Math Class (Outsource: Math Class Supplement) Random Numbers. Lab 06 Math Class

static int min(int a, int b) Returns the smaller of two int values. static double pow(double a,

12. Numbers. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Primitive Data Types: Intro

Chapter 5 Methods. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

CS110: PROGRAMMING LANGUAGE I

Expressions and operators

Using Free Functions

Chapter 5 Methods. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

To define methods, invoke methods, and pass arguments to a method ( ). To develop reusable code that is modular, easy-toread, easy-to-debug,

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Benefits of Methods. Chapter 5 Methods

1001ICT Introduction To Programming Lecture Notes

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Chapter 5 Methods / Functions

COP3502 Programming Fundamentals for CIS Majors 1. Instructor: Parisa Rashidi

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from

Chapter 6 Methods. Dr. Hikmat Jaber

JAVA Programming Concepts

EE219 Object Oriented Programming I (2006/2007) SEMESTER 1 SOLUTIONS

Lecture 2:- Functions. Introduction

Chapter 5 Methods. Modifier returnvaluetype methodname(list of parameters) { // method body; }

ECET 264 C Programming Language with Applications

Chapter 5 Methods. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

C Programs: Simple Statements and Expressions

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

Function. specific, well-defined task. whenever it is called or invoked. A function to add two numbers A function to find the largest of n numbers

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

Chapter 5 Methods. Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk

Preview from Notesale.co.uk Page 2 of 79

Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2010) - All Sections Midterm Examination

9 C Language Function Block

C++, How to Program. Spring 2016 CISC1600 Yanjun Li 1

Programmierpraktikum

C++ Programming Lecture 11 Functions Part I

COMP101: Introduction to Programming in JAVA. Reading: Morelli Chapter 0, Chapter 2, Chapter 3, Cohoon and Davidson Chapter 1. For pseudocode see

Procedural Abstraction and Functions That Return a Value. Savitch, Chapter 4

Chapter 4 Mathematical Functions, Characters, and Strings

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 2, Name:

MaSH Environment nxt. Contents

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

PASS$MOCK$EXAM$ $FOR$PRACTICE$ONLY$

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 6, Name:

1st and 3rd September 2015

Introduction to Programming

Lecture Static Methods and Variables. Static Methods

Programming in C Quick Start! Biostatistics 615 Lecture 4

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

Lecture Static Methods and Variables. Static Methods

DUBLIN CITY UNIVERSITY

Object-Oriented Programming

CSC 1051 Algorithms and Data Structures I. Midterm Examination March 1, Name: KEY A

Chapter 15 Graphing Functions and Data

Functions and an Introduction to Recursion Pearson Education, Inc. All rights reserved.

1.1 Your First Program

1.1 Your First Program! Naive ideal. Natural language instructions.

Sta$cs and forma.ng numbers

Functions and Recursion

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 26, Name: Key

Name CS/120 Sample Exam #1 -- Riley. a) Every program has syntax, which refers to the form of the code, and, which refers to the meaning of the code.

1.1 Your First Program

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination

Lecture 5. Functions II. Functions with Arguments. CptS 121 Summer 2016 Armen Abnousi

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

Chapter 3 - Functions

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Methods CSC 121 Fall 2014 Howard Rosenthal

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY

Using APIs. Chapter 3. Outline Fields Overall Layout. Java By Abstraction Chapter 3. Field Summary static double PI

The life and death of objects, sta2cs. CSCI 136: Fundamentals of Computer Science II Keith Vertanen

Calling Prewritten Functions in C


Use the dot operator to access a member of a specific object.

(2-2) Functions I H&K Chapter 3. Instructor - Andrew S. O Fallon CptS 121 (January 18, 2019) Washington State University

MaSH Environment graphics

Defining Classes II. 5.3 USING AND MISUSING REFERENCES 267 Example: A Person Class 267 Pitfall: null Can Be an Argument to a Method 275 CHAPTER

Classes. Classes as Code Libraries. Classes as Data Structures. Classes/Objects/Interfaces (Savitch, Various Chapters)

Trigonometric Functions of Any Angle

CS115 Principles of Computer Science

MATHEMATICAL / NUMERICAL FUNCTIONS

ENGI Introduction to Computer Programming M A Y 2 8, R E Z A S H A H I D I

Function Example. Function Definition. C Programming. Syntax. A small program(subroutine) that performs a particular task. Modular programming design

Midterm Exam 5 April 20, 2015

1.1 Your First Program

: Find the values of the six trigonometric functions for θ. Special Right Triangles:

HPC.NET - are CLI-based Virtual Machines Suitable for High Performance Computing?

Classes. Classes as Code Libraries. Classes as Data Structures

Using the um-fpu with the Javelin Stamp

Choose the correct answer below. 2. Convert the angle to a decimal in degrees.

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Single row numeric functions

Transcription:

DUBLIN CITY UNIVERSITY REPEAT EXAMINATIONS 2008 MODULE: Object-oriented Programming I - EE219 COURSE: B.Eng. in Electronic Engineering (Year 2 & 3) B.Eng. in Information Telecomms Engineering (Year 2 & 3) B.Eng. in Digital Media Engineering (Year 2) YEAR: 2 and 3 EXAMINERS: Dr. Derek Molloy (DCU Extension 5355) Dr. F. Owens TIME ALLOWED: 2 Hours INSTRUCTIONS: Please answer FOUR questions. All questions carry equal marks Please note that where a candidate answers more than the required number of questions, the examiner will mark all questions attempted and then select the highest scoring ones. Requirements for this paper Please tick (X) as appropriate Log Table Graph Paper Attached Answer Sheet Statistical Tables Floppy Disk Actuarial Tables THE USE OF PROGRAMMABLE OR TEXT STORING CALCULATORS IS EXPRESSLY FORBIDDEN PLEASE DO NOT TURN OVER THIS PAGE UNTIL YOU ARE INSTRUCTED TO DO SO EE219 Object-oriented Programming I Repeat Examination Page 1 of 5

Question 1 1(a) Examine the following segment of code that has several errors: 00 #include <iostream> 01 using namespace std; 02 03 class Shape 04 05 private: 06 float posx=0.0f, posy=0.0f; 07 public: 08 virtual Shape(float, float); 09 virtual void display(); 10 }; 11 12 13 class Circle : public Shape 14 15 float radius; 16 public: 17 Circle(float, float, float); 18 virtual void setradius(float); 19 virtual void display(); 20 }; 21 22 Shape::Shape(float x, float y): x(posx), y(posy) } 23 24 void Shape::display() 25 26 cout << "The Shape is at position (" << x << "," << y << ")\n"; 27 } 28 29 Circle::Circle(float rad, float x, float y): Shape(x,y), radius(rad) } 30 31 void Circle::display() 32 33 Circle::display(); 34 cout << " and a radius of " << rad << endl; 35 } 36 37 int main() 38 39 Circle c(20, 30); 40 c.display(); 41 return 0; 42 } Locate the 9 (approximate) errors and describe why you believe there is an error at that location. Use the line numbers to help you to explain your answers. [18 marks] 1(b) Organise the following concepts into suitable class hierarchies: television, channel, volume, DVD player, video player, LCD television, Plasma television, dimensions, aerial. Concisely explain the rationale for your groupings and create appropriate additional classes if required. [7 marks] EE219 Object-oriented Programming I Repeat Examination Page 2 of 5

Question 2 2(a) Examine the following class definitions: #include <iostream> #include <string> using namespace std; class Vehicle string color; string brandname; public: Vehicle(string, string); virtual void display(); }; class Car: public Vehicle int numberseats, numberdoors, numberwheels; }; public: Car(string, string, int, int, int); Car(Vehicle, int, int, int); virtual void display(); Write an implementation for each of the methods listed in the class definition. Write a main() function that would test the methods and all constructors. Write a class for a Motorbike that suits the example above. [22 marks] 2(b) Where s and t are strings, describe the working and output of this line of code: cout << (s.length() < t.length()? s : t); [3 marks] Question 3 3(a) Discuss the output of the following C++ control statements: - while (x<5) cout << The value of x is << x++ << endl; } - do cout << The value of x is << x++ << endl; } while (x<5); - for (x=0; x<5; x++) cout << The value of x is << x << endl; } - for (x=0; x<5; ++x) cout << The value of x is << x << endl; } Assuming that before each control statement x is an int with value 0. [5 marks] 3(b) Explain pass-by-value and pass-by-reference. Write a short segment of code to demonstrate the difference? 3(c) Describe C++ namespaces using a code example. Describe Java packages, again using a code example. How do C++ namespaces compare to Java packages? EE219 Object-oriented Programming I Repeat Examination Page 3 of 5

Question 4 4(a) Java applets generally do not have a main() method. What is the lifecycle of a Java applet and what standard methods do we have to implement? If we do not implement one of these methods, will the applet compile? 4(b) What is the output of this segment of C++ code? int z[5] = 1,2,3,4,5}; int *p = &z[0]; for (int i=0; i<5; i++) (*p)++; (*p++)++; } for (int i=0; i<5; i++) cout << "The value of x[" << i << "] is " << z[i] << endl; } [5 marks] 4(c) Describe the Java pre-defined variables super and this. Write a short piece of code to demonstrate their possible uses. Question 5 5(a) Write the following Java applet and associated HTML file: where the user inputs u and v as 2-D vectors and theta is the angle between these vectors in degrees, which is calculated automatically when the go button is pressed, according to the formula: θ = cos 1 ( u. v / u v ) where u.v = u 1 v 1 + u 2 v 2 and u = u + (similarly for v) 2 2 1 u2 Please see table Q5.1 to see the Math class methods available. [25 marks] EE219 Object-oriented Programming I Repeat Examination Page 4 of 5

Table Q5.1 The Math class methods Method Summary static double abs(double a) Returns the absolute value of a double value. static float abs(float a) Returns the absolute value of a float value. static int abs(int a) Returns the absolute value of an int value. static long abs(long a) Returns the absolute value of a long value. static double acos(double a) Returns the arc cosine of an angle, in the range of 0.0 through pi. static double asin(double a) Returns the arc sine of an angle, in the range of -pi/2 through pi/2. static double atan(double a) Returns the arc tangent of an angle, in the range of -pi/2 through pi/2. static double atan2(double y, double x) Converts rectangular coordinates (x, y) to polar (r, theta). static double ceil(double a) Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer. static double cos(double a) Returns the trigonometric cosine of an angle. static double exp(double a) Returns Euler's number e raised to the power of a double value. static double floor(double a) Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer. static double IEEEremainder(double f1, double f2) Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. static double log(double a) Returns the natural logarithm (base e) of a double value. static double max(double a, double b) Returns the greater of two double values. static float max(float a, float b) Returns the greater of two float values. static int max(int a, int b) Returns the greater of two int values. static long max(long a, long b) Returns the greater of two long values. static double min(double a, double b) Returns the smaller of two double values. static float min(float a, float b) Returns the smaller of two float values. static int min(int a, int b) Returns the smaller of two int values. static long min(long a, long b) Returns the smaller of two long values. static double pow(double a, double b) Returns the value of the first argument raised to the power of the second argument. static double random() Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. static double rint(double a) Returns the double value that is closest in value to the argument and is equal to a mathematical integer. static long round(double a) Returns the closest long to the argument. static int round(float a) Returns the closest int to the argument. static double sin(double a) Returns the trigonometric sine of an angle. static double sqrt(double a) Returns the correctly rounded positive square root of a double value. static double tan(double a) Returns the trigonometric tangent of an angle. static double todegrees(double angrad) Converts an angle measured in radians to an approximately equivalent angle measured in degrees. static double toradians(double angdeg) Converts an angle measured in degrees to an approximately equivalent angle measured in radians. EE219 Object-oriented Programming I Repeat Examination Page 5 of 5