Question: Questions 5 to 8 will be using the SegmentList and Segment classes shown above. The goal is to use SegmentList, as an alternative to List,
Questions to will be using the SegmentList and Segment classes shown above. The goal is to use SegmentList, as an alternative to List, to create a list of connected points, as seen in Figure The SegmentList default constructor initializes the first segment to the nullptr. The SegmentList parametrized constructor should initialize the first segment. The addNeighbor method is responsible for adding new segments; it should find the last segment, and make its neighbor point to the newly added segment. The draw method should start at the first segment, and draw each of its neighbor segments, with a line connecting all neighbors, as seen in Figure The destructor must release all memory used by the class.
Which code snippet correctly implements the parametrized SegmentList constructor?
A SegmentListfloat x float y first Segmentx y;
B SegmentListfloat x float y first Segmentx y;
c SegmentListfloat x float y first new Segmentxy;
D SegmentListfloat x float y first neighbor new Segment x y;
Which code snippet correctly implements the addNeighbor method?
A void addNeighborfloat x float y first neighbor new Segmentx y;
B void addNeighborfloat x float y while first neighbor nullptr first first neighbor; first neighbor new Segmentx y;
C void addNeighborfloat x float y if first nullptr first new Segmentx y; Segment temp first; while temp neighbor nullptr
temp tempneighbor; temp neighbor new Segmentx y;
D void addNeighborfloat x float y if first nullptr first new Segmentx y; else
Segment temp first; while tempneighbor nullptr temp tempneighbor; tempneighbor new Segmentx y;
Which code snippet correctly implements the draw method?
A void draw firstdraw;
B void draw while first nullptr first draw; first first neighbor;
C void draw Segment temp first; while temp nullptr temp tempneighbor; tempdraw;
D void draw Segment temp first; while temp nullptr tempdraw; temp tempneighbor;
Which code snippet correctly implements the destructor?
A ~ SegmentList delete first;
B ~ SegmentList delete first; delete first neighbor;
C ~ SegmentList while first nullptr delete first neighbor; delete first;
D ~ SegmentList Segment temp first; while temp nullptr delete tempneighbor; delete first;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
