Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include using namespace std; struct Point { double x; double y; }; struct LineSeg { Point s; Point e; }; double segLength(LineSeg l) {

#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); }

This is a question I got for my object oriented programming, any help would be appreciated, thank you

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

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago