0% found this document useful (0 votes)
2 views

Computer Science 1B 2021 Exam Memo - CSC01B1-2021-EXAM-MEMO

The document is a memorandum for the CSC01B1 module exam in Introduction to Data Structures (C++) at the Faculty of Science, detailing instructions for the assessment, including rules on plagiarism and submission formats. It contains various questions related to UML modeling, class relationships, exception handling, and C++ coding tasks, with a total of 100 marks available. The exam is scheduled for November 2, 2021, and is overseen by assessors Prof. Da Coulter and Prof. Dt Van Der Haar.

Uploaded by

thaboinnocent268
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)
2 views

Computer Science 1B 2021 Exam Memo - CSC01B1-2021-EXAM-MEMO

The document is a memorandum for the CSC01B1 module exam in Introduction to Data Structures (C++) at the Faculty of Science, detailing instructions for the assessment, including rules on plagiarism and submission formats. It contains various questions related to UML modeling, class relationships, exception handling, and C++ coding tasks, with a total of 100 marks available. The exam is scheduled for November 2, 2021, and is overseen by assessors Prof. Da Coulter and Prof. Dt Van Der Haar.

Uploaded by

thaboinnocent268
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
You are on page 1/ 7

FACULTY OF SCIENCE

ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING

MODULE CSC01B1
Introduction to data structures (C++)
CAMPUS APK

NOVEMBER FSAO / EXAM


2021
MEMORANDUM
DATE: 2021-11-02 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

Use UML to model the following scenario: A Weather Predictor has a real valued
computer time budget and a volume (made up of three integers) which are set
when the predictor is created. In addition, it has a three-dimensional collection
of Air Cells whose life cycle it manages. Each Air Cell contains a set of integer
x, y, and z values which indicate its position within a three-dimensional space as
well as real values indicating the temperature, pressure, and humidity within that
cell. These values need to be accessible and modifiable. Both the Weather
Predictor and Air Cells have a simulate behaviour (the predictor delegates this
to its cells). There are two kinds of predictor namely Long Term and Short Term
which override the simulate behaviour.

1.1 (5)

Write the most correct option(s)

A class often has multiple constructors which differ in terms of their parameter lists
(in number, order, and type of parameters). What is this an example of?
1.2
A B C D E
inheritance composition aggregation overloading abstracting
Assume that A has a B. Whenever an A is instantiated so too is B. Whenever A is
destroyed so too is B. What kind of relationship is this?
1.3
A B C D E
composition aggregation inheritance polymorphism generics
Assume that class A is an abstract base class and that B derives from A. B is also
an abstract base class given that the following code compiles:
1.4 A a = new B;

True False 無1

Assume that class A has a data member m. Class B is an A while class C is


unrelated to both A and B. Given that m is visible in A but not in C what keyword was
1.5 used when declaring m?
A B C D E
public private protected static const
Assume that the class Q1 supports operator chaining for its equality operator (==).
What would an appropriate return type be for such an operator?
1.6
A B C D E
Q1 Q1& bool void& void

Write your answers to the following

1
The Sino-Japanese ideogram Wu/Mu in this case represents a question which is flawed.
COMPUTER SCIENCE 1B CSC01B1 -3-

Consider the following lines of code which makes use of a hypothetical


Classifier class which takes in a PPM encoded image string and returns a
Boolean value indicating if the image is of a cat:
1.7 bool blnCat = classifier.classify(strImage); (3)
Based on this would you consider the class to be an abstract data type? Justify
your answer with reference to the requirements of an abstract data type.
Yes logical properties are separate from implementation details
Consider that a Student is a Person and that both Student and Person
define a void member function call work().Your friend expects that the
following code will produce the output for Student’s work function but it instead
produces the output for Person. What is wrong and how can it be fixed?

1.8 Student* s = new Student; (2)


Person* p = new Person;
s = p;
s->work();

Not polymorphic work must be declared as virtual


Your friend is adding and removing values from a linked list but is frustrated that
the order of items keeps getting reversed. What data structure is this behaving
1.9 as and how can your friend fix this? (2)
Stack
Insert at back remove from front
Name the object orientated concept is being described:
i. A Projects Day Team has Students -aggregation
1.10 (3)
ii. A Student has Organs -composition
iii. A Project is an Academic Activity -inheritance
.
[20]

QUESTION 2

Write your answers to the following

Complete the following code in which a generic Q2Cube class acts as a container for
three-dimensional data of type T

a) template
b) public
c) <T>
d) const
2.1 e) Q2Cube<T>& (10)
f) T
g) ***
h) !=
i) freeCube()
j) *this or objRHS

The copyCube() function assumes that the current object is already the same size as the
object that is being copied. If this is not the case, then an error condition has been
encountered. Provide code which defines a simple two class hierarchy consisting of a base
exception type and a specific exception type for this kind of error.
2.2 (2)
class Error {};
class NotEqualToError : public Error {};

Write code to protect the following using exception handling assuming that the class has
been updated to raise the exception types defined in the previous sub-question.
2.3 (3)
try
COMPUTER SCIENCE 1B CSC01B1 -4-

