Chat with us, powered by LiveChat C++ code need | Collepals Essay Writers
Select Page

# C++ code need

c++ exercise and need the explanation and answer to help me learn.

Write a C++ program that reads the Financial Transaction graph , represent it using
adjacency lists and finally print the adjacency list. For this recitation, you are supposed
to create two structures/classes

(1) Edge : All elements or nodes in the adjacency list represent distinct edges.
Each edge object contains three members: the destination vertex, the weight of the
edge and address of the next edge in the linklist. Note, we do not require source
vertex as the edge should be inserted in the linklist corresponding to the source
vertex.
(2) Graph : The graph should contain the number of vertices and an array of linklists.
The length of the array of linklist should be equal to the number of vertices
please see the attached file to understand all
Requirements:
Recitation 5 The objective of this recitation is to read a weighted graph and represent it in form of an Adjacency List.
Imagine you want to model a network of Þnancial transactions between bank accounts. In this network, each account is represented as a vertex, and the Þnancial transactions (money transfers) between accounts are represented as weighted directed edges. The weight on each directed edge can represent the amount of money transferred and the direction of the transaction (e.g., debit).
For example:
¥Vertices (Bank Accounts): A, B, C, D, E  Weighted Directed Edges (Financial Transactions):
¥A to B: \$1,000 (debit from A to B)
¥B to C: \$500 (debit from B to C)
¥C to D: \$300 (debit from C to D)
¥D to E: \$600 (debit from D to E)
¥E to A: \$200 (debit from E to A)
¥E to C: \$400 (debit from E to C)
In this weighted directed graph, the numerical values represent the amount of money transferred, and the direction of the edge indicates the direction of the transaction (e.g., from A to B). This graph can be used to track Þnancial ßows, detect unusual transaction patterns, or analyze the movement of funds within the network.
An adjacency list is a common way to represent a graph data structure. It’s a collection of linklists used to describe which vertices (or nodes) are adjacent to each vertex in a graph. Each vertex in the graph has a list of its neighboring vertices. In the case of a directed graph, each entry in the adjacency list represents outgoing edges from a vertex
Below we represent the above graph in form of an adjacency list.
A : B/1000 Ñ> Null
B : C/500 Ñ> Null
C : D/300 Ñ> Null
D : E/600 Ñ> Null
E : C/400 Ñ> A/200 Ñ> Null

Format of the Graph You are to read in an edge weighted graph G = (V, E, w) from a text Þle named Ôgraph.txtÕ. The format of the input Þle containing the graph is as follows. The Þrst line in the Þle contains two positive integers:
n m
where n is the number of vertices and m is the number of edges.
Each of the next n lines has a string representing the bank account.
Each of the next m lines has three space separated Þelds of the form:

and are two integers in the interval [1, n] denoting the vertices that are the endpoints of the edge, and is a non-negative ßoating point number denoting the edge weight.
You must represent G using adjacency lists (i.e. linklist). Therefore, when you read the value of n, you should initialize an array of pointers of size n for the adjacency list for each vertex. As you read each edge, you should insert it into the appropriate adjacency list, at the front of the list. For a given edge [u, v], the node ÔvÕ is inserted into vertex uÕs adjacency list.
Write a C/C++ program that reads the Financial Transaction graph , represent it using adjacency lists and Þnally print the adjacency list. For this recitation, you are supposed to create two structures/classes
(1)Edge : All elements or nodes in the adjacency list represent distinct edges.  Each edge object contains three members: the destination vertex, the weight of the edge and address of the next edge in the linklist. Note, we do not require source vertex as the edge should be inserted in the linklist corresponding to the source vertex.
(2)Graph : The graph should contain the number of vertices and an array of linklists. The length of the array of linklist should be equal to the number of vertices
Sample input Ñ-> Ôgraph.txtÕ. We have also uploaded Ôgraph.txtÕ in module for reference.
Content of Ôgraph.txtÕ
5 6
A
B

C
D
E
B A 1000
C D 300
B C 500
D E 600
E A 200
E C 400
Expected Output A : Null
B : C/500 Ñ> A/1000 Ñ> Null
C : D/300 Ñ> Null
D : E/600 Ñ> Null
E : C/400 Ñ> A/200 Ñ> Null
Note:
1.You should dynamically allocate memory for edges in the linklist.
2.Do not use vector or arrays to create edges in your adjacency list.