Question
C# code that works. Please show the output as well. A system has one and always the same one Graph_Manager object to store graphs with
C# code that works. Please show the output as well.
A system has one and always the same one Graph_Manager object to store graphs with different
IDs and the users can later manipulate any graphs. A 2D graph has an ID and is composed of
vertices and directed edges. A vertex object has three attributes vertex_ID:int, x_coordinate:int,
y_coordinate:int and a drawing method. Similarly, a directed edge has three attributes
edge_ID:int, from_vertex:Vertex, to_vertex:Vertex and a drawing method. A graph object has a
print method to display its result on the screen.
The users can utilize the Graph_Manager to create a blank graph, revise a created graph, or copy
an existing graph. For graph creation, the new graph object is assigned with an incremented ID.
For graph revision, the graph ID is first selected. A new vertex or edge can be added to the graph
by a vertex_ID or edge_ID. Otherwise, a revision may simply update the attribute values of a
vertex or edge according to the specified vertex_ID and edge_ID. For graph copying, the system
will clone a chosen graph entirely together with a copy of its vertices and edges. A different ID
will be assigned to the new graph.
(4 pts) Provide a UML class diagram for your system design. There are four classes that must
exist in the design: Graph_Manager, Graph, Vertex, and Edge. More entities can be added.
Finally, circle and indicate the design patterns that are applied.
(6 pts) Implement the system in C# that allows two users to create a graph with a new ID or
select an existing graph by its ID for doing copy, update, or print simultaneously. Please start up
with two Windows Forms to mimic multiple users. The way to do so is described at this link
https://stackoverflow.com/questions/15300887/run-two-winform-windows-simultaneously. Only
when the print method is called will the chosen graph be displayed. There is no need to draw a
graph in real time after mouse clicks.
The next page shows snippet Java code for drawing a directed edge. Create a JFrame and add in
the code to visualize the result. You will see that a directed edge starts with a black dot and ends
with an arrow. Feel free to take advantage of the code for printing a graph.
public void paint(Graphics g) {
super.paint(g);
int s = 25;
Rectangle r1 = new Rectangle(200, 130, 2 * s, 2 * s);
Rectangle r2 = new Rectangle(100, 330, 2 * s, 2 * s);
g.drawOval(r1.x, r1.y, r1.width, r1.height);
g.drawOval(r2.x, r2.y, r2.width, r2.height);
int v = r1.y > r2.y? -1: 1;
double d = cosine(new Point(r2.x - r1.x, r2.y - r1.y), new Point(v, 0));
double x = r1.x + s + v * s * d;
double y = r1.y + s + v * s * Math.sqrt(1 - d * d);
double x2 = r2.x + s - v * s * d;
double y2 = r2.y + s - v * s * Math.sqrt(1 - d * d);
g.drawLine((int) x, (int) y, (int) x2, (int) y2);
g.fillOval((int) (x - 5), (int) (y - 5), 10, 10);
Point p = compute(new Point(r2.x - r1.x, r2.y - r1.y), Math.PI / 6);
g.drawLine((int) x2, (int) y2, (int) x2 + p.x, (int) y2 + p.y);
p = compute(new Point(r2.x - r1.x, r2.y - r1.y), -Math.PI / 6);
g.drawLine((int) x2, (int) y2, (int) x2 + p.x, (int) y2 + p.y);
}
public double cosine(Point p1, Point p2) {
double d0 = p1.x * p2.x + p1.y * p2.y;
double d1 = Math.sqrt(p1.x * p1.x + p1.y * p1.y);
return d0 / d1;
}
public Point compute(Point p1, double angle) {
double d1 = Math.sqrt(p1.x * p1.x + p1.y * p1.y);
double x = -20 * p1.x / d1;
double y = -20 * p1.y / d1;
double nx = x * Math.cos(angle) - y * Math.sin(angle);
double ny = x * Math.sin(angle) + y * Math.cos(angle);
return new Point((int) nx, (int) ny);
}
Step by Step Solution
3.41 Rating (160 Votes )
There are 3 Steps involved in it
Step: 1
Code snippet graph LR AGraphManager creates manages GGraph G has VVertex G has EEdge V drawing Drawing E drawing Drawing Design patterns applied 1 Sin...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