Question

In: Computer Science

In C++, please build a simple Distance Vector program that will communicate with N partners and...

In C++, please build a simple Distance Vector program that will communicate with N partners and do the following. (NOTE: All connections between a server and clients should be TCP/IP socket.)

  1. You will run N instances on your machine
  2. Each instance will run on a different port (instance 1 will run on port 18181, instance 2 on port 18182, instance 3 on port 18183, etc)
  3. The program will start by reading in the appropriate neighbors file and vector file.
  4. The program will ONLY read vectors where the fromNode is equal to that node. For instance, node 1 will only read in vectors where node1 is the fromNode.
  5. The program will support the following requests from clients:
    1. Show files at the server’s current directory: ‘print
      1. This will print the current vector table on a node.
      2. ONLY print valid vectors (don’t print uninitialized ones)
    2. Download files: ‘refresh
      1. This will force the current node to send its vector table to all its neighbors.
    3. Upload files: ‘update
  1. This will be of the form: Update fromNode toNode cost
  2. Update checks that the toNode is the current node. If it is not it is ignored
  3. Update then checks if the toNode-fromNode exists in vector table. If it does not it is added and neighbors are notified
  4. If the pair is in the table, and if the new cost is less than the old cost, that cost is stored and the neighbors are notified.

Solutions

Expert Solution

#include<stdio.h>

#include<iostream.h>

Using namespace std;

Struct node

{

unsigned dist[6];

unsigned from[6];

}

DVR[10];

int main()

{

cout<<"\n\n-------------------- Distance Vector Routing Algorithm----------- ";

int costmat[6][6];

int nodes, i, j, k;

cout<<"\n\n Enter the number of nodes : ";

cin>>nodes; //Enter the nodes

cout<<"\n Enter the cost matrix : \n" ;

for(i = 0; i < nodes; i++)

{

for(j = 0; j < nodes; j++)

{

cin>>costmat[i][j];

costmat[i][i] = 0;

DVR[i].dist[j] = costmat[i][j]; //initialise the distance equal to cost matrix

DVR[i].from[j] = j;

}

}

for(i = 0; i < nodes; i++)

for(j = i+1; j < nodes; j++)

for(k = 0; k < nodes; k++)

if(DVR[i].dist[j] > costmat[i][k] + DVR[k].dist[j])

{ //We calculate the minimum distance

DVR[i].dist[j] = DVR[i].dist[k] + DVR[k].dist[j];

DVR[j].dist[i] = DVR[i].dist[j];

DVR[i].from[j] = k;

DVR[j].from[i] = k;

}

for(i = 0; i < nodes; i++)

{

cout<<"\n\n For router: "<<i+1;

for(j = 0; j < nodes; j++)

cout<<"\t\n node "<<j+1<<" via "<<DVR[i].from[j]+1<<" Distance "<<DVR[i].dist[j];

}

cout<<" \n\n ";

return 0;

}


Related Solutions

write a simple program to explain vector type in c++... use comments to explain plz
write a simple program to explain vector type in c++... use comments to explain plz
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem you will take a list of names from the user and sort them alphabetically using selection sort. The code for selection sort for integer is available in the "Lab and Weekly Coding Solution module" in webcourses. Ask the user how many names the user wants to input. Let's say the number be N. Then take N number of names and put them in an...
C++ program, I'm a beginner so please make sure keep it simple Write a program to...
C++ program, I'm a beginner so please make sure keep it simple Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File.txt: Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets...
USE C++ and please keep program as simple as possible and also comment so it is...
USE C++ and please keep program as simple as possible and also comment so it is easy to understad Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the...
In c++, please make it short and simple A hotel chain needs a program which will...
In c++, please make it short and simple A hotel chain needs a program which will produce statistics for the hotels it owns. Write a program which displays the occupancy rate and other statistics for any of the chain’s large hotels (all are 20 floors with 16 rooms each floor). In main: -declare a 20 X 16 array of “int” named hotel to represent a hotel’s 20 floors and 16 rooms per floor. Then in main, repeatedly: -call a function...
Simple code please thats easy to follow. C++ Write a program that can be used to...
Simple code please thats easy to follow. C++ Write a program that can be used to compare Insertion Sort, Merge Sort and Quick Sort. Program must: Read an array size from the user, dynamically an array of that size, and fill the array with random numbers Sort the array with the Insertion Sort, MergeSort and QuickSort algorithms studied in class, doing a time-stamp on each sort. Use your program to measure and record the time needed to sort random arrays...
A program written in C that asks for the distance to be entered and then prints...
A program written in C that asks for the distance to be entered and then prints the fare A transportation company has the following rates For the first 100 miles                                                       20 cents a mile For the next 100 miles                                                       a) + 10 cents per mile over 100 miles For the next 100 miles                                                       b) + 8 cents per mile over 200 miles more than 300 miles                                                          c) + 5 cents per mile over 300 miles Write a program that asks...
PROGRAM IN C++ The distance a vehicle travels can be calculated using the following equation: distance...
PROGRAM IN C++ The distance a vehicle travels can be calculated using the following equation: distance = speed * time For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120 miles. Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. The program should then use a loop to display the distance the vehicle has traveled for each...
PROGRAM LANGUAGE IN C NOT C# or C++ KEEP IT SIMPLE EVEN IF IT IS REDUNDANT...
PROGRAM LANGUAGE IN C NOT C# or C++ KEEP IT SIMPLE EVEN IF IT IS REDUNDANT PLEASE. Problem: Driving Function driving(): Write a function driving(), that updates the odometer and fuel gauge of a car. The function will take in a reference to the variables storing the odometer and fuel gauge readings, along with a double representing the miles per gallon (mpg) the car gets and the number of miles the driver intends to go. The function should update the...
Write a program in C or C++ that takes a number series of size n (n...
Write a program in C or C++ that takes a number series of size n (n integers) as input from the user, push all the numbers to the stack, and reverse the stack using recursion. Please note that this is not simply popping and printing the numbers, but the program should manipulate the stack to have the numbers stored in reverse order. In addition to the provided header file, the students can use the following function to print the content...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT