## Interview Question for Software Engineers

Country: United States

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>

using namespace std;

class LineSeg {

public:

double x;
double y;
double z;
double l;

LineSeg(double X,double Y, double Z, double L){
x = X;
y = Y;
z = Z;
l = L;
}

};

class Circle {

public:
double centerX;
double centerY;
double centerZ;

double normalX;
double normalY;
double normalZ;

Circle(double X, double Y, double Z,double R, double nx, double ny, double nz) {
centerX = X;
centerY = Y;
centerZ = Z;

normalX = nx;
normalY = ny;
normalZ = nz;

}
};

Circle * Configuration(LineSeg * L0, LineSeg * L1 ){
double dx = L0->x - L1->x;
double dy = L0->y - L1->y;
double dz = L0->z - L1->z;

double distance = sqrt( dx*dx + dy*dy + dz*dz);

//cosine theorem
double cos_of_L0_axis = (L0->l * L0->l + distance*distance - L1->l * L1->l )/ (2 * L0->l * distance );
double centerDis_from_L0 = cos_of_L0_axis * L0->l;
double sin_of_Lo_axis = sqrt(1 - cos_of_L0_axis * cos_of_L0_axis);
double radius_of_circle = sin_of_Lo_axis * L0->l;

//parameterized expression
double centerx = L0->x + dx * (centerDis_from_L0 / distance);
double centery = L0->y + dy * (centerDis_from_L0 / distance);
double centerz = L0->z + dz * (centerDis_from_L0 / distance);

if (distance > L0->l + L1->l) {
cout << "two points are too far from each other"<<endl;
return nullptr;
}

double dis = 0;
dis = L0->l - L1->l;
if(dis < 0){
dis = -dis;
}

if (distance < dis) {
cout<< "two points are too closed to each other" << endl;
return nullptr;
}

return new Circle( centerx, centery, centerz, radius_of_circle, dx,dy,dz);
}``````

Comment hidden because of low score. Click to expand.
-2
of 2 vote

You know all three sides of the triangle, so you can use law of sines to find neede angle and then calculate required position.

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.