ELEN3009 - Test 2019

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

ELECTRICAL AND INFORMATION ENGINEERING

University of the Witwatersrand, Johannesburg


Software Development II

August Test 2019: 1 Hour – 35 marks

Instructions

• Answer all questions. The questions do not carry equal weight.


• For questions which require you to write source code, note that:
– You only need to specify #include’s if specifically asked.
– For classes, you can give the implementation entirely in the header file,
unless directed otherwise.
– Marks are not awarded solely for functionality but also for good design,
making appropriate use of library functions, following good coding prac-
tices, and using a modern, idiomatic C++ style.
– Your code must be easily understandable or well commented.
– You may use pencil but then you forfeit the right to query the marks.
• Reference sheets are provided separately.

Question 1

Sun Microsystems, who created the Java language, used the slogan “Write once, run every-
where” to promote the language. Explain what is meant by this slogan, and how this slogan
could be used to highlight the differences between Java and languages like C++.
[Total Marks 5]

Question 2
a) Read the description of the unique algorithm that is given in your reference sheets and
write a set of unit tests to verify the behaviour of unique.
(12 marks)
b) Provide an implementation of the unique algorithm. Your algorithm must have the
following signature:
Iterator unique(Iterator first, Iterator last)

Iterator is a class representing an iterator having only the following functionality:


• ++iter and iter++ advance the iterator to the next element in the sequence.
• *iter dereferences the iterator and gets the element pointed to.
• = is used to assign one Iterator to another.
• == and != allow two Iterators to be compared.
In your solution you may not make use of any STL algorithms or classes. (9 marks)
[Total Marks 21]

Page 1 of 2
Question 3

You are required to develop software for a solar inverter, which converters DC power from
a solar panel to AC which can be used by most existing appliances. The product brief is as
follows:

The inverter consists of a switch mode transformer, an ammeter and con-


trol panel. The switch mode transformer can operate at any frequency and
voltage, however the control panel must only allow “American” (110V at 60Hz)
or “European” (220V at 50Hz) output mode presets. Furthermore, the trans-
former can operate at any duty cycle, however the control panel must limit it
to “Eco”, which is a 40% duty cycle or “Power” which is a 50% duty cycle. The
ammeter measures the current flowing through the power supply. The con-
trol panel allows the user to set the modes and turn on the inverter. A Quick-
Start feature exists where the unit should run in “American” output mode and
“Power” duty cycle. The inverter must also automatically “trip”, i.e. turn off
the switch mode transformer if the current drawn is greater than 2 Amps.

Your task is to create an Inverter class and implement the following public member func-
tions in order to model the above behaviour:
// starts the inverter with user defined settings
void start(OutputMode output_mode, DutyCycle duty_cycle);
// starts the inverter with predefined settings
void quickStart();

Add additional functions and/or data members to your Inverter class, as required. Make
use of the existing classes supplied in Listing 1. You are not required to provide the imple-
mentation details for these existing classes.

enum class OutputMode { American, European };


enum class DutyCycle { Eco, Power };

class Ammeter
{
public:
Ammeter();
// returns the measured current in amps
float MeasuredAmps() const;
};

class SwitchModeTransformer
{
public:
SwitchModeTransformer();
void setVoltage(unsigned int voltage);
void setFrequency(unsigned int frequency);
void setDutyCycle(float duty_cycle_percentage);
void startSwitching();
void stopSwitching();
};

Listing 1: Existing classes for use with the Inverter class

[Total Marks 9]

Page 2 of 2

You might also like