Sei sulla pagina 1di 10

Page 1 of 10

Contents

Table of Contents
Contents ................................................................................................................................................. 1
Guidelines .............................................................................................................................................. 1
Language-Independent Questions........................................................................................................... 4
C++ Test (Ignore this section if you have no C++ experience) .................................................................... 5
C# Test (Ignore this section if you have no C# experience)........................................................................ 7
JavaScript Test (Ignore this section if you have no JavaScript experience) ................................................ 9

Guidelines
Please complete any sections that you feel you can.
We’d prefer if you avoid any web searches, but please paste in any web-links you do access for help.
Please also state how long the test took to complete.

Add your name below:

Name:

Time taken to finish test:

All information within this document is copyright © West Pier Studio LTD. All rights reserved. Unauthorised copying or reproduction without the permission of West Pier Studio LTD is strictly prohibited.
Page 2 of 10
Maths

1. Solve the following simultaneous equations. Please show workings.

x + y = 7
2x + y + 3z = 32
2y + z = 13

2. An object travels for 10 seconds along a straight line with an initial velocity of 10m/s. During the
whole of the 10seconds a force is applied that causes it to decelerate at 3m/s2. How far will it be
from the starting point after 10 seconds. Please explain your workings.

All information within this document is copyright © West Pier Studio LTD. All rights reserved. Unauthorised copying or reproduction without the permission of West Pier Studio LTD is strictly prohibited.
Page 3 of 10
3. The quadratic equation

Can be solved with the following formula:

This method implements the solver:

void solveQuadratic(float a, float b, float c, QuadraticVal values) {


float bSquaredMinus4ac = b*b – 4*a*c;

values.x1 = ((-b + Math.sqrt(bSquaredMinus4ac)) / (2 * a));


values.x2 = ((-b – Math.sqrt(bSquaredMinus4ac)) / (2 * a));
}

3A. What can go wrong with this function, and discuss how you would improve the code to fix these issues.

3B. Given the various outcomes from this function, what do you think could be modified in the code to
better communicate these outcomes to any client code calling this function?

All information within this document is copyright © West Pier Studio LTD. All rights reserved. Unauthorised copying or reproduction without the permission of West Pier Studio LTD is strictly prohibited.
Page 4 of 10
Language-Independent Questions
1) Describe some examples where you have implemented compile-time, and run-time,
polymorphism. Explain the benefits that polymorphism provided to these implementations.

2) What are some of the pro and cons of using properties (get / set accessors)?

3) What errors can you find with this pseudocode, and how would you modify it to fix these?
Additionally, how can you improve the performance of this code?

RemoveDuplicates(myList)
{
listCount = myList.Count;
for (i = 0; i < listCount; i = i + 1)
{
for (j = i + 1; j < listCount; j = j + 1)
{
if (myList[i] == myList[j])
{
myList.removeAt(j);
}
}
}
}

All information within this document is copyright © West Pier Studio LTD. All rights reserved. Unauthorised copying or reproduction without the permission of West Pier Studio LTD is strictly prohibited.
Page 5 of 10
C++ Test (Ignore this section if you have no C++ experience)
1) Why might it be reasonable to define a copy constructor and assignment operator, instead of using
the defaults?

2) What is the difference between a virtual function and a pure virtual function?

All information within this document is copyright © West Pier Studio LTD. All rights reserved. Unauthorised copying or reproduction without the permission of West Pier Studio LTD is strictly prohibited.
Page 6 of 10
3) We are building a game with an inventory system, where the player's inventory is represented as a
vector of Item objects. The inventory gets modified frequently during gameplay and we have
discovered that adding items is sometimes much slower than expected, causing performance
problems.

class Item {
std::string name;
public:
Item(std::string name): name(name) {
std::cout << "created a new item: " <<name << std::endl;
}

Item(const Item& other): name(other.name) {


std::cout << "copied an item: " <<name << std::endl;
}
};

int main(int argc, char* argv[]) {


std::vector<Item> bag;
bag.push_back(Item("Medicine"));
bag.push_back(Item("Life Stone"));
bag.push_back(Item("Soul Drop"));
bag.push_back(bag[0]);
}

OUTPUT:
created a new item: Medicine
copied an item: Medicine
created a new item: Life Stone
copied an item: Life Stone
copied an item: Medicine
created a new item: Soul Drop
copied an item: Soul Drop
copied an item: Life Stone
copied an item: Medicine
copied an item: Medicine

Based on the output of this program, why might this code be performing more copies than expected?
How can you reduce the number of copies the inventory system creates, while keeping its behaviour
the same?

All information within this document is copyright © West Pier Studio LTD. All rights reserved. Unauthorised copying or reproduction without the permission of West Pier Studio LTD is strictly prohibited.
Page 7 of 10
C# Test (Ignore this section if you have no C# experience)
1) Explain the differences between reference and value types, particularly thinking about their
implementations in C#.

2) An RPG has a party of 5 characters, each with 10 items. The game's interface displays a
subheading for each party member, followed by a list of their items. The code which does this has
been found to be causing performance problems due to the amount of garbage collection it causes.

Assume a C# implementation that allocates 16 bytes for an empty List<string>, and 8 more bytes for
each element added beyond the List's Capacity (initially 0).

for (int partyMember = 0; partyMember < 5; ++partyMember)


{
var partyItems = new List<string>();
for (int item = 0; item < 10; ++item)
{
var itemName = Party[partyMember].Items[item].Name;
partyItems.Add(itemName);
}

Print("Items for member {0}:", partyMember);


PrintItems(partyItems);
}

a) How much garbage does this code generate in total?


b) How can this code be improved to generate less garbage?

All information within this document is copyright © West Pier Studio LTD. All rights reserved. Unauthorised copying or reproduction without the permission of West Pier Studio LTD is strictly prohibited.
Page 8 of 10
3) The following code shows characters being created, using a list of items.

class Player
{
private List<string> inventory = new List<string>();

public Player(List<string> items)


{
inventory = items;
}

public List<string> GetItems()


{
return inventory;
}
}

// Jack has a potion and a sword

var jacksItems = new List<string>();


jacksItems.Add("potion");
jacksItems.Add("sword");
var jack = new Player(jacksItems);

// Jill has everything that Jack has, and a helmet

var jillsItems = new List<string>();


jillsItems = jack.GetItems();
jillsItems.Add("helmet");
var jill = new Player(jillsItems);

This code results in the wrong items being added to Jack’s inventory.
Why does this issue occur? How can the design of the Player class be improved to prevent this kind
of bug in the future?

All information within this document is copyright © West Pier Studio LTD. All rights reserved. Unauthorised copying or reproduction without the permission of West Pier Studio LTD is strictly prohibited.
Page 9 of 10
JavaScript Test (Ignore this section if you have no JavaScript experience)
1) Given the following code:

var obj = {};

obj.method = function() {
var logFunction = function() {
console.log(``This = ``, this);
};
logFunction();
};

obj.method();

What will the console print when console.log is called?

Provide up to 4 ways the code could be changed, so that the context of “this” would have a more
desired outcome.

2) Given the following code snippet:

var myFunction = function() {


var myVar = 0;

return function() {
myVar++;

return myVar;
};
};

var first = myFunction();


var second = myFunction();

console.log(first());
console.log(first());
console.log(second());
console.log(second());

What would be output to the console? Explain why this is the case.

All information within this document is copyright © West Pier Studio LTD. All rights reserved. Unauthorised copying or reproduction without the permission of West Pier Studio LTD is strictly prohibited.
Page 10 of 10

3A) Complete the following code by adding an inheritable function, “printName”, which logs the name
property to the console.

function Base() {
this.name = "Base";
};

var base = new Base();


base.printName();

3B) Now write a subclass, named “Sub”, which extends Base and prints its own name to the console.

All information within this document is copyright © West Pier Studio LTD. All rights reserved. Unauthorised copying or reproduction without the permission of West Pier Studio LTD is strictly prohibited.

Potrebbero piacerti anche