{
//
} catch(NotEqualToError& e)
{
cerr << “!= error” << endl;
} catch (Error& e)
{
cerr << “Error” << endl;
} catch (…)
{
cerr << “???” << endl;
}

Consider the following node-based data structure for the remaining sub-questions:

Provide code for a templated node structure compatible with the depicted data-structure.
template <typename T>
struct Node
{
2.4 (5)
T data;
Node<T>* next;
};

Provide code for inserting a node containing the value ‘E’ at the end of the data-structure
Node<char>* nodeNew = new Node<char>;
nodeNew->data = ‘E’;
2.5 (5)
nodeNew->next = nullptr;
_tail->next = nodeNew;
_tail = nodeNew;
Provide code for deleting the entire data structure
Node<T>* nodeCurrent = _head;
while(nodeCurrent != nullptr)
{
2.6 (5)
Node<T>* n = nodeCurrent;
nodeCurrent = nodeCurrent->next;
delete n;
}

[30]
COMPUTER SCIENCE 1B CSC01B1 -5-

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.
The text file numeric-parameters.txt is made up of lines in the following format:

SIM-NAME VERSION P0 P1 … PN OUT-FILE EOL

The data represents the input parameters for a set of virtual simulations. Each line
represents the data for running one instance of the simulation and the location where its
results should be saved. There can be an arbitrary number of lines and they can vary in
length. Each value in a line is separated by a space character and has the following
meaning:
• SIM-NAME: The name of the simulation as a string
• VERSION: A positive integer
• P0 … PN: A set of integer parameters for this particular instance of the simulation.
• OUT-FILE: The name of the file the results of the simulation should be saved to.
• EOL: Represents the end of line characters for the operating system

The names of the simulation and the output file are limited to letters, underscored,
numbers, and full stops. In addition, they may not exceed 32 characters each.

Write code which reads these values from the file and uses the system() function to run
3.1 the simulation with its parameter set. The name of the simulation executable is its sim- (5)
name followed by its version number followed by .exe.
ifstream f(“numeric-parameters.txt”);
string strLine = “”;
while(getline(f, strLine))
{
stringstream ss(strLine);
string strEX = “”;
ss >> srEXE;
strVer = “”;
ss >> strVer;
strEXE += strVer + “.exe ”;
string strP = “”;
while(ss >> strP)
{
strEXE += “strP “;
}
system(strEXE.c_str());
}
f.close()
Define a structure with alignment packing/padding disabled to represent the data for one
run of a simulation.
#pragma pack(push)
#pragma pack(1)
struct SimRun
3.2 { (5)
char name[32];
int version;
int params[16];
};
#pragma pack(pop)
Assume that the file simulation-parameters.dat is a pre-existing binary file of
homogenous records of the type defined in question 3.2. Write code for a function which
3.3 (5)
reads the last record from the end of the file.
fstream f(“simulation-parameters.dat, ios::binary | ios::in);
COMPUTER SCIENCE 1B CSC01B1 -6-

f.seekg(0, ios::end);
SimRun recRun;
f.read(reinterpret_cast<char*>(&recRun), sizeof(SimRun));
f.close();
Assume that the file simulation-parameters.dat is a pre-existing binary file of
homogenous records of the type defined in question 3.2. Write code for a function which
determines if there are an even or odd number of records in the file.
fstream f(“simulation-parameters.dat, ios::binary | ios::in);
3.4 (5)
f.seekg(0, ios::end);
int intBytes = f.tellg();
bool isEven = (intBytes / sizeof(SimRun) % 2) == 0;
f.close();
Analyse the provided code asymptotically using Big-O notation. State any assumptions
made.

3.5 (10)

Assumptions (4)
Derivation (5)
Result (1)
.
[30]

QUESTION 4

Your software expects a dynamic array of integer values to be monotonically increasing (that
is each subsequent element is either the same as the previous or larger, never smaller). You
will need to create a DLL to contain this such a
bool isIncreasing(int* aryData, int intSize) function in a dynamically linked
library called monotone-increase.dll
Write code for the header file of such a DLL
#ifndef EXAMPLE_DLL_H (1)
#define EXAMPLE_DLL_H (1)

#ifdef BUILDING_EXAMPLE_DLL (1)


#define EXAMPLE_DLL __declspec(dllexport) (1)
#else (1)
#define EXAMPLE_DLL __declspec(dllimport) (1)
4.1 (10)
#endif (1)

extern "C" (1)


{
bool EXAMPLE_DLL isIncreasing(int*, int); (1)
}

#endif (1)
Write code for the .cpp implementation file of the DLL including the
implementation of the isIncreasing function
4.2 • Normal library function (5)
• Loop through array from 1 up to n – 1
o Compare a[i] with a[i – 1]
COMPUTER SCIENCE 1B CSC01B1 -7-

o Check if < or ==
• Return
You have code for a program which uses this functionality in a file called
process-main.cpp. Write a BAT file which compiles an implicitly linked
executable called process.exe which expects to link to the DLL which will be
4.3 stored in the lib folder (5)
g++ process-main.cpp -o process.exe -lmonotone-increase -L\lib

(also been accepting -L.)


.
[20]

You might also like