0% found this document useful (0 votes)
49 views12 pages

EE402 OOP Embedded Systems Exam 2023

The document outlines the Semester 1 Examinations for the EE402 module on OOP with Embedded Systems for the academic year 2023/2024. It includes details on the exam structure, instructions for candidates, and various questions related to C++ and Java programming concepts. The exam consists of compulsory and optional questions covering topics such as class definitions, function return types, and the use of templates.

Uploaded by

rohanvish2701
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views12 pages

EE402 OOP Embedded Systems Exam 2023

The document outlines the Semester 1 Examinations for the EE402 module on OOP with Embedded Systems for the academic year 2023/2024. It includes details on the exam structure, instructions for candidates, and various questions related to C++ and Java programming concepts. The exam consists of compulsory and optional questions covering topics such as class definitions, function return types, and the use of templates.

Uploaded by

rohanvish2701
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SEMESTER 1 EXAMINATIONS 2023/2024

MODULE: EE402 - OOP with Embedded Systems


PROGRAMME(S):
ECSAO Study Abroad (Engineering & Computing)
MECE MEng Electronic & Computer Engineering
MCTY MSc Electronic and Computer Technology
ECE BEng Electronic & Computer Engineering
ECEI BEng Electronic & Computer Engineering
MEQ Masters Engineering Qualifier Course
MQTY Qualifier Programme MSc Electronic & Computer
ECSA Study Abroad (Engineering & Computing)

YEAR OF STUDY: 4, C, O, X

EXAMINER(S):
Prof. Derek Molloy (Internal) (Ext:5355)
Prof. Martin Glavin (External) External

TIME ALLOWED: 3 Hours

INSTRUCTIONS: Answer Question 1 and any three questions from Question 2, 3,


4 and 5. All questions carry equal marks and the total marks available is 100.

Please type your DCU Examination ID here: Click here to enter text.

PLEASE DO NOT TURN OVER THIS PAGE UNTIL YOU ARE INSTRUCTED TO DO SO.

This is a computer-based examination. This is your exam paper and your examination script.

The use of programmable or text storing calculators is expressly forbidden.


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.

This is a computer-based examination. Save any working files, including this document, in the directory
C:\Temp\ as all other locations are lost on a power cycle of the PC. Save this document regularly.

At the end of the examination you must upload this completed document as a PDF as instructed. You
are not permitted to submit any other files. Do not re-order or edit the questions.

Students will use a Word version of this document made available electronically during the lab exam.
Printed exam papers are not required.

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 1 of 12
QUESTION 1 (Compulsory) [TOTAL MARKS: 25]

Q 1 Answer the following questions. Please keep any text answers concise.

a) Explain declaration and definition in C++. Is the statement, class Student; a


declaration or definition? Explain your answer. (2 marks)

Replace this text with your answer to Q1(a)

b) Which of the following are default return types for a function in C++? (Select all
that apply.) (2 marks)

☐char
☐void
☐double
☐float
☐int

c) Write a short Java function to prove that references to objects are passed by value
in Java. (3 marks)

Replace this text with your answer to Q1(c)

d) In C++, what is the purpose of the virtual keyword when used in a class definition?
(Only one answer is correct.) (2 marks)

☐ It declares a member variable as being accessible from derived classes.


☐ It specifies that a member object should have virtual inheritance.
☐ It indicates that the function can be overridden in derived classes.
☐ It declares a class as abstract and cannot be instantiated.
☐ It indicates that a class has no polymorphic behaviour.

e) Describe different ways that the keyword super is used in Java. Also, describe an
equivalent functionality and syntax that is available in C++? (2 marks)

Replace this text with your answer to Q1(e)

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 2 of 12
f) In Java, what is the purpose of the finalize method when used in a class? (Only
one answer is correct.) (2 marks)

☐ It is used to explicitly deallocate memory for objects.


☐ It is automatically called when an object is eligible for garbage collection.
☐ It is used to indicate that a class cannot be extended further.
☐ It is a constructor method for creating new instances of the class.
☐ It indicates that a class is to be treated as constant and that no child classes can
be created.

g) Which of the following statements are true about the void pointer (void*) in C++?
(Choose all that are true) (2 marks)
☐ void* can be used to prevent a variable from being modified by hiding the memory
address of the object.
☐ void* can be used to create generic data structures, such as linked lists or trees,
that can hold elements of any data type.
☐ void* is a special type of pointer that does not have a specific data type
associated with it.
☐ void* can be used to explicitly state that no variable is to be passed to a function
or method.
☐ You can use a void* to pass a pointer to a function along with additional context
data. Later, you can cast the void* back to the appropriate function type.

