Question
Start by defining two structure types, Edge and Graph, in mst.cpp . Be sure to document each. An object of type Edge represents one edge
Start by defining two structure types, Edge and Graph, in mst.cpp. Be sure to document each.
An object of type Edge represents one edge in a graph. It has three fields: two vertex numbers and a weight. Include a parameterless constructor that sets all three fields to 0.
An object of type Graph represents a weighted graph. It has four fields:
the number of vertices in the graph,
the number of edges in the graph,
an array of Edge structures that holds the edges,
the physical size of that array of edges.
Choose clear and sensible names for the fields.
Include a constructor Graph(nv) that yields a graph with nv vertices and no edges. The constructor must create the array of edges.
Since you need to create the array of edges before you know how many edges there are, you will need to set a fixed array size. You can assume that there are no more than 100 edges, but that number must be easy to change. To increase the maximum number of edges to 200, for example, should only require changing only one line of your program. To achieve that, create a named constant that is the maximum number of edges. For example,
const int maxNumEdges = 100;
defines constant maxNumEdges with a value of 100. Any time you need to refer to the maximum number of edges, use maxNumEdges, not 100.
Note. The physical-size field should be set to maxNumEdges by the constructor. When you want to know the size of the array of edges in g, use g.physicalSize (or whatever you have called that field), not maxNumEdges. The reason is that it is is possible that you add another Graph constructor later that creates an array whose size is not maxNumEdges. You would prefer not to be forced to edit the rest of the code when you do that.
Software developers frequently think about doing things in ways that make the software easy to modify later. Mostly, that is the result of having not done it in the past, and having spent long hours changing things that should have been easy to change.
Do not confuse the physical size of the array with the current number of edges. The physical size is the maximum number of edges allowed. The current number of edges might be less than that.
All structure types must be documented by saying
what an object of this structure type represents and
what property of the object each field represents.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started