Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/gpl4you/public_html/_config-rating.php on line 26

Write me a function that receives three integer inputs for the lengths of the sides of a triangle and returns one of four values to determine the triangle type (1=scalene, 2=isosceles, 3=equilateral, 4=error). Generate test cases for the function assuming another developer coded the function

Each number represents the first number found after the decimal point when one number is divided by another. The first number, 5 is for 1/2; 6 is for 2/3, 7 is for 3/4, 8 is for 4/5, & so on.

++a means increment & use. a++ means use & increment. i.e use the same value and then increment. This means a temporary is created to hold & use the same value. While a is incremented. So, ++a is faster & it is always better practice to use ++a

Q. No. :

5

Question :

What it wrong with this function:
F1(...){
x = new();
F2();
delete x;
}

F2() has to assume that x has been newed i.e F1() has been called. This results in dependency of F2() on F1(). The design is flawed. If F1 throws an exception, F2 may not be called & memory for x cannot be reclaimed as long as the program is running.

Q. No. :

6

Question :

Given 2 squares on a 2 dimensional plane, find a line that would cut these two squares in half.

Find the centers of the squares and draw a line joining them. Any Line passing the center of the square cuts it in half.

Q. No. :

7

Question :

Suppose you have a 100 files in a directory and you need to find out if a keyword occurs in these files. How would you do it in Unix? How would you do it in Windows?

on Unix:
grep /*
on windows (using a dos command):
find (keyword) (file location & pattern)

Q. No. :

8

Question :

Given a cube. A ant is placed in a corner and cannot move. A spider starts from the opposite corner, and can move along cube edges in any direction (x,y,z) with probablity 1/3. What is the expected number of steps for this spider to get to the ant?

Let x=number of turns to reach ant from starting point.
Let y=number of turns to reach ant from diagonal corner on same face as ant.
Let z=number of turns to reach ant from an adjacent corner to ant.

After one turn the spider will be on a diagonal corner of a common face as the ant. So the mean number of turns from the x position is one more than the mean number from the y position:

E(x)=1+E(y).

Once at a y position there is a 2/3 chance it will then move to a z position, and a 1/3 chance back to an x position:

E(y)=(2/3)*(1+E(z))+(1/3)*(1+E(x)).

If the spider arrives at a z position there is a 1/3 chance it will move to the ant, and a 2/3 chance it will move back to a y position:

E(z)=(1/3)*1+(2/3)*(1+E(y)).

With these three equations and three unknowns it is not difficult to solve for E(x), E(y), and E(z).

Q. No. :

9

Question :

What is: in-order traversal of tree, quick sort in an array

A duck is in circular pond. The duck wants to swim ashore, because it wants to fly off and this particular duck is not able to start flying from the water. There is also a fox, on the shore. The fox wants to eat the duck, but this particular fox cannot swim, so it can only hope to catch the duck when the duck reaches the shore. The fox can run 4 times faster than the duck can swim. Is there always a way for the duck to escape?

(You don't have to remember much linear algebra to understand this -- just the formula for multiplying two symmetric 2x2 matrices:

[ a b ] [ d e ] [ ad + be bd + ce ]
[ b c ] [ e f ] = [ bd + ce be + cf ]

You can then prove the result above by induction: Let

[ 1 1 ]
A = [ 1 0 ]

assume by induction that the equation above is is true for some n, multiply both sides by another power of A using the formula for matrix multiplication, and verify that the terms you get are the same as the formula defining the Fibonacci numbers.)

int M[2][2] = {{1,0}{0,1}}

int fib(int n)
{
matpow(n-1);
return M[0][0];
}

void matpow(int n)
{
if (n > 1) {
matpow(n/2);
M = M*M;
}
if (n is odd) M = M*{{1,1}{1,0}}
}

Q. No. :

12

Question :

A computer has three registers, A, B and R. It has only three instructions:

A->R : Load R with A

B->R : Load R with B

A-R->A : Subtract R from A and store the result in A

Using these instructions how can you do the follwoing?

SELECT *
FROM customer c JOIN orders o ON c.custId=o.custId
JOIN order_items oi ON oi.OrderId=o.OrderId
JOIN inventory i ON oi.invId=i.invId
WHERE c.LName=:lname;

**NB: Breaking Order_items into a separate table to prevent a many-to-many relationship. For interview, this is probably not necessary

Q. No. :

14

Question :

What is static method? What is a static initializer?

A staic method in a class's role is to use the static data members only.
and staic method can be accessed by a static/non-static class object.
But a static method cannot have non-static access to the data-members.
And static method cnnot be constant, volatile and virtual.

Now, static non-class method: A staic keyword in front of a non-class method is used to limit the method scope to the current compilation unit. It has internal linkage and one can use this principal in C for information hiding, while class's static method/data-member has external-linkage.
e.g.
In abc.cpp/c
static void print_some_data()
{
}
is limited in abc.cpp/c only, no other compilation unit in an application can use it.

Q. No. :

15

Question :

Write a method to calculate the acute angle between a clock hour hand and minute hand.

public class Clock{
public static void main(String args[]){
long hours = 3;
long minutes = 15;
// Angle made by the hour hand in hours and minutes
long angle_hour = 30* hours;
double angle_Min_hour = 0.5*minutes;
long mins = 6 * minutes;
System.out.println(angle_hour+":"+angle_Min_hour+":"+mins);
System.out.println("Diff:"+((angle_hour+angle_Min_hour)-mins));
}
}

Q. No. :

16

Question :

Template vs. Inheritance. Why use one over the other?

Templates are useful when a specific behavior is independent of data type on which it operates.
Whereas inheritance is useful when a)code reuse b)more specifically (as in case of polymorphism) you want to have different specific behavior with a generic name for the behavior.

Q. No. :

17

Question :

Given a IP address, Validate the IP address. The IP address lies between [000.000.000.000]-[255.255.255.255] .
IP address is in String, hence you can fetch the characters in the string and move ahead.

Virtual Functions are implemented usign the vtable, which is a table of function pointers for each of the virtual function present in the class.
The class creates a vtable upon call of its constructor. In case of derived class ,base class creates the initial vtable but constructor of derived class over-rides the entry in the vtable if the virtual function is defined in derived class.

Q. No. :

19

Question :

What’s the difference between these two declarations?
struct str1 { … } ;
typedef struct { … } str2 ;

The first form declares a structure tag whereas the second declares a typedef. The main difference is that the second declaration is of a slightly more abstract type — its users don’t necessarily know that it is a structure, and the keyword struct is not used when declaring instances of it.