游戏公司面试题,80分求解,该如何解决

游戏公司面试题,80分求解
内容如题,自己做了一些,有些不知道对错,所以干脆拿上来大家一起讨论学习一下,跪谢各位了。各位解答时请注明是哪道题,8道题每题10分一共80分。对不起了,我新手没多少分,否则会重重答谢大家的!!
我会把自己的答案也放上来供大家参考指正。
再次感谢!!!
1. Without using any standard library functions, write a function that accepts a string and toggles all of the individual letters within between upper and lower case – optimally. For example, if the input string were “Mixed Case!” the output would be “mIXED cASE!”

To make sure the test doesn’t go astray please write the main() function to call your function and pass in your name as a parameter.

// insert code here

2. Consider the following code snippet:

Note: You should not use a compiler to answer this question.

class AbstractBase
{
public:
AbstractBase()
{
m_pCharArray = new char[ 16 ];
}

~AbstractBase()
{
delete m_pCharArray;
}

virtual void function( void ) = 0;

private:
char *m_pCharArray;
};

class Derived : public AbstractBase
{
public:
Derived()
{
m_pDerivedArray = new char[ 16 ];
}

~Derived()
{
delete m_pDerivedArray;
}

void function( void ) {};

private:
char *m_pDerivedArray;

};

AbstractBase* factory( void )
{
return new Derived;
}

int main(int argc, char* argv[])
{
AbstractBase* pObject;
pObject = factory();
delete pObject;

return 0;
}


The main function calls a factory method that returns ‘a kind of’ Base. In this case you can see that the factory method specifically returns a specialized Derived class which is intentional.

a) What bugs are present in the code? What problems are caused by this?
b) How would you fix them?

3. What sort of performance overhead is incurred when using const in C++ programs to create classes and member functions that are considered to be ‘const correct’?

4. Consider the following function that takes in a pointer to the header of a linked list as a parameter, calls an unknown library function and dumps the value stored in each node.

struct sllist
{
int value;
sllist* pNext;
};

// parameter pHeader, pointer to the head of a linked list structure for integers
// the list is of unknown size and is terminated with lastnode->pNext == NULL
void DumpList( sllist *pHeader )
{
DodgyFunction( pHeader ); // library function, no source available

// iteration code  
sllist *pCurrent = pHeader; // point to head of the list
while( pCurrent->pNext != NULL ) // iteration loop
{
printf("%d\n", pCurrent->value );
pCurrent = pCurrent->pNext; // go to the next value
}
printf("%d\n", pCurrent->value ); // print the value in the last node
}


When you execute DumpList() it appears that the program remains stuck in the iteration loop. At the time of calling this function, you have determined that you have a valid linked list that is correctly terminated.

a) What is DodgyFunction() doing?
b) Without changing the sllist node structure or altering the iteration code, add code after the DodgyFunction() call to confirm your theory. The code should be as optimal as possible.



5. You are working on a title that is specified to run at 60 frames per second (60Hz), but is currently under-performing. Running a profiling tool tells you how much time is used in an average frame by major systems:

RenderSystem::update() - 10ms
AISystem::update() - 20ms
ScriptingSystem::update() - 1ms
UserInputSystem::update() - 8ms
UISystem::update() - 2ms
PhysicsSystem::update() - 4ms

Describe ways you could get the program to run at 60Hz based on this profiling data.

6. You have an array of 4 32-bit integers which you use to store a 128-bit number. Fill in the following functions for bitwise shifting operations.