Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2

Similar documents
Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

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

Module Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1

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

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

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

Answer BOTH questions from Section A and ONE question from Section B.

CS2141 Software Development using C/C++ C++ Basics

CE221 Programming in C++ Part 1 Introduction

The University of Nottingham

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

Introduction to Programming Using Java (98-388)

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

An overview of Java, Data types and variables

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)

ECE Fall 20l2, Second Exam

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Short Notes of CS201

Do not turn over until you are told to do so by the Invigilator.

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

CS201 - Introduction to Programming Glossary By

Bristol Institute of Technology

CS201 Some Important Definitions

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING

COMP 2355 Introduction to Systems Programming

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

Chapter 3 Process Description and Control

Final CSE 131B Spring 2004

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

Introduction to Programming using C++

Contents. 6-1 Copyright (c) N. Afshartous

Homework 4. Any questions?

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Character Stream : It provides a convenient means for handling input and output of characters.

Exam Duration: 2hrs and 30min Software Design

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

COP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME

Advanced Systems Programming

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

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

Modern Programming Languages. Lecture Java Programming Language. An Introduction

Procedures, Parameters, Values and Variables. Steven R. Bagley

Compositional C++ Page 1 of 17

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

File IO and command line input CSE 2451

C:\Temp\Templates. Download This PDF From The Web Site

Chapter 14 - Advanced C Topics

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Introduction to Java

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Approximately a Test II CPSC 206

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

1.Which four options describe the correct default values for array elements of the types indicated?

6.096 Introduction to C++ January (IAP) 2009

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

3. Java - Language Constructs I

Computer Components. Software{ User Programs. Operating System. Hardware

PROGRAMMAZIONE I A.A. 2017/2018

Arrays and Pointers in C. Alan L. Cox

de facto standard C library Contains a bunch of header files and APIs to do various tasks

CSC 1214: Object-Oriented Programming

Multiple Choice Questions. Chapter 5

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

UNIVERSITY OF EAST ANGLIA School of Computing Sciences May/June UG Examination EMBEDDED SYSTEMS CMPE3D02. Time allowed: 3 hours

Midterm assessment - MAKEUP Fall 2010

What is a thread anyway?

Data Types and Computer Storage Arrays and Pointers. K&R, chapter 5

ECE 462 Midterm Exam 2. 10:30-11:20AM, October 19, 2007

ECE 462 Fall 2011, Third Exam

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

Kickstart Intro to Java Part I

Java and OOP. Part 2 Classes and objects

Java Basic Syntax. Java vs C++ Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

1 Shyam sir JAVA Notes

C++ Important Questions with Answers

Project. Threads. Plan for today. Before we begin. Thread. Thread. Minimum submission. Synchronization TSP. Thread synchronization. Any questions?

Course Outline. Introduction to java

Pointers as Arguments

Understanding Pointers

Lecture Contents. 1. Overview. 2. Multithreading Models 3. Examples of Thread Libraries 4. Summary

The University of Nottingham

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

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING

CORE JAVA TRAINING COURSE CONTENT

Programming in C++ 4. The lexical basis of C++

CISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters.

Two hours QUESTION PAPER MUST NOT BE REMOVED FROM THE EXAM ROOM UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

2 2

Subject: Fundamental of Computer Programming 2068

Lecture 5: Methods CS2301

Stream Computing using Brook+

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

From Java to C. Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides

Transcription:

UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2014/15 PROGRAMMING 2 CMP-5015Y Time allowed: 2 hours Answer four questions. All questions carry equal weight. Notes are not permitted in this examination. Do not turn over until you are told to do so by the Invigilator. CMP-5015Y Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2

Page 2 1. (a) A class can be threaded by extending Thread or implementing Runnable. Which is better, and why? Describe with code segment examples how you define a class that can be threaded (using either Thread or Runnable) and how an object of that class could be run in its own thread. (b) What is the output of the following code? [6 marks] [3 marks] public static class Player extends Thread{ int id; Player op; public Player(int n){id=n; public void connect(player other){ op=other; public void run(){ if(op!=null){ try { op.join(); catch (InterruptedException ex) { System.out.println(" INTERRUPTED"); System.out.println("PLAYER ID ="+id); public static void main(string[] args) { Player p1=new Player(1); Player p2=new Player(2); p1.connect(p2); p1.start(); p2.start(); CMP-5015Y Version 2

Page 3 (c) What is a monitor lock? [2 marks] (d) Describe, with code examples, different ways of claiming a monitor lock in Java with the keyword synchronized. (e) Describe, with examples, three common problems that can be encountered with concurrent programming and give scenarios where they are likely to occur. [9 marks] 2. (a) What is a nested class? [2 marks] (b) How do nested classes differ in Java and C++? [2 marks] (c) Describe the four types of nested class in Java. Give an indication of when you should use each type. [12 marks] (d) Demonstrate the usage of each type of nested class by implementing Comparator nested classes for the Person class. Your solution should be a complete new version of the Person class. Include a static method that uses each type of Comparator nested class to sort an array of Person objects. Use a different attribute to sort with each nested class, and sort with Arrays.sort. [14 marks] public class Person{ String firstname; int age; double weight; char sex; CMP-5015Y Version 2 TURN OVER

Page 4 3. (a) What is an enum type in Java? Give an example of how to define one. [4 marks] (b) How do enum types in Java differ from enum types in C++? What are the benefits of Java enum types? [6 marks] (c) Explain how C++, Java and C# differ in relation to how they implement inheritance, including mechanisms for abstract methods/member function. [12 marks] (d) Explain the difference between C++ templates, Java generics and C# generics in terms of how the code is compiled. What are the benefits and problems of each approach? [8 marks] 4. (a) What is the output of the following program? #include <stdio.h> #include <stdlib.h> #define PRINTX printf("x = %i\n", x); int main(int argc, char **argv) { int x = 2, y, z; x *= 3 + 2; PRINTX; x *= y = z = 4; PRINTX; x = y == z; PRINTX; x == (y=z); PRINTX; x = ++y - z--; PRINTX; return EXIT_SUCCESS; (b) What type of variable is created in each of the following declarations? Where the declaration will not compile, or potentially cause an error, explain why this is the case. [5 marks] CMP-5015Y Version 2

Page 5 (i) const int a; (ii) const double * const p = &d; (iii) unsigned u = 042; (iv) char s[] = { h, e, l, l, o ; (v) int (*compare)(int,int); (c) Write a C function, range that returns the difference between the largest and smallest values contained in array of double precision floating point values provided as an argument to the function. (d) The following macro definition has two deficiencies; explain the deficiencies and give a revised macro definition that addresses both problems. [5 marks] #define SQUARE(x) x*x 5. (a) A file, data.txt, contains an unknown number of integer values, one value being given on each line of the file. Write a C code fragment to compute the average (mean) of the numbers in the file. (b) Explain what is meant by the Rule of three in C++ programming. (c) What is the purpose of the following C++ code fragment? int numbers[] = {-4, +3, -2, -3, 9, 42, 3; int previous = 0; for (int &current : numbers) { int temp = previous; previous = current; current = current>temp?current-temp:temp-current; What does the array contain after execution of the fragment? CMP-5015Y Version 2 TURN OVER

Page 6 6. (a) Explain the differences between pointers and references in the C++ and Java programming languages. (b) Write a C++ class definition describing a time of day, where the hour of the day and minute of the hour are represented as integers. The class should include appropriate constructors, accessor methods, overloaded operators supporting the use of stream I/O, and overloading of the subtraction operator to determine the difference between two Time objects, expressed in minutes. [20 marks] END OF PAPER CMP-5015Y Version 2