Docsity

Review Sheet for Final Exam - Object Oriented Programming | ECE 46200, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 462 Final Exam
08:00-10:00AM, December 18, 2008
I certify that I will not receive nor provide aid to any other student for this exam.
Signature:
You must sign here. Otherwise, the exam is not graded. Please put your photo ID on the desk.
This exam is also available on-line in Blackboard. Please circle here if you take the exam on-line. In
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.
Name:
Seat:
Name: 1 Seat:
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Review Sheet for Final Exam - Object Oriented Programming | ECE 46200 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

ECE 462 Final Exam

08:00-10:00AM, December 18, 2008

I certify that I will not receive nor provide aid to any other student for this exam.

Signature:

You must sign here. Otherwise, the exam is not graded. Please put your photo ID on the desk.

This exam is also available on-line in Blackboard. Please circle here if you take the exam on-line. In

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.

Name:

Seat:

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.

Contents

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

Total Score:

This page is blank.

This page is blank.

1 Programming Assignment 1-

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.

N

2 C++ Pass by Value, by Pointer, and by Reference

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?

3 Java Applet

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.

4 Java RMI

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 { T executeTask(TaskInterface t)

throws RemoteException; }

// TaskInterface.java // :::::::::::::: package RMIInterface;

public interface TaskInterface { T executeCode(); }

5 Lab Exercise

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 #include #include #include #include #include #include <sys/time.h> using namespace std;

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; }

6 C++ Multiple Inheritance

Write the C++ code to implement this class hierarchy.

  • Person is a class and has an attribute name; its type is string. The name of a Person object is a constant and cannot be changed after initialization.
  • Student is a direct derived class of Person and has an additional attribute called GPA; its type is float.
  • Teacher is a direct derived class of Person and has an additional attribute called course; its type is string.
  • TeachingAssistant is a direct derived class of both Student and Teacher. TeachingAssistant has an additional attribute called numberStudent; its type is int. Each TeachingAssistant has one and only one name from the Person class.

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.

7 C++ Echo Server

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.

8 Programming Assignment 3

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.