The submission instructions for questions involving functions are different from other questions.
A helper code has been provided to you which contains the main_program that calls the function to be implemented. You are required to write this function in a separate file and upload only this file. To make it clear, here is an example sample question.
int add(int a, int b); // function declaration is required during compilation
Now you create a solution file named add.cpp and write the function definition as
int add(int a, int b)
{
return a+b;
}
On Linux and MacOS, you can use the following command to compile your program
s++ add_main.cpp add.cpp
On Windows, in Simple CodeBlocks, copy the function code in the helper code file, below the main_program as shown below.
#include
int add(int a, int b); // function declaration is required during compilation
main_program
{
int a,b;
cin >> a >> b;
cout << add(a, b) << endl;
}
// #include // do not include simplecpp again
int add(int a, int b)
{
return a+b;
}
This is only to compile and run as usual to check. Note that this is only for checking that the function implementation is correct.
Finally upload the solution file add.cpp that only contains the function implementation, and not the main_program. Do not upload the helper code file add_main.cpp.
Write a function that takes the coordinates of three non-collinear points p1, p2, p3 along with the coordinates of a query point q as input, and returns true if the query point lies on the plane formed by p1, p2, p3, else it returns false. The function should also calculate the distance of the query point q from this plane and store it in the last parameter dist.
Function to implement
bool point_on_plane(double* p1_x, double* p1_y, double* p1_z, double* p2_x, double* p2_y, double* p2_z, double* p3_x, double* p3_y, double* p3_z, double* q_x, double* q_y, double* q_z, double* dist)
Input Format
12 real numbers (space separated)
Output Format
An integer (either 1 or 0 representing if q lies on plane)
A real number representing the distance of q from the plane. The output should be correct upto 2 decimal places.
In order to force cout to always print 2 digits after the decimal point, do the following before printing the output with cout
cout << fixed; // uses fixed floating point representation
cout.precision(2); // print two digits after the decimal point
Constraints
Each of the coordinates are real numbers that lie between -103 and 103
Sample Input 1
0 0 1 1 2 3 2 3 4 7 6 8
Sample Output 1
0 0.71
Sample Input 2
0.0 0.0 0.0 1.0 1.0 1.0 1.0 2.0 3.0 3.0 2.0 1.0
Sample Output 2
1 0.00
Filename to submit
point_on_plane.cpp