Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a new function to this programme which checks if a given point is on (contained in) a given line segment. #include #include using namespace

Add a new function to this programme which checks if a given point is on (contained in) a given line segment.

#include  #include  using namespace std;
struct Point { double x; double y; }; struct LineSeg { Point s; Point e; };
double segLength(LineSeg l) { return sqrt( pow(l.s.x - l.e.x, 2) + pow(l.s.y - l.e.y, 2) ); }
int main() { Point p1 = { 1, 1 }; Point p2 = { 2, 2 }; LineSeg line = { p1, p2 }; cout << segLength(line) << endl; } 

Add a new function to this programme which checks if a given point is on (contained in) a given line segment. Your function should have the following form:

bool contains(LineSeg l, Point p) { ... }

It should return true if p is contained in l and return false otherwise. Your code should function correctly when called using the following test code:

int main() { Point p1 = { 1, 1 }; Point p2 = { 2, 2 }; LineSeg line = { p1, p2 }; Point p3 = { 1.5, 1.5 }; cout << std::boolalpha << contains(line, p3) << endl; Point p4 = { 1.6, 1.6 }; cout << std::boolalpha << contains(line, p4); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

Students also viewed these Databases questions

Question

Question What happens to my plan if I die?

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago