






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Blackboard, you can see “Final Exam” and “Final Exam (Attachment)”. The latter is used when your code is too long to fit in the space given by Blackboard.
This exam is printed double sides.
This is an open-book, open-note exam. You can use any book or note or program printouts. No electronic device is allowed. Please turn off your cellular phone now.
There are 8 questions and you can select at most 5 questions to answer. Please mark (on the next page) which questions to grade. If you mark 6 questions, only 4 will be graded. If you mark 7 questions, only 3 will be graded. If you mark 8 questions, only 2 will be graded. Each question is worth 20 points.
If the specification is incomplete, inconsistent, or incorrect, please explain how you would modify the specification. You need the ability to detect and handle imperfect specifications.
Mark at most 5 questions to be graded. If you mark 6 questions, only 4 will be graded. If you mark 7 questions, only 3 will begraded. If you mark 8 questions, only 2 will be graded.
1 Programming Assignment 1-2 7
2 C++ Pass by Value, by Pointer, and by Reference 7
3 Java Applet 7
4 Java RMI 7
5 Lab Exercise 8
6 C++ Multiple Inheritance 10
7 C++ Echo Server 10
8 Programming Assignment 3 10
This page is blank.
This page is blank.
In the first two programming assignments, the paddles are parts of two circles. If each paddle is a triangle, as shown below, how do you calculate the ball’s direction after the collision? Write the code in C++ or Java (your choice). Please remember to declare and define the necessary classes and objects.
Briefly explain the differences between pass by value, by pointer, and by reference. Show at least three examples to illustrate the differences. Please pay special attention to (1) If an object is changed inside a function, is this change visible after the function returns? (2) What is the effect on performance? (3) If an object contains an attribute that requires dynamic memory allocation, what are the differences among the three methods for argument passing?
Write a dual-purpose Java program that (1) can be an application (2) can be an Applet. This program has a JPanel object and a red ball bounces within this panel. You also need to write an HTML file that uses this Applet.
Write both the server and the client for Java RMI. The server extends interface EngineInterface and the client extends interface TaskInterface. When the client’s executeCode is called, it returns a String object saying “Hello ECE462.”
// :::::::::::::: // EngineInterface.java // :::::::::::::: package RMIInterface;
import java.rmi.Remote; import java.rmi.RemoteException;
public interface EngineInterface extends Remote {
throws RemoteException; }
// TaskInterface.java // :::::::::::::: package RMIInterface;
public interface TaskInterface
Consider the following program that uses threads to add the elements in an array. The correct answer should be 0 + 1 + 2 + 3 + 4 + ... + (arraySize - 1). (1) Is it possible that the program’s two output values are different? Why? (2) What problem does this program have? You answer might by “syntax error”, “memory leak”, “segmentation fault”, or other problems. Please indicate the line (or lines) where the problem occurs. If there are several problems, you need to find all problems. (3) If the program has problem (or problems), how do you fix it?
#include
class AdderThread: public QThread { public: AdderThread(int (^) * a, int f, int l) { array = a; first = f; last = l; } void addElement(int v) { mutex.lock(); sum += v; mutex.unlock(); } void run() { for (int cnt = first; cnt <= last; cnt ++) { addElement(array[cnt]);
delete thrd[cnt]; }
delete [] thrd; delete [] dataArray;
return 0; }
Write the C++ code to implement this class hierarchy.
Create a TeachingAssistant object whose name is “Tom Johnson”, GPA is 3.85, course is “ECE 462 C++ and Java”, and the number of student is 50. Print this object’s attributes. Your answer should include (1) the declaration of the class hierarchy (2) constructors to properly initialize the attributes. All attributes should be private or protected.
Write a C++ (using Qt) echo server. The server can accept multiple clients. When the server receives a string (ending with an new line character, ’\n’), the server sends back the string to the client. If the string is “bye\n”, the server closes the connection and the client can no longer communicate with the server.
Write the C++ code to detect and eliminate a line in a Tetrix game. Please remember to declare and define the necessary classes and objects.