Complete the function that computes the length of a path that starts with the given Point. The Point structure = point on the plane that is a part of a path. The structure includes a pointer to the next point on the path, or nullptr if it's the last point.   I'm not sure how to fill in the '?'; especially the while loop I'm not sure how to implement the condition for that.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Complete the function that computes the length of a path that starts with the given Point. The Point structure = point on the plane that is a part of a path. The structure includes a pointer to the next point on the path, or nullptr if it's the last point.  

I'm not sure how to fill in the '?'; especially the while loop I'm not sure how to implement the condition for that.
pathlength.cpp
1 #include "point.h"
2 #include <cmath> // need sqrt, pow
3 using namespace std;
4
double pathLength(Point* first)
6 {
double result{0.0};
Point* p{first)};
while (?)
7
8
9
10
{
Point* q = ?;
if (?)
{
result = result + sqrt(pow(?, 2) + pow(7), 2));
}
11
12
13
14
15
16
p = q;
17
18
19
20
return result;
21 }
point.h
1
#ifndef POINTH
2
#define POINT_H
3
4
struct Point
5 {
double x;
double y;
6.
7
8
Point * next;
9.
};
10
11
double pathLength(Point* list);
12
13
#endif
Transcribed Image Text:pathlength.cpp 1 #include "point.h" 2 #include <cmath> // need sqrt, pow 3 using namespace std; 4 double pathLength(Point* first) 6 { double result{0.0}; Point* p{first)}; while (?) 7 8 9 10 { Point* q = ?; if (?) { result = result + sqrt(pow(?, 2) + pow(7), 2)); } 11 12 13 14 15 16 p = q; 17 18 19 20 return result; 21 } point.h 1 #ifndef POINTH 2 #define POINT_H 3 4 struct Point 5 { double x; double y; 6. 7 8 Point * next; 9. }; 10 11 double pathLength(Point* list); 12 13 #endif
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY