Upcoming SlideShare
×

# C,c++ develope test

390

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
390
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
14
0
Likes
0
Embeds 0
No embeds

No notes for slide

### C,c++ develope test

1. 1. TEST 29/06/2011 C/C++ DEVELOPER TEST (Answer in English or write code for question) C/C++ 1- What is the problem with this code? Please explain. void InitString(char *des) { des=new char[256]; des[0]='a'; des[1]='b'; des[2]='0'; } void main() { char 8p=0; InitString(p); cout<<p[1]; delete p; } Answer : 2-What is the problem with this code ?Please explain. void main() { ClasaA *a=new ClasaA[256]; delete a; } 3-What do you prefer to use ? Why? #define PI 3.14159265; or static const float PI=3.14159265 4-What value does p have at the end of the program .Why does it have this value? struct Mystruct { char a,b; }; -1-
2. 2. TEST 29/06/2011 void main() { Mystruct f ; f.a='a';f.b='b' ; char *p=&f.a ; p++; printf("%c",*p); )__________________________________ 5-What is the problem with this code ?Please expain. class A { public: int normal; A(){ normal=0;} ~A(){normal=1;} }; class B: public A { pulbic: int *p; B() {p= new int;} ~B(){delete p;} }; void main() { A *clasa=new B(); delete clasa; } 6-How many memory leaks will this program have? Please explain. class Test { Public: staic Test *get() { static Test* eu=0; if (!eu) -2-
3. 3. TEST 29/06/2011 eu=new Test; return eu; } }; void main() { for(int i=0;i<100;i++) Test *t=Test::get(); } 7- What is the diffenrence between the implementation from Tes1.cpp and the one from Test2.cpp? Test.h /////// Class Test { int i=0; Test(int i); }; Test1.cpp /////// #include "Test.h" Test::Test(int i1):i(i1){} Test2.cpp ////// #include "Test.h" Test::Test(int i1){i=i1;} 8-What does this program print?Why? union Vector3D { float v[3]; struct { float x,y,z; }; }; void main() -3-
4. 4. TEST 29/06/2011 { Vector3D t; t.x=1.0f;t.y=2.0f;t.z=3.0f; t.v[1]=1.0f; std::cout<<t.x<<" "t.y<<" "<<t.z; } 9-Wil this program generate a memmory leak? Why? void main() { char *p=new char[256]; delete p; } 10-What's the binary value of '0'? What is the difference between '0' and '0'? 11-Will this code return the correct value? float medie(float a,float b) { rerurn 1/2*(a+b); } 12-What are the conditions which have to be accomplished in order for this code to work?Why? cObject CreateObject() { cObject t; return t; } 13- Explain what causes the compilation error. class Vehicle { public : float weight ; void driven(); }; class ForWater:public Vehicle { public: void waves(); -4-
5. 5. TEST 29/06/2011 }; class ForLand:public Vehicle { public: void holes(); }; class BothWaterAndLand: public ForWater, puclic ForLand { public: void setWeight(){ weight=0.0f;} }; void main() {} 14-When is the Fibonaci sequence generated ? What problems would the excessive usage of templates generate on large scale projects? #inclue "iostream" using namespace std; template<unsigned int n> struct fib { static const unsigned int result=fib<n-1>::result+fib<n-2>::result; }; template<>struct fib<1> { static const unsigned int result=1; }; template<> struct fib<0> { static const unsigned int result=0; }; int main() { std::cout<<"fib<43>="<<fib<43>::result<<'n'; return 0; } 15-What are the conditions which have to be accomplished in order for this code to compile?Why? -5-
6. 6. TEST 29/06/2011 template<class T> class ClasaTeste { private: T m_var; public: void Add(T newVar) { m_var+=newVar; } void Add1(T newVar) { m_var=m_var+ newVar; } }; class cVector3df { float x,y,z; }; vodi main() { ClasaTeste<cVector3df>t; cVector3df p; t.Add(p); t.Add1(p); } 16-Implement a general function which interchanges different types of variables using templates. 17- What is the mistake in the code below ?Please explain. class Animal { public: void Eat(){} void Sleep(){} }; class Cat: public Animal -6-
7. 7. TEST 29/06/2011 { public: void Meow(){} }; class Dog:public Animal { public: void Bow_Wow(){} }; void main() { std::vector<Animal*>animals; for (int i=0;i<10;i++) { if(i%2) animals.push_back(new Dog); else animals.push_back(new Cat); } for(int i=1;i<10;i++) { if(i%2) ((Cat*)animals[i]))->Meow(); else ((Dog*)animals[i]->Bow_Wow(); } } 18-Why isn't the result 65? #define add(x,y,z) x+y+z vodi main() { float expresie= (add(10,2,1)*5.0f); printf("%f",expresie); scanf("%s"); } -7-
8. 8. TEST 29/06/2011 19-Given a tree (not necessarily a binary tree) and 2 nodes which belong to the tree, find the closest common parent for these 2 nodes .Implement the structure .Write a function that takes two nodes as parameters and returns the closest common parent for the two nodes. 20-Is the function SafeDel correct ?If not ,please fix it in order to keep the same way of calling the function .Give a reason fof which one would rather use SafeDel than delete. template <class T> inline void SafeDel(T *p) { delete p; p=0; } void main() { int *i=new int; SafeDel(i); ) 21-If this function was used on windows in order to decide wiht which program to open the file what problems could arise?Give an example fof each problem you idenfify. char *GetFileExtension(const char *Filename) { char *extension=(char*)FileName; While (*extension++!='.'); return extension; } 22-How can one determine the system endian),using the printed result. void main() { int i=0; const unsigned char t[]={2,0,0,0,}; memcpy(&i,t1,sizeof(int)); printf("%d",i); -8- type (little endian/big
9. 9. TEST 29/06/2011 } 23-Explain the problem that may occur in the code below. void main() { int i=0; printf ("%d%d",i,i++) } 24-Find any kind of problem in the code below: class Test { public: int i; void seti(int i1){i=i1;} void addi(){i++;} }; void main() { Test p(); p.seti(2); p.addi(); } 25-Can this code be wirtten without using a loop? #include <iostream> using namespace std; #define NUMAR 100 void main() { unsigned char a[256]={0}; unsigned char *adr=a; *adr=0; for(int i=0;i<NUMAR;i++,*adr=(*adr)<<1,(i>=sizeof(char))*8&&(*adr)==0)?*++adr=1:NULL); } 3D Algebra 26-Given c=[1,2,3] b=[1 2 3]T Does bc=cb ?If not ,write the results for bc and cb. 27-Compute the determiant of the following matrix -9-
10. 10. TEST 29/06/2011 3 -2 0 1 4 -3 -1 0 2 28-Compute the inverse of the following matrix. -4 -3 3 0 2 -2 14 1 29-Implement the dot product using the following structure:: struct cVector3df{float x,y,z;} 30-Does 0.(9)=1.0?Please explain. 31-What are the intersection conditions between a vector and a plane? (direct cVector3df, plan cPlane) 32-What are the intersection conditions between a cube and a sphere? class bbox3D{ cVector3df min,max;};class sphere{float Radius; cVector3d Point;}; 33-Given a unit cube with the minium point coordinates at( 0,0,0).Write a matrix which translates the the minium point cordinates of the cube to (5,5,5); 34-Write a function which verifies the collision between 2 AABB boxes. 35-Given an object of mass m connected to a wall by a spring with spring constant equal to k.The object is kept in balance with a force F,the spring being compressed .At t=0 seconds the force F disapprears.The friction force has the following expression Ff=c*v(where c is a constant and v is the instant speed )during the movement of the spring .Write a function which receives as parameters F,m,K,c and dt and updates the elongationj(spring solver lD) 36-How would you implement the physics on a big boat without engine in order to optimize the resources ? Give details.(You may use the simplest geimetrical figure to simulate the boat and the actions of the water on it). Graphics 37- Give an example of a situation when you would prefer to use a mix system of animation :bone animation plus per vertex animation. 38-If we have a character wiht animations and we want to use a normal map ,why do we have update the TBN's at each vertex movement? 39-How would you implement a skybox? 40-How would you implemnet the terrain in a First Person Shooter? 41-Give an example where a fiel with bone animation is bigger than a file wiht vertex animation given the same mesh and the sam - 10 -
11. 11. TEST 29/06/2011 animation 42-Write a shader which makes a plane behave exactly like a billboard. 43-What does the following shader do? ////////////////////////////// precision mediump float; attribute vec4 a_position; atrribute vec2 a_texCoord; uniform sampler2D s_texture; uniform mat4 u_mvpMatrix; varying vec4 v_position; void main() { float h=a_position.y+texture2D(s_texture,a_texCoord).r; g1_Position=a_postion; g1_Position.y=h; v-position=g1_Position; g1_Position=u_mvMatrix *g1_Position; }////////////////////////// pixel Shader void main() { g1_FragColor=vec4(0.5,0.5,0.5,1.0); } Logics Problem 44- A man convicted to death has the right to say a last sentence before he dies . If he tells the truth he wil be decapitated and if he lies he will be burned alive.What sentence will he say? Optimizations 45- Optimize the following code void sort(unsigned char *v,int len) { bool sort =false; while(!sort) { sort =true; - 11 -
12. 12. TEST 29/06/2011 for(int i=0;i<len-1;i++) if(v[i]>v[i+1]) sort=false; if(sort==false) { for(int i=0;i<len-1;i++) if(v[i]>v[i+1]) { unsigned char t=v[i]; v[i]=v[i+1]; v[i+1]=t; } }}} AI 46-Wire 2 advantages and 2 disadvantages for using a state machine when implementing the artificial intelligence in a game. 47-Write a function that decides the next move in a tic-tac-toe game . Void updateAI(float difficulty,char *table,unsigned int &resultX,unsigned int & resultY) GAME DEVELOPMET 48-Why would you need a texture manager?How would you implement a texture manager? 49-What does the local position of a node in the scene mean versus its global position (the objects are being stored in a tree)? How would you calculate the global and local position? HARDWARE 50-What is the best way to send information to the GPU,alot of data at the time or less information but frequently. - 12 -