home / study / engineering / computer science / computer science questions and a
ID: 3885499 • Letter: H
Question
home / study / engineering / computer science / computer science questions and answers / (geometry: points in triangle?) c++ program suppose a right triangle is placed in a plane as ...
Your question has been answered
Let us know if you got a helpful answer. Rate this answer
Question: (Geometry: points in triangle?) C++ program Suppose a right triangle is placed in a plane as show...
(Geometry: points in triangle?) C++ program
Suppose a right triangle is placed in a plane as shown below. The right-angle point is placed at (0, 0), and the other two points are placed at (200, 0), and (0, 100). Write a C++ program that
prompts the user to enter a point with x - and y -coordinates and determines whether the point is inside the triangle
Here are some sample runs:
Enter a point's x- and y-coordinates: 100.5 25.5
The point is in the triangle
Enter a point's x- and y-coordinates: 100.5 50.5
The point is not in the triangle
(0,100) p2 opl (0,0) (200, 0)Explanation / Answer
Program:
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include <iostream>
using namespace std;
int check_point(int x,int y)
{
if( (y > 0) && (x > 0) && (x + 2*y < 200) )
return 1;
else
return 0;
}
int main()
{
float num1,num2;
cout<<"Enter a point's x- and y-coordinates: ";
cin>>num1>>num2;
if (check_point(num1, num2))
cout<<"The point is inside the triangle";
else
cout<<"The point is outside in the triangle";
}
Output:
Enter a point's x- and y-coordinates: 100.5 50.5
The point is outside in the triangle
Enter a point's x- and y-coordinates: 100.5 25.5
The point is inside the triangle
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.