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 radius;
    
    
    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;
        radius = R;
        
        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);
}

- albertchenyu February 24, 2015 | Flag Reply
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.

- Yola February 11, 2015 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More