h) Given the following segment of Java code, select which statement below is true in
relation to the sayHello() method?: (Only one answer is correct.)(2 marks)

public class StaticExample {


public static void sayHello() {
System.out.println("Hello, World!");
}
// more unseen code here

public static void main(String[] args) {


sayHello();
}
}
☐ Using the sayHello() method in the main() function is a coding error.
☐ It can only be called from within the main() function.
☐ It must be invoked on an instance of the StaticExample class.
☐ It cannot be called at all because it lacks a return statement.
☐ It can be called directly using the class name, without creating an object.

i) What issues would arise if destructors could be non-virtual in C++? Explain your
answer using a short example. (2 marks)

Replace this text with your answer to Q1(i)

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 3 of 12
j) Are Java arrays safer than C++ arrays? Describe why you believe this is/is not the
case with the aid of short code examples. (2 marks)

Replace this text with your answer to Q1(j)

k) The following is an example of const modified methods in a class. Review the code
example and select which of the statements that follow are true. (Two answers are
correct.)(2 marks)

class SomeNumber{
private:
int value;
public:
SomeNumber(int value): value(value) { //code here };
void a() const { //code here };
void b() { //code here };
void c() const;
};

void SomeNumber::c(){ //code here }

☐ Const and non-const functions can be called by non-const modified objects.


☐ Non-const functions cannot be called by const modified objects if the non-const
function does not modify the object value state.
☐ Non-const functions can be called by any const modified objects.
☐ The b() method is a non-const member function.
☐ The a() method can modify the value member as it is inside the class and the
value member is private.

l) In C or C++ programming, what is the primary difference between including a header


file using angle brackets (< >) and using double quotes (" ")? (Only one answer is
correct.)(2 marks)

☐ Angle brackets are used for system libraries, while double quotes are used for
user-defined headers.
☐ Angle brackets search for the header file in the current directory, while double
quotes search in system directories.
☐ Angle brackets are used for C code, while double quotes are used for C++ code.
☐ Angle brackets allow the pre-processor to look in additional directories specified
by the user, while double quotes search only in the standard system directories.

[End of Question 1]

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 4 of 12
QUESTION 2 (Optional) [TOTAL MARKS: 25]
Q 2(a) [6 Marks]

Using C++ and OOP best practice, write all of the code necessary to ensure that the
following block of code functions correctly. Do not use separate compilation1:

int main() {
EE402::Sensor tempSensor("Temp1", "Thermocouple", "deg C", 25.5);
tempSensor.display();
EE402::Sensor humidSensor("Humid1", "Hygrometer", "% RH", 60.0);
humidSensor.display();
return 0;
}

The code above should result in the exact following output:


Sensor [name: Temp1, type: Thermocouple, units: deg C, reading: 25.5]
Sensor [name: Humid1, type: Hygrometer, units: % RH, reading: 60]
Sensor Humid1 has been removed.
Sensor Temp1 has been removed.

Replace this text with your solution. You may cut and paste the code above into your
main() function and please paste your output into this box. Do not use separate
compilation.

Q 2(b) [6 Marks]

Adapt the code in 2(a) so that the type of the sensor is an enumeration called
SensorType, rather than a std::string. Provide for the following sensor types:
temperature, humidity and pressure. The following segment of code should result in
the same output as Q2(a).

int main() {
EE402::Sensor tempSensor("Temp1", EE402::TEMPERATURE_SENSOR, "deg C", 25.5);
tempSensor.display();
EE402::Sensor humidSensor("Humid1", EE402::HUMIDITY_SENSOR, "% RH", 60.0);
humidSensor.display();
return 0;
}

Note: You can complete Q2(c) even if you do not complete this part.

Replace this text with your solution. Do not use separate compilation.

Please keep all of your classes in a single C++ file and paste your solution into the black box when it is
complete. It is not important that the black box format is retained. Remember that you can copy and
paste the text from this exam paper into your IDE to speed development in all questions but do not
include the code provided in your solution if it remains unaltered.

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 5 of 12
Q 2(c) [13 Marks]

Use the STL to write a C++ class called SensorAggregator that contains a flexible
number of Sensor objects. It should have appropriate functionality to allow a new
sensor object to be contained, e.g., addSensor(EE402:Sensor), and a
display() function that displays all of the sensor readings, sorted by value for each
sensor type state.

The class should have the methods: getMinimum(SensorType) and


getMaximum(SensorType) that return the relevant object of the Sensor class2.

The main() function below should give the exact output that follows:

int main() {
EE402::Sensor s1("Temp1", EE402::TEMPERATURE_SENSOR, "degree C", 25.5);
EE402::Sensor s2("Temp2", EE402::TEMPERATURE_SENSOR, "degree C", 35.5);
EE402::Sensor s3("Humid1", EE402::HUMIDITY_SENSOR, "% RH", 60.0);
EE402::Sensor s4("Temp3", EE402::TEMPERATURE_SENSOR, "degree C", 5.5);

EE402::SensorAggregator sa;
sa.addValue(s1);
sa.addValue(s2);
sa.addValue(s3);
sa.addValue(s4);
sa.display();
cout << "The minimum TEMPERATURE value is:" << endl;
sa.getMinimum(EE402::TEMPERATURE_SENSOR).display();
cout << "The maximum TEMPERATURE value is:" << endl;
sa.getMaximum(EE402::TEMPERATURE_SENSOR).display();
return 0;
}

Sensor [name: Temp3, type: temperature, units: degree C, reading: 5.5]


Sensor [name: Temp1, type: temperature, units: degree C, reading: 25.5]
Sensor [name: Temp2, type: temperature, units: degree C, reading: 35.5]
Sensor [name: Humid1, type: humidity, units: % RH, reading: 60]
The minimum TEMPERATURE value is:
Sensor [name: Temp3, type: temperature, units: degree C, reading: 5.5]
The maximum TEMPERATURE value is:
Sensor [name: Temp2, type: temperature, units: degree C, reading: 35.5]

Replace this text with your solution.

[End of Question 2]

2 If you cannot complete Q2(b), you can substitute std::string as the type of the parameter.

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 6 of 12
QUESTION 3 (Optional) [TOTAL MARKS: 25]
Q 3(a) [10 Marks]

Write a template class called Pairs that can store an arbitrary pair of values of
independent types. Implement everything required in the template so that the following
segment of code gives the exact output that follows:

int main() {
EE402::Pair<std::string, double> firstPair("PI", 3.1415927);
std::string firstValue = firstPair.getFirst();
double secondValue = firstPair.getSecond();
cout << "The first pair is " << firstValue << ", " << secondValue << endl;
EE402::Pair<int, char> secondPair(65, 'A');
secondPair.display();
EE402::Pair<std::string, char> thirdPair("Meaning of Life", (char) 42);
cout << "Using an output stream operator the third pair is " << thirdPair << endl;
return 0;
}

The code above should result in the following output:

The first pair is PI, 3.14159


[65, A]
Using an output stream operator the third pair is (Meaning of Life, *)

HINT: The following code may be useful to you:


friend ostream& operator<<( ostream& os, const X& x);

Replace this text with your solution. Do not use separate compilation. Remember
that you can cut-and-paste the main function above into your editor, but do not
include it as part of your solution.

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 7 of 12
Q 3(b) [9 Marks]

The C++ explicit cast const_cast<T> enables you to “cast away” const or
volatile. Using a small segment of code, demonstrate how you can use this cast to
pass a constant argument to a function that does not require a constant parameter.

In addition, write a short code example to demonstrate upcasting and downcasting


using C++ explicit casts.

Replace this text with your solution.

Q 3(c) [6 Marks]

With the aid of outline source code, explain multiple inheritance in C++. Why is it a
useful feature of the language?

How does multiple inheritance lead to difficulties in the design process? In particular,
explain the use of the virtual keyword as it relates to inheritance within a multiple
inheritance context.

Replace this text with your solution. Do not include a diagram but provide a written
description if necessary.

[End of Question 3]

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 8 of 12
QUESTION 4 (Optional) [TOTAL MARKS: 25]
Q 4 (a) [20 Marks]

Write the Java Swing Bar Chart example, exactly as displayed in Figure 4. The
application should have the following functionality:
 When the “Random Array” button is pressed, the application generates 10
different random values, each in the range from 1 to 100.
 The interface is updated as illustrated in Figure 4, where the 10 different values
labelled “Value 1” to “Value 10” are displayed as a bar chart (scaled as
appropriate) and the numeric equivalent is displayed at the top of the window.
 The graph should plot the elements in blue, except for the largest value, which
should be plotted in red. If the maximum value is repeated (e.g., 95 appeared
multiple times in Figure 4) all should be red.
 The “Input via Dialog Boxes” displays 10 dialog boxes, which allow you to enter
the values manually, as illustrated in Figure 4. The dialog box should only
permit a valid integer value.
 The application should exit when the X button is clicked.

Figure 4 The application with 10 different random numbers (1-100) and the Input
dialog that appears when the second button is pressed.

Replace this text with your solution. You should use the ALT-PrtScn function to
capture your user interface output and paste it into this box.

[Question 4 Continued on Next Page]

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 9 of 12
Q 4(b) [5 Marks]

Adapt the code in Q4(a) so that a single mouse click on the graph generates a new
set of random values, which display in the same manner.

Replace this text with your solution. Only include the code changed from Q4(a).

[End of Question 4]

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 10 of 12
QUESTION 5 (Optional) [TOTAL MARKS: 25]
Q 5(a) [5 Marks]

A distributed gas sensor system is required that uses many distributed embedded
Linux sensors, each of which reads the level of carbon dioxide (CO2), carbon
monoxide (CO) and methane (CH4) in Parts per Million (ppm) through three 10-bit
Analogue to Digital Converters (ADCs) at each location. A central server must be
developed that receives the data from the distributed sensors.

Describe a suitable architecture for such a system and discuss the advantages and
disadvantages of using embedded Linux on a board such as the BeagleBone Black or
Raspberry Pi for such an application.

Replace this text with your solution. Describe the architecture, but do not attempt to
include a diagram.

Q 5(b) [20 Marks]

It is decided that the Java programming language is to be used for the application in
Q5(a) with the following requirements:

 Write a Java class called Reading that contains a sensor location name
(String) and a ppm reading (float) for each of the three gas sensors, which
is a number in the range zero to one million. Write a second class
GasReadings that contains a vector of Reading objects.

 Write a Java client/server pair, where the client application sends a


GasReadings object to a server. The server should calculate the average
reading for each gas reading type (CO2, CO, CH4) and send it back to the
client sensor, within the returned GasReadings object.

 The server should display a warning on the server machine if any sensor value
exceeds a safe threshold. The warning should identify the value that exceeded
the threshold and its location. The safe threshold for the individual gases are
as follows:
o Carbon Dioxide (CO2) 1,000 ppm
o Carbon Monoxide (CO) 50 ppm
o Methane (CH4) 100 ppm

 Example outputs from the server and client applications are provided overleaf.
Note that output from the server and client applications occurs simultaneously.

[Question 5(b) Continued on Next Page]

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 11 of 12
 You have been provided with three files to help you with your solution:
Client.java, Server.java and ConnectionHandler.java, which were
provided with this exam paper. You must use these files as the structure of your
solution.

Example Client Output:


**. Java Client Application - EE402 Q5 2023/24
00. -> Connected to Server: localhost/127.0.0.1 on port: 5050
-> from local address: /127.0.0.1 and port: 35680
01. -> Sending readings to the server...
02. -> Sending an object...
03. -- About to receive an object...
04. <- Object received...
05. <- The Server responded with:
06. -- Disconnected from Server.
There are 4 readings:
Reading is CO:40.6ppm, CO2: 100.0ppm, CH4:10.0 at location S123
Reading is CO:50.0ppm, CO2: 200.0ppm, CH4:16.5 at location S234
Reading is CO:65.7ppm, CO2: 999.0ppm, CH4:15.0 at location S345
Reading is CO:100.0ppm, CO2: 800.0ppm, CH4:1.0 at location S567
The averages: CO2:524.75ppm CO:63.75ppm CH4:10.5ppm
**. End of Application.

Example Server Output:


New Server has started listening on port: 5050
**. Listening for a connection...
00. <- Accepted socket connection from a client:
<- with address: /127.0.0.1
<- and port number: 35680
02. -- Finished communicating with client:/127.0.0.1
**. Listening for a connection...
01. <- Received readings from the client
There are 4 readings.
Alarm! CO Sensor at location S345 exceeds level with reading 65.7ppm
Alarm! CO Sensor at location S567 exceeds level with reading 100.0ppm
02. -> Sending (EE402.GasReadings@352cd8da) to the client.

Replace this text with your solution. Only include the classes that you have altered
and clearly identify changes to the code that was provided -- e.g., by bolding the
code. Where possible include output capture.

[End of Question 5]

[END OF EXAM]

EE402 – OOP with Embedded Systems


Semester 1 Examinations 2023/2024 Page 12 of 12

You might also like