Pergunta de entrevista da empresa GE HealthCare

1. What is a virtual? 2. If class has virtual function, what happens in compile time and in run time? 3. What is a polymorphism? 4. Write the function that gets array of chars and returns number of elements with 3 bits ON, performance is important. 5. Write the function that draws a line from x1,y1 to x2,y2 6. You have very long function with many return statements. You have to determine how much time it runs.

Respostas da entrevista

Sigiloso

8 de set. de 2016

2. in C++, when a class defines has at least one Virtual Function, an extra pointer is added to the class definition called Virtual Table Pointer (aka vptr) which points to a Table containing Function Pointers. (each Class defines it's own VirtualTable). when an object is created, just before calling the constructor, the VPTR is set to the Table of the actual created object (actually it get overwritten by the deriving objects) lastly, any call to a Virtual function is not called directly, but through its corresponding pointer (*vptr[fidx])().

Sigiloso

8 de set. de 2016

3. polymorphism is the SW Engineering Terminology for OO ability of requesting an acting on References(Pointers) of same base types, but actually having different behaviours based on the actual object pointed. this is achieved using Virtual & Pure-Virtual Functions

Sigiloso

8 de set. de 2016

4. unsigned int charsWith3(char* str, char bits) { static const char bitsOn[255] = { 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7 }; int c(0); while (*str != '\0') { if (bitsOn[*str] == bits) ++c; ++str; } return c; }

Sigiloso

6 de jan. de 2021

draw line #include #include #include #include std::vector> Matrix; void putpixel(int x,int y,int color) { Matrix[y][x] = '1'; } void Line(const int x_1,const int y_1,const int x_2,const int y_2) { int color=7; int x1=x_1; int y1=y_1; int x2=x_2; int y2=y_2; if(x_1>x_2) { x1=x_2; y1=y_2; x2=x_1; y2=y_1; } int dx=std::abs(x2-x1); int dy=std::abs(y2-y1); int inc_dec=((y2>=y1)?1:-1); if(dx>dy) { int two_dy=(2*dy); int two_dy_dx=(2*(dy-dx)); int p=((2*dy)-dx); int x=x1; int y=y1; putpixel(x,y,color); while(x lineOfPix(64,'0'); Matrix.push_back(lineOfPix); } Line(2,2,20,50); for(int i = 0; i<64 ; ++i) { for(int j = 0; j<64 ; ++j) { std::cout<