122: CS2 --- Assignment 3

Due Monday, May 8

Problem Description: There has been an explosion of interest in computer networks. Simulating a dynamically changing network is an important research area. This project involves working with representations of dynamically changing networks by creating a network class. The network object will be implemented using a 2-dimensional vector or matrix A known as the adjacency matrix of the network. The nodes of the network are labelled 0, 1, ..., n - 1, where n is the total number of nodes. The adjacency matrix is defined by A[i][j] = 1 if there is a link joining nodes i and j and A[i][j] = 0, otherwise. A header file for the class Network has been defined for you. The header file for this class is network.h, and a sample test datafile is sample.dat.

You are to provide the implementation code for the class Network. The class Network has a default constructor that creates an empty network (no nodes) and a specific constructor that creates a network with n nodes, but no links. In addition, the class Network has the following member functions that you will implement.

- bool TestLink(int i, int j)
Returns the value true if, and only if, there is a link joining nodes i and j.

- int NodeSize()
Returns the number of nodes in the network.

- int LinkSize() Returns the number of links in the network.

- void AddLink(int i, int j)
Adds a link joining nodes i and j

- void RemoveLink(int i, int j)
Removes the link joining nodes i and j

- void AddNode()
Adds a single node to the network.

- void RemoveNode(int i)
Removes the node i from the network.

- void Display()
Outputs the adjacency matrix of the network.

You are also to include the following auxilliary functions for operating on sequece objects.

- void ExtractTo(Network &Net, ifstream &NetworkFile)
The file NetworkFile storing the network information is read into the object Net. The file NetworkFile is formatted to contain the integer n in the first position specifying the number of nodes in the network followed by pairs i, j of integers in the range 0,1, ..., n-1 representing the links of the network.

- Overload the insertion operator <<

Your client program will begin by prompting the user for the name of the file where the network data is stored. It should then call the ExtractTo()function to intialize the network object. Following this the program will display the (adjacency matrix of the) initial network using the operator <<. The rest of the program will be menu driven simulation of a dynamically changing network with the following menu:

1. Add a new link
2. Remove a link
3. Add a new node
4. Remove a node
5. Display network
6. Exit program