Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ programming For two points u and v, the distance d between them is given as follows. d = q (ux ? vx) 2 +

c++ programming

For two points u and v, the distance d between them is given as follows. d = q (ux ? vx) 2 + (uy ? vy) 2 . Write a function distance to calculate the distance between two PointXY objects. double distance(const PointXY &u, const PointXY &v); Write a function area perimeter to calculate the area and perimeter given an input vector of three points. The three points form a triangle. Your function should enable the program below to compile and run correctly. // #include relevant headers using namespace std; // class declaration and functions int main() { int n = 3; vector v(n); // set x,y coordinates double area, perimeter; area_perimeter(v, area, perimeter); // function call area_perimeter(v, area, perimeter); // call twice why not cout << "area = " << area << endl; cout << "perimeter = " << perimeter << endl; return 0; } Write an appropriate signature for the area perimeter function. 1. Declare variables a, b, c and compute the edge lengths of the triangle a = distance(v[0],v[1]), similarly b for (v[1],v[2]) and c for (v[2],v[0]). 2. The perimeter of the triangle is the sum of the edge lengths a + b + c. 3. Define the semi-perimeter as s = perimeter/2.0. 4. The area of the triangle is given by the Herons formula. area = p s(s ? a)(s ? b)(s ? c) .

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

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions