Author Topic: CodeMaster Test !  (Read 7925 times)

0 Members and 1 Guest are viewing this topic.

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
CodeMaster Test !
« on: March 29, 2007 »
 
CODEMASTERS YOSEMITE PROGRAMMING TEST



C/C++
1)
Write a class that implements a simple list. It must provide methods to add and remove values, and provide some way to iterate through all elements in the list.

2)
Write destructors for these two classes.
class A
{
public:
   int *a;
   A() { a = new int[10]; }
};

class B : public A
{
public:
   int *b;
   B() { b = new int[20]; }
};


3)
Given the following definition, write a constructor that sets the value of m_constant.


class CConstant {
public:
   const int m_constant;
   const int Get() {return m_constant; }
};

4)
Write a copy constructor for the Circle class defined below. In what two situations does the C++ compiler use the copy constructor implicitly?

class Circle {
public:
Circle();
int center_x;
inst center_y;
double r;
};
5)
What is a hash table? What is its purpose, and how does it function?
6)
What does mysteryFunction return?

int mysteryFunction ( int n)
{
int k = 0;

while( n ) {
k++; n = n / 10;
}
return k;
}

Assembly
1)
What does MysteryFunctionAsm() do. What assumptions does it make?

void MysteryFunctionAsm(unsigned char far *addr,
unsigned      value1,
int         value2)
{
   _asm   {
      les di,addr     

      mov al,BYTE PTR value2
      mov ah,al

      mov cx,value1
      shr cx,1

      rep stosw
   }
}
2)
Write a function in assembly language (80x86, 680x0, or PowerPC) that returns the address of the first byte in a memory block that has the most significant bit set. The function will take a pointer to the beginning of a block of RAM, and the size of the memory block. The function must return the address of the first byte, or null if a non-zero byte is not found. The function should be as fast as possible, especially for long searches.

The prototype for the function is:
void* FindNegByte(void *ram, char size, char key_value);
3D
1) Matrix Math
Calculate the sum of these two matrices.
|2 3|   |3 -1|
|1 4| + |5  6|

2)
Calculate the product of these two matrices.
|2 3|   |5 6|
|1 2| * |3 0|

3)
What does mysteryFunction3D() compute?

struct vector_3d_typ {
// a 3-D vector along with normalization factor
float x,y,z,w;   
} vector_3d,*vector_3d_ptr;


float mysteryFunction3D_1(vector_3d_ptr u,vector_3d_ptr v)
{
return( (u->x * v->x) + (u->y * v->y) + (u->z * v->z));
}

4)
What is the identity matrix of  a 3 x 3 matrix?
5)
Write a function to multiply two 16.16 fixed point numbers. Where...
typedef long   FIXED;
6)
What is a BSP tree? How does it function?
 

Internet
1)
Write a function to load into memory the html page at http://www.yahoo.com.
2)
Re-write the simple list class for the first class so that it is threadsafe.


Do anyone like to try this?



Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: CodeMaster Test !
« Reply #1 on: March 29, 2007 »
Assembly 2 -
Code: [Select]
org 100h         ; entry point for .com
jmp findaddress
addrss  db 00h,00h,00h,00h  ; 4 bytes for address
string  db 128 dup (?)      ; same value but in string form
buffer  db 0FFFFh dup (?)   ; the buffer we will search






; heres where the magic happens #########################################
pusha
push es
findaddress:
   lea di,buffer ; buffer we will be searching
   xor cx,cx     ; cx will be decrimented at loop for maximum search size
searchit:
   lodsb         ; get byte and increase di (pointer)
   and al,80h    ; set all but the high order bit to zero
   or  al,al     ; quick compare
   jnz foundit   ; if al isn't zero than we have our buffer offset
   loop searchit ; otherwise repeat maximum cx times
   mov  di,01    ; if we get here we didnt find one
   xor  es,es
foundit:
   dec di        ; di was pointing one byte beyond actual address
   mov ax,es     ; get segment offset
   mov bx,di     ; store address for start of buffer
   lea di,addrss ; heres where we will put the address
   stosw         ; store segment in variable
   mov ax,bx     ; get address for start of buffer
   stosw         ; store offset in variable
pop es
popa
; that was it ############################################################






converttostring:
   pusha
   lea si,addrss  ; convert value
   lea di,string  ; to hex string
   mov cx,4       ; 4 byte value
   call hexstringproc
   popa

printresult:
   pusha
   mov  ax,03h    ; mode number
   int  10h       ; bios call
   mov  bx,5      ; get x value
   mov  dx,5      ; get y value
   lea  si,string ; get string offset
   call textproc
   popa

pauseforkey:
   xor ah,ah
   int 16h
   ret

hexstringproc proc
    xor ax,ax
    lodsb
    ror ax,04h ; mov lower number from al to ah
    shr ah,04h ; repair al
    add ax,3030h
    cmp ah,"9"
    ja  hexstringah
    hexstringcheckal:
        cmp al,"9"
        ja  hexstringal
    hexstringstore:
        stosb
        mov al,ah
        stosb
        loop hexstringproc
    mov al,"h" ; hex terminate
    stosb
    xor al,al  ; zero terminate
    stosb
    ret
    hexstringah:
        add ah,07h
        jmp hexstringcheckal
    hexstringal:
        add al,07h
        jmp hexstringstore
hexstringproc endp
textproc proc
    ; find length of string
    mov   di,si    ; string address
    pusha       ; preserve registers
    cld         ; clear flags
    xor   al,al ; compare zero
    mov   cx,-1 ; compare maximum 0FFFFh times
    repnz scasb ; compare until both are zero
    not   cx    ; invert cx
    dec   cx    ; point cx to char before the zero
    mov   es,cx ; conserve value in es
    popa        ; restore registers
    mov   cx,es  ; restore value
    mov   di,si    ; string address
    ; prepare offset for co-ordinates
    push  0B800h   ; screen text buffer
    pop   es
    mov   ax,160   ; screen width in bytes (80 words/chars)
    mul   dx       ; convert to offset
    add   ax,bx    ; x co-ordinate
    add   ax,bx    ; double x (for word)
    mov   di,ax    ; load finished offset
    ; print it to screen
    mov   ah,0Fh  ; colour attributes
    textloop:
        lodsb      ; load next char
        stosw      ; store char & colour
        loop textloop
    ret
textproc endp
tooooo easy to be considered a challenge when reading a byte using lodsb es:di already holds address of the byte in question

float mysteryFunction3D_1(vector_3d_ptr u,vector_3d_ptr v)
{
return( (u->x * v->x) + (u->y * v->y) + (u->z * v->z));
}

what the hell kinda operator is "->" supposed to be but it looks somewhat like a 3 dimensional crossproduct if "->" is actually a minus

Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: CodeMaster Test !
« Reply #2 on: March 29, 2007 »
my mistake thats no crossproduct

Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: CodeMaster Test !
« Reply #3 on: March 29, 2007 »
Assembly 1 - MysteryFunctionAsm()

addr  address of the buffer to be written to
value 1 is the number of bytes that should be copied
value 2 is the byte that gets copied

basically drop double copies of [value 2] into buffer specified by [addr] repeatedly 1/2 [value 1] times

Challenge Trophies Won:

Offline p01

  • Atari ST
  • ***
  • Posts: 158
  • Karma: 51
    • View Profile
    • www.p01.org
Re: CodeMaster Test !
« Reply #4 on: March 29, 2007 »
I've not coded in C/C++ for like 8 years :p

C.6.
returns the log10 of n

3D.1.
|5  2|
|6 10|

3D.2.
|19 12|
|11  6|

3D.3.
returns the scalar|dot product of the vectors u and v

3D.4.
|1 0 0|
|0 1 0|
|0 0 1|

3D.5.
?
int function mul16_16( int a, int b )
{
  return a*b>>16;
}

3D.6.
Won't go into details but the indea of a BSP, Binary Space Partionning, tree is to chop the space/scene recursiverly in half spaces ( which might involve splitting some triangles in the scene ) to optimize the traversal of the said scene. It's handy to find what faces an observer at any given point and direction.

WEB.1.
does an XHR done in JS qualifies :p

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: CodeMaster Test !
« Reply #5 on: March 29, 2007 »
Quote
what the hell kinda operator is "->" supposed to be
That's a pointer. (And it's a dot product).
Say you have
Code: [Select]
typedef struct
{
  int x, y;
} point;

int main(void)
{
point a;
point *b;
int c;

a.x=5;
a.y=6;

b=&a; /* b is now the address of a */

c=b->x; /* b->x is retrieved from a */
/* c is now equal to 5 */

return 0;
}

C/C++
2.
virtual ~A() { delete [] a; }
~B() { delete [] b; }

Anyone else a C++ fan?  Did I get the virtual in the right place?

3.  I know you can write to constants in constructors.
CConstant(int initial_value)
{
 m_constant = initial_value;
}

6.  is 1+n/10

3D
5.  You have to worry about overflow and precision.
/* if 64bit longs are available */
FIXED mulfixed(FIXED a, FIXED b)
{
return ((__int64)a*b)>>16;
}
/* if floats are available */
FIXED mulfixed(FIXED a, FIXED b)
{
return (FIXED)(((float)a*b)*(1.0f/65536.0f));
}
/* hard way */
FIXED mulfixed(FIXED a, FIXED b)
{
FIXED top32;
FIXED mid32;
top32 = (a>>16)*(b>>16);
mid32 = (a&0x0000ffff)*(b>>16)+(a>>16)*(b&0x0000ffff);
return top32+(mid32>>16);
}
someone want to check that?

Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: CodeMaster Test !
« Reply #6 on: March 30, 2007 »
C/C++
2.
virtual ~A() { delete [] a; }
~B() { delete [] b; }

Anyone else a C++ fan?  Did I get the virtual in the right place?

Yup. It is in the right place Jim. If you sometimes struggle where to put the virtual
keyword - it is also no problem putting it in front of both destructors. But keep that
in mind if there is another class C e.g. which is derived from B.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline ferris

  • Pentium
  • *****
  • Posts: 841
  • Karma: 84
    • View Profile
    • Youth Uprising Home
Re: CodeMaster Test !
« Reply #7 on: March 30, 2007 »
It's times like these when you realize how little you really know about your programming language...;D
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: CodeMaster Test !
« Reply #8 on: March 31, 2007 »
My problem lately has been that C++ hadn't even been standardised when I was at university, so I have never had a C++ course.  All the new programmers at my work have done C++ at some stage in their education.  So I'm having to teach myself, which isn't a problem for me, specifically, since I use the language every day.  It's just when someone asks me a question or to explain something about the language, I'm really not that confident.

Jim
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: CodeMaster Test !
« Reply #9 on: April 01, 2007 »
In my university the main language was Java. We had some basic C and ASM courses as well
though. Nevertheless, we didn't focus on a certain language anyway. The focus was
to get to know all the design patterns and steps of software architecture and pro-
ject planning. The actual programming language was secondary then ...

But, as far as I can judge it - your explanations are very good here, Jim !!!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: CodeMaster Test !
« Reply #10 on: April 01, 2007 »
Absolutely - the point is not what languages you know, it's the discipline of computing and software engineering that matter.  That's what's pissed me off recently - the pre-interviews I've had have had questions like the OP's in them and that is totally irrelevant to my skills.

We did Modula-2 at university, and Eiffel.  How useful was that to getting a job?

Jim
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: CodeMaster Test !
« Reply #11 on: April 01, 2007 »
Thats fuckin stupid they are so busy tryin to cover all the bases that they figure you will pick up the most important stuff yourself. I never went to college myself I learnt to program through trial and error its the best way I think you might pick up some bad habits by doing it but over time your strengths outweigh them

Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: CodeMaster Test !
« Reply #12 on: April 01, 2007 »
Hey that sucks jim. I'm studying e-commerce at the moment but doing the C++ module from the standard IT degree just cos I want to be able to show that I have some experience with the language.

Still its not going to prove that I can do anything useful with it. I just have to make one console app using inheritance and dynamic objects. Then sit a multiple choice exam. I'm sure you would find this all piss easy and it wouldent take you long either. Maybe you could do something similar? Then at least you will have something to shove in the next dumb employers face.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: CodeMaster Test !
« Reply #13 on: April 01, 2007 »
lol i must be getting better i got 2 questions correct :updance:.

the 2dcrossproduct one and the matrix addition  :D
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: CodeMaster Test !
« Reply #14 on: April 01, 2007 »
I taught myself C on the Amiga while I was at university - in fact, I had to code my dissertation in C because the Sun workstation I was given to use didn't have Modula-2 on it, and I've taught myself C++ on this job.  I don't particularly want a certificate to shove in someone's face.  If that's what they are looking for, then they are not looking for me, they're looking for a piece of paper :)

Jim
Challenge Trophies Won: