FACULTY OF SCIENCE
ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING
MODULE CSC01B1
Introduction to data structures (C++)
CAMPUS APK
NOVEMBER FSAO / EXAM
2020
DATE: 2020-11-03 SESSION: 12:30 – 15:30
ASSESSOR(S) PROF DA COULTER
INTERNAL MODERATOR PROF DT VAN DER HAAR
DURATION 2 HOURS MARKS 100
Please read the following instructions carefully
1. You must complete this test yourself within the prescribed time limits.
2. You are bound by all university regulations please special note of those regarding
assessment, plagiarism, and ethical conduct.
3. You may not directly take any code from any source including your own previous
submissions. All code must be written by yourself during this the test.
4. You must complete and submit the “Honesty Declaration : Online Assessment”
document along with your submission to EVE. No submissions without an
accompanying declaration will be marked.
5. You may submit scanned pages as per the instructions on EVE
6. Your answers to the question (in a single PDF format) together with the declaration
must be submitted in a zip archive named in the following format.
STUDENTNUMBER_SURNAME_INITIALS_SUBJECTCODE_ASSESSMENT
e.g. 202012345_COULTER_DA_CSC01B1_EXAM.zip
7. Additional time for submission is allowed for as per the posted deadlines on EVE.
8. No communication concerning this test is permissible during the assessment session
except with Academy staff members.
/2…
COMPUTER SCIENCE 1B CSC01B1 -2-
QUESTION 1
Draw the following
• Identify classes (1)
• Identify attributes (1)
1.1 • Identify operations (1) (5)
• Identify has-a relationships (1)
• Identify is-a relationships (1)
Write the most correct option(s)
In order for overriding to occur the relationship between two classes must be one
based on …
1.2
A B C D E
inheritance composition aggregation overloading abstracting
An abstract base class cannot be (select two):
1.3
A B C D E
instantiated passed by value passed by ref destroyed extended
Stream insertion and extraction operators can be implemented as member functions
1.4
True False 無1
Generic programming allows for the creation of abstract types through the use of
type parameters. Which two keywords are used in this context?
1.5
A B C D E
generic template typename protected public
Assume that the class Q1 supports operator chaining for its >> operator. What would
an appropriate return type be for such an operator
1.6
A B C D E
istream istream& ostream ostream& void
Write your answers to the following
Consider the following lines of code which makes use of a hypothetical Sorter
class:
Sorter.sort(_data);
Based on this would you consider the sorter class to be an abstract data type?
1.7 (3)
Justify your answer with reference to the requirements of an abstract data type.
• Yes
• Logical properties (data gets sorted) separate from implementation
details (details of sorting algorithm)
Consider that BinarySearcher is a kind of Searcher. What is wrong with the
following code and how would you fix it?
BinarySearcher b;
1.8 Searcher s; (3)
s = b;
Slicing problem, b forgets its class, use pointers /
references
Consider adapting an instant messaging system. You have now had to add
1.9 encryption to the process to comply with local privacy laws but it is no longer (1)
possible to deliver the messages in real time. They will need to be stored
1
The Sino-Japanese ideogram Wu/Mu in this case represents a question which is flawed.
COMPUTER SCIENCE 1B CSC01B1 -3-
temporarily while they are processed. Would a Stack or Queue be more
appropriate for this task?
Queue
Which object orientated concept is being described:
i. A computing device has memory modules -Aggregation (0.5 for
1.10 composition) (3)
ii. There are different kinds of memory module -Inheritance
iii. A memory module stores data and instructions -General association
.
[20]
QUESTION 2
Write your answers to the following
a) private
b) static
c) template
d) Q2<T>&
e) friend
2.1 (10)
f) ostream&
g) const
h) const
i) ~
j) T
2.2 (2)
• try
2.3 • catch (3)
• catch order
Consider the following node-based data structure for the remaining sub-questions:
Provide code for a generic node structure compatible with the depicted data-structure.
template <typename T>
struct Node
{
2.4 T value; (5)
Node<T>* next;
Node<T>* prev;
};
Node<T>* n1 = _head->prev;
Node<T>* n7 = _head->next;
n1->next = n7;
2.5 n7->prev = n1; (5)
delete _head;
_head = n1;
Node<T>* nodeCurrent = _head;
2.6 if(nodeCurrent == nullptr) (5)
return;
COMPUTER SCIENCE 1B CSC01B1 -4-
cout << nodeCurrent->value << ‘ ‘;
nodeCurrent = nodeCurrent->next;
while(nodeCurrent != _head)
{
cout << nodeCurrent->value << ‘ ‘;
nodeCurrent = nodeCurrent->next;
}
[30]
QUESTION 3
Write the necessary C++ code for the following statements, and answer the remaining questions.
Unless otherwise indicated you may assume that the necessary header files are included. Most of the
marks in this section are awarded for the file handling operations.
• Opening file with input stream
• Using string stream to handle variable length lines
3.1 • Reading in values (5)
• Calling function
• Closing file
Define a structure with alignment packing/padding disabled to represent the data for one
Neuron. You may assume that every Neuron has exactly 16 weights.
#pragma pack(push)
#pragma pack(1)
struct Neuron
{
3.2 (5)
int intID;
double dblBias;
double aryWeights[16];
char chFun;
};
#pragma pack(pop)
int count()
{
fstream f(“neural-layer.dat”, ios::binary | ios::in);
f.seekg(0, ios::beg);
3.3 (5)
int intBytes = f.tellg();
f.close();
return intBytes / sizeof(Neuron);
}
fstream f(“neural-layer.dat”, ios::binary | ios::in);
Neuron recNeuron;
int c = count();
for (int i = 0; i < c; i++)
{
f.read(reinterpret_cast<char*>(&recNeuron), sizeof(Neuron));
3.4 for(int w = 0; w < 16; r++) (5)
{
if (recNeuron.aryWeights[w] > 1.0 || recNeuron.aryWeights[w] < 0)
throw recNeuron; //Other error handling or reporting
}
}
f.close();
COMPUTER SCIENCE 1B CSC01B1 -5-
Analyse the provided code asymptotically using Big-O notation. You may assume that
the makeMove operation is not dependant on the amount of data stored in a World.
State any further assumptions made.
3.5 (10)
Assumptions (4)
Derivation (5)
Result (1)
.
[30]
QUESTION 4
Your software is extensible through a series of DLL-based plugins. Not all plugins work with
the current version of the software. Each plugin implements a c-function called validate
which takes in an integer parameter representing the current version of the software and
returns a Boolean indicating if it is compatible or not.
Provide code for a function which takes in a vector of DLL filenames as well as
an integer version number as input and must then loop through all of the
specified files, attempt to extract and run the validate function from each one,
and return true only if all of the plugins are compatible with this version of the
software.
• windows.h
• typedef for function
4.1 • Loop through files (10)
• HINSTANCE
• LoadLibrary
• Error handling
• GetProcAddress
• Casting to function type
• Call function
• Free Library
#ifndef LIB_H
#define LIB_H
#ifdef BUILD_DLL
#define DLL_FUN __declspec(dllexport)
#endif
#define DLL_FUN __declspec(dllimport)
4.2 #endif (5)
extern “C”
{
DLL_FUN bool validate(int);
}
#endif
Pro (1) -e.g. precompiled, code obfustaced, etc.
4.3 (2)
Con (1) -e.g. windows specific
How is managing DLLs as a resource in your program similar to managing
4.4 memory or data files? (3)
Acquire (LoadLibrary), use (GetProcAddress), release (FreeLibrary)
.
[20]