Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write cpp and h file only, do not write main.cpp file. and your header file should exactly same with I provide below Graphs Yeah! Since

Write cpp and h file only, do not write main.cpp file. and your header file should exactly same with I provide below

Graphs

Yeah! Since this is the lastest quest of this level, it is also gonna be the funnest quest.

You get to implement a simple Graph data structure with a WHOLE LOT OF freedom around how you do it.

All you have to do in this quest is to make various shapes. I don't care how you make them as long as you make them correctly.

Pick and choose. Each shape is worth a certain number of rewards. Generally, the simpler ones are also cheaper and easier to get.

But before you get to it, here's the representation I'll be looking for:

// header fileclass Graph {protected: struct Edge { int _dst; std::string _tag; Edge(int dst = -1, std::string tag = "") : _dst(dst), _tag(tag) {} }; std::vector<:vector> > _nodes; // Suggested private helpers. Not tested. void add_edge(int src, int dst, std::string tag); std::string to_string() const;public: void make_silly_snake(); void make_mr_sticky(); void make_driftin_dragonfly(); void make_slinky_star(); void make_kathy_da_grate(); void make_dodos_in_space(); void make_purty_pitcher(); friend class Tests; // Don't remove this line.};

We're keeping everything as simple as possible so you can focus on your visual art in this quest. Our Graph nodes only have numbers, not names. Edges from one node to another may have optional string tags you can stick on them.

This lets us model the graph as a collection of nodes which each contain a collection of edges.

This is it:

std::vector<:vector> > g;

where the entire graph is simply the collection of nodes, called g above. In this case, we're using vectors for collections.

Important: The graph is NOT a 2D matrix. It is a vector of nodes, where each node contains a vector of edges. Nodes that don't have edges leaving them will be represented by the cells that hold empty vectors. Put another way, the edge from node A to node B can be found in the vector

located at g[A]. But that edge is NOT g[A][B]. Instead you must scan this inner vector to find the edge with the destination of interest.

If you think about it, the Edge object is already an added level of complexity that serves only a cosmetic purpose. We could have made the inner vector a vector of ints, where the ints stand for the destination nodes, and thereby kept things much simpler (We'd still get our shapes).

The reason I have it is to give me a way to stick a label on each edge. I thought it'd be cool. I'll revisit this decision later. For now, it's needed to pass this quest.

Note the golden comment in the starter code. The suggested helper methods are NOT tested. The only methods you need to implement are the public ones, described below in the miniquests. Feel free to implement or not implement the suggested helpers, or implement as many more as you want.

The only thing the miniquests will be looking for is whether your Graph object looks like what it's looking for (in hyper-space, of course. No serialization required).

See I told you it's gonna be fun.

Your first optional miniquest - The Silly Snake

Implement:

void Graph::make_silly_snake();

When invoked, it should clear itself and be reborn as a silly snake. See Figure 1.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
\f\f\f\f\fFigure 6: Dodos in space (Warning: Only a representation of reality. Verify your own numbering) \f\f3 you-saw-me 4 1-be once-like 2 the-silly-snake 5 kekule 1 oes-1 0Drop your0 5 4 1 3 O 2\f10 front-left 9 and-left dis-be-me 11 4 back 0 dis-be-me-head 1 me dis-be-me be-dis 3 5 12 be-dis long-tall 2 front-right op your depress 6 be-dis me-right 8 back 74 Slinky-Star Slinky-Star 0 3 Slinky-Star Slinky-Star Slinky-Star 1 210 2 9 8 6 7 5 0 11 13 3 12 14 Drop your And press 4\f6 7 8 5 O 2 3 9 4 10 17 op your 13 12 press this 14Your Quest Code Yippee-Dodo-5 Now Questing: just simply bee 37 81-opog-2 11 3 23 Yippee-Dodo-11 22 Yippee-Dodo-1 2 Yippee-Dodo-7 15 14 44 Yippee-Dodo-22 45 46 Yippee-Dodo-23 Drop your files 24 47 And press this butt 27 Yippee-Dodo-12 26 Yippee-Dodo-13 25Your Quest Co 38 36 Questing: just simply bee Yippee-Dodo-#38 26 39 Yippee-Dodo-#2 27 9 Ippee-Dodo-#36 Yippee-Dodo-#8 37 8 0 Yippee-Dodo-#0 3 Yippee-Dodo-#2 2 6 Drop your here Yippee-Dodo-#o And 29 11 28 Yippee-Dodo-#2 button Yippee-Dodo-#10 10You Quest Code 11 ow Questing: just simply bee 56 pentagon pentagon 33 O 12 57 uobowed pentagon pentagon 32 pentagon pentagon uoboqued A pentagon 55 34 10 uobowed 1 pentagon 58 pentagon pentagon 13 31 pentagon pentagon 59 pentagon 30 3 14 2 pentagon 40 23 pentagon 35 36 pentagon 20 uoboqued 16 47 pentagon 15 22 pentagon pentagon pentagon ess 42 37 pentagon 39 pentagon pentagon 21 pentagon 38 17 pentagon 19

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions