Multimedia Programming

Similar documents
Object-Oriented Software Engineering (Re-exam for Object-Oriented Analysis, Design and Programming)

Object-Oriented Software Engineering Re-exam, 2012 (Also Object-Oriented Analysis, Design and Programming, Re-exam, 2012)

Multimedia Programming Examination 2012

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Network Programming. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Midterm assessment - MAKEUP Fall 2010

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

PART1: Choose the correct answer and write it on the answer sheet:

CS 2113 Software Engineering

Chapter 2. Network Chat

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming

CPSC 441 Tutorial TCP Server. Department of Computer Science University of Calgary

CS108, Stanford Handout #22. Thread 3 GUI

Lab 1 : Java Sockets

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015

Input from Files. Buffered Reader

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Answer on question #61311, Programming & Computer Science / Java

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CSCI 201L Midterm Written Summer % of course grade

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2012

1 Looping Constructs (4 minutes, 2 points)

CS 5010: PDP. Lecture 11: Networks CS 5010 Fall 2017 Seattle. Adrienne Slaughter, Ph.D.

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Networking Code CSCI 201 Principles of Software Development

"protocol stack! chat. Java

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2012

protocols September 15,

THIS EXAMINATION PAPER MUST NOT BE REMOVED FROM THE EXAMINATION ROOM

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

H212 Introduction to Software Systems Honors

CS September 2017

Graphical User Interface

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

Object- Oriented Analysis, Design and Programming

CSCI 201L Midterm Written SOLUTION Summer % of course grade

CSCD 330 Network Programming Spring 2018

Forward rendering. Unity 5's rendering paths. Which lights get what treatment?

SampleApp.java. Page 1

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Object- Oriented Analysis, Design and Programming. Instructions. Medialogy, 4 th Semester, Aalborg. Tuesday 30 August 2011,

RAIK 183H Examination 2 Solution. November 11, 2013

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

Object- Oriented Analysis, Design and Programming

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Module 6: Binary Trees

Distributed Programming - Sockets

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

RAIK 183H Examination 2 Solution. November 10, 2014

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

Networking Basics. network communication.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Internet Technology 2/7/2013

Principles, Models, and Applications for Distributed Systems M

CS171 Midterm Exam. October 29, Name:

Phase 2: Due 11/28/18: Additional code to add, move and remove vertices in response to user mouse clicks on the screen.

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Question Points Score Total 100

CS171 Final Practice Exam

7. Sketch mode: Description of system for communicating specific information to humans that leaves out many details that are not required.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

COURSE DESCRIPTION. John Lewis and William Loftus; Java: Software Solutions; Addison Wesley

CS301 - Data Structures Glossary By

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2013

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

UTM CSC207: Midterm Examination October 28, 2011

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

F I N A L E X A M I N A T I O N

Final Exam. COMP Summer I June 26, points

Phase 2: Due 05/02/18 The Gui now stores and displays a graph in response to user mouse clicks on the screen.

CSE373 Fall 2013, Midterm Examination October 18, 2013

CMP 326 Midterm Fall 2015

CS1092: Tutorial Sheet: No 3 Exceptions and Files. Tutor s Guide

Pieter van den Hombergh Richard van den Ham. March 17, 2018

Reading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.

Give one example where you might wish to use a three dimensional array

CS171 Final Practice Exam

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

CS 355. Computer Networking. Wei Lu, Ph.D., P.Eng.

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

First Name: AITI 2004: Exam 2 July 19, 2004

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Advanced Java Programming. Networking

APPENDIX. public void cekroot() { System.out.println("nilai root : "+root.data); }

Soda Machine Laboratory

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

Data Structure and Algorithm, Spring 2013 Midterm Examination 120 points Time: 2:20pm-5:20pm (180 minutes), Tuesday, April 16, 2013

Unit 9: Network Programming

CMSC132, Practice Questions

Principles, Models, and Applications for Distributed Systems M

Contents Chapter 1 Introduction to Programming and the Java Language

COMP16121 Sample Code Lecture 1

Transcription:

Multimedia Programming Medialogy, 8 th Semester, Aalborg University Wednesday 6 June 2012, 09.00 12.00 Instructions and notes You have 3 hours to complete this examination. Neither written material nor electronic equipment may be brought into the examination room. There are 12 questions and each question is worth 10 marks. The maximum possible score is 120 marks. You must get at least 50 marks to pass. Note that a number at the beginning of any line in a program listing or pseudocode indicates the number of that line and is not part of the program or algorithm itself. DO NOT UNTIL INSTRUCTED TO DO SO! END OF EXAMINATION

Question 1 The following pseudocode defines the insertion sort algorithm. Show that the worstcase running time of insertion sort is Θ(n 2 ). 2

Question 2 Choose one of the patterns described by Gamma et al. (1995) and answer the following questions about it: a. What is the name of the pattern you have chosen? b. Give an example of a problem that your chosen pattern solves. c. Briefly describe how the pattern solves problems like the one you mentioned in part b. d. What are the typical costs and benefits of applying your chosen pattern? 3

Question 3 a. Explain, with an example, what is meant by the race condition in multi-threaded programming. b. Study the following Java program and answer the questions that follow it. 1 public class Threads { 2 public static Integer balance = 100; 3 4 static class ChangeRunnable implements Runnable { 5 int x; 6 7 ChangeRunnable(int x) { 8 this.x = x; 9 10 11 public void run() { 12 try{ 13 Thread.sleep((long)Math.random()*1000); 14 int b = balance; 15 Thread.sleep((long)Math.random()*1000); 16 b += x; 17 Thread.sleep((long)Math.random()*1000); 18 balance = b; 19 catch(exception e) { 20 e.printstacktrace(); 21 22 23 24 25 public static void main(string[] args) { 26 try { 27 Thread plus10 = new Thread(new ChangeRunnable(10)); 28 Thread minus5 = new Thread(new ChangeRunnable(-5)); 29 plus10.start(); 30 minus5.start(); 31 plus10.join(); 32 minus5.join(); 33 System.out.println(balance); 34 catch (InterruptedException e) { 35 e.printstacktrace(); 36 37 38 i. What are the possible outputs of this program? ii. How would you modify the program so that it always generates the same output every time it is run? iii. Discuss whether this modified version of the program should be considered multi-threaded. 4

Question 4 a. Explain the difference between UDP and TCP. Which protocol would you use for each of the following applications: i. A time server. ii. FTP iii. ping b. Suppose we have two Java programs, Client and Server. The Server program is defined as follows: import java.io.bufferedreader; import java.io.inputstreamreader; import java.io.printwriter; import java.net.serversocket; import java.net.socket; public class Server { public static void main(string[] args) { try { ServerSocket serversocket = new ServerSocket(50000); Socket clientsocket = serversocket.accept(); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); String line = in.readline(); System.out.println(line); out.println(line+" to you too!"); out.close(); in.close(); clientsocket.close(); serversocket.close(); catch (Exception e) { e.printstacktrace(); (continued) 5

The Client program is defined as follows: import java.io.bufferedreader; import java.io.inputstreamreader; import java.io.printwriter; import java.net.socket; public class Client { public static void main(string[] args) { try { Socket socket = new Socket("localhost",50000); PrintWriter out = new PrintWriter(socket.getOutputStream(),true); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out.println("hello"); System.out.println(in.readLine()); out.close(); in.close(); socket.close(); catch (Exception e) { e.printstacktrace(); i. When running this system, which of the two programs should be started first? ii. What is printed out to the console window by the Server program? iii. What is printed out to the console window by the Client program? iv. Explain the difference between a BufferedReader, an InputStreamReader and an InputStream. v. To what does the number 50000 refer in the first line of the try block in each program? 6

Question 5 a. Name the three different types of thread used in a Swing program and briefly describe the function of each. b. Study the following Java program and answer the questions that follow it. 1 import java.awt.borderlayout; 2 import java.awt.event.actionevent; 3 import java.awt.event.actionlistener; 4 import javax.swing.jframe; 5 import javax.swing.jlabel; 6 import javax.swing.jtextfield; 7 import javax.swing.swingutilities; 8 9 public class GUI extends JFrame implements ActionListener { 10 11 private static final long serialversionuid = 1L; 12 private JTextField text = new JTextField(); 13 private JLabel label = new JLabel(); 14 15 public GUI() { 16 settitle("gui"); 17 setdefaultcloseoperation(jframe.exit_on_close); 18 getcontentpane().add(text); 19 getcontentpane().add(label,borderlayout.line_start); 20 text.addactionlistener(this); 21 pack(); 22 setvisible(true); 23 24 25 public void actionperformed(actionevent event) { 26 label.settext("text: "+text.gettext()); 27 28 29 public static void main(string[] args) { 30 SwingUtilities.invokeLater(new Runnable() { 31 public void run() { 32 new GUI(); 33 34 ); 35 36 i. What kind of layout manager does the program use? Briefly describe how this type of layout manager behaves. ii. Give the variable name and type of each component that appears in the GUI. iii Which object in the program serves as an ActionListener? iv. What does this ActionListener do? v. What does the statement, pack(), do in the sixth line of the constructor? 7

Question 6 a. Let n be an integer and let f(n) be a function of n. Explain precisely what it means if we say that f(n) = Θ(g(n)). b. Show that, if f(n) = 4n 2 + 3n, then f(n) = Θ(n 2 ). c. Give the worst case running time in terms of O-notation for the following method: public static void unknown(int n) { for(int i = 0; i < n; i++) { for(int j = 0; j < Math.log(n); j++) System.out.print(i+" "); System.out.println(); System.out.println(); 8

Question 7 a. The height of a node in a heap is defined to be the length of the longest simple downward path from the node to a leaf. Why is it defined in this way, rather than just the length of the downward path from the node to a leaf? b. State the min-heap property and draw a tree representation of an example of a minheap with at least 7 nodes in it. How would this min-heap be stored as an array? c. If A is an array of integers that represents a max-heap and i is the index of a node in this heap, the following pseudocode shows the MAX-HEAPIFY algorithm: Describe briefly what MAX-HEAPIFY does and explain why it has a worst-case running time of O(lg(n)). 9

Question 8 a. Explain the difference between a stack and a queue. b. The following array implements a queue, Q, with the head and the tail of the queue as indicated in the diagram: i. What value will be returned by the next call to DEQUEUE on this queue? What will be the new position of the head of the queue after this call? ii. What is the index of the position into which the next element will be inserted when ENQUEUE is next called? What will be the new position of the tail of the queue after this call? iii. If the head position is 12 and DEQUEUE is called, what will be the new position of the head after the call? 10

Question 9 a. FPGA stands for Field Programmable Gate Array. i. What does gate array refer to? ii. What does field programmable refer to? b. Study the following figure, which shows two FPGA architecture syles, and answer the questions that follow it. i. What are the typical architectural elements in modern FPGAs? ii. What are their respective roles? iii. What are the two architectural styles represented in the figure above? c. The following figure shows a LUT-based configurable logic element. What is the LUT mostly used for? 11

Question 10 a. Study the following figure and answer the questions that follow it Most FPGAs are based on SRAM, Flash, anti-fuse or fuse technologies. i. Identify these technologies in the figure above. ii. What are their respective advantages and drawbacks? iii. Which one is most commonly used? b. What is the difference between a hard-core (hardwired) and a soft-core microprocessor? c. Study the following figure, which shows a generic FPGA design flow, and explain what happens in each of the steps. Note that the map step shown on the right hand side is not shown on the left-hand side; do not forget to describe it. 12

Question 11 a. What kind of problems can dynamic programming be used to solve efficiently? b. The following algorithm is a recursive solution to the rod-cutting problem, where n is the length of the rod and p is the price array, giving the revenue for each rod length: Explain why this algorithm is inefficient. c. Sketch an efficient dynamic programming solution to the rod-cutting problem that uses a bottom-up method. (HINT: Use an array, r[0..n], to store the maximum revenues for rods of length 0 to n.) What is the worst-case running time of your solution? 13

Question 12 Consider this shader code for Unity: (1) Shader "Custom/NewShader" { (2) Properties { (3) _Material ("color of material", Color) = (1,0,0,1) (4) _Specular ("color of highlights", Color) = (1,1,1,1) (5) (6) SubShader { (7) Tags { "RenderType"="Opaque" (8) (9) CGPROGRAM (10) #pragma surface func Lambert (11) (12) half4 _Material; (13) half4 _Specular; (14) (15) struct Input { (16) float dummy; (17) ; (18) (19) void func (Input IN, inout SurfaceOutput o) { (20) o.albedo = _Material.rgb; (21) o.specular = 0.9; (22) (23) ENDCG (24) (25) Which line(s) of the code specify the kind of this shader (vertex and fragment program in Cg, vertex and fragment program in GLSL, or Surface Shader)? On which hardware platforms (Windows PC, MacOS X computer, Android device, and/or ios device) is this kind of shader supported? The shader compiles without error messages. It is supposed to render a red surface with white highlights. However, no highlights are rendered. Which three(!) lines have to be edited and/or where must new lines be added to render highlights? (Specify the three line numbers.) Which parts of the three lines have to be edited and/or what should the new lines accomplish? (Instead of describing the required three changes, you can also just specify the correct code.) Suppose the correctly edited shader computes highlights per vertex (Gouraud shading). What is the disadvantage of this computation? Propose a solution to overcome this disadvantage. (Don t provide details, just specify the general idea.) What disadvantage(s) or costs does your solution imply? END OF EXAMINATION