Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have previously posted a question in chegg which is as follows Create an overloaded function that computes the distance between 2, 3, 4 or

I have previously posted a question in chegg which is as follows

Create an overloaded function that computes the distance between 2, 3, 4 or 5 points

class XYPoint {

public:

int x;

int y;

XYPoint(int xc, int yc) : x(xc), y(yc) {}

};

float distance(XYPoint p1, XYPoint p2);

...

float distance(XYPoint p1, ...XYPoint p5);

distance is computes as two-d distance between points and added : distance{p1-p2} + distance{p2-p3} + distance{p3-p4}

This program is to be written in c++ using different a file for header, a file for implementation and other file for main.

Should be compiled in g++ in terminal in an ubuntu system

The expert answer given to this was:

#ifndef XYPOINT_H #define XYPOINT_H

class XYPoint { public: XYPoint(int xc, int yc); float distance(XYPoint p1, XYPoint p2); float distance(XYPoint p1,XYPoint p2,XYPoint p3,XYPoint p4, XYPoint p5); private: int x; int y; };

#endif

==========================================================

#include "XYPoint.h" #include

XYPoint::XYPoint(int xc, int yc) :x(xc), y(yc){} float XYPoint::distance(XYPoint p1, XYPoint p2){ double squareSum = pow(p1.x - p2.x,2) + pow(p1.y - p2.y, 2); double d = sqrt(squareSum); return d; } float XYPoint::distance(XYPoint p1,XYPoint p2,XYPoint p3,XYPoint p4, XYPoint p5){ return distance(p1,p2) + distance(p2,p3) + distance(p3,p4) + distance(p4,p5); }

==========================================================

#include #include "XYPoint.h"

using namespace std;

int main(){ XYPoint p(0,0); XYPoint p1 (1,1); XYPoint p2 (2,2); XYPoint p3 (3,3); XYPoint p4 (4,4); XYPoint p5 (5,5); double distance = p.distance(p1,p2,p3,p4,p5); cout<<"p1 p2 distance: " <

I need the g++ commands using which this was compiled. Because when i am trying to compile the same, it is throwing a lot of errors

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

Write short notes on Interviews.

Answered: 1 week ago

Question

Define induction and what are its objectives ?

Answered: 1 week ago

Question

Discuss the techniques of job analysis.

Answered: 1 week ago

Question

How do we do subnetting in IPv6?Explain with a suitable example.

Answered: 1 week ago

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago