Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions 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
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY