Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This code is from Project two #include<iostream> #include<queue> #include \"Pack

ID: 3719527 • Letter: T

Question

This code is from Project two

#include<iostream>
#include<queue>

#include "Packet.h"
using namespace std;

class NetworkObject

//beginning Network Object class definition

{

public:

//Constructor

NetworkObject(int objId): packets(),objectId(objId){

//Parameterized constructor

NetworkObject();

//push packet into the queue that belong to one particular NetworkObject
void setPacket(Packet *pckt)
{
packets.push(pckt);
}

//pop packet one by one that belongs one particular NetworkObject
Packet *popPacket()
{
Packet *pkt;
pkt = packets.front();
packets.pop();
return pkt;
}

//retrieve all the packets of a particular NetworkObject
void getPacketInfo()
{
Packet *pkt;
while(!packets.empty())
{
pkt = popPacket();
cout <<" Packets from source "<<pkt->getSourceID()<< " to destination "<<pkt->getTargetID() <<" with data "<<pkt->getData();
}
}

//returns objectId

int getObjectId(){

return objectId;

}

private:

//private member

int objectId;
queue<Packet*> packets; //packets variable to store the packets in an queue
};

//server class constructor is called from networkobject class parameterized constructor

class Server : public NetworkObject

{

public:

Server(int objId): NetworkObject(objId){}

};

int main()

{

  

//declare 6 NetworkObjects with id 4,8,16, 32, 64, 128.

NetworkObject at[6] = {{4}, {8}, {16}, {32}, {64}, {128}};

//Instantiate two objects of type Packet
Packet *pckt1 = new Packet(8,4,"8 to 4");
Packet *pckt2 = new Packet(8,5,"8 to 5");

//push the above created packets in the queue
at[1].setPacket(pckt1);
at[1].setPacket(pckt2);

for(int i=0; i<6;i++)

{

//prints the object IDs of the network objects along with packet information

cout << " Object ID of Network Object: "<< at[i].getObjectId() << endl;
at[i].getPacketInfo();
  
}

}

And this code is from project Three

#include<iostream>

#include<queue>

#include "Packet.h"

using namespace std;

class NetworkObject

//beginning Network Object class definition

{

public:

//Constructor

NetworkObject(int objId): packets(),objectId(objId){

//Parameterized constructor

NetworkObject();

//push packet into the queue that belong to one particular NetworkObject

void setPacket(Packet *pckt)

{

packets.push(pckt);

}

//pop packet one by one that belongs one particular NetworkObject

Packet *popPacket()

{

Packet *pkt;

pkt = packets.front();

packets.pop();

return pkt;

}

//retrieve all the packets of a particular NetworkObject

void getPacketInfo()

{

Packet *pkt;

while(!packets.empty())

{

pkt = popPacket();

cout <<" Packets from source "<<pkt->getSourceID()<< " to destination "<<pkt->getTargetID() <<" with data "<<pkt->getData();

}

}

//returns objectId

int getObjectId(){

return objectId;

}

private:

//private member

int objectId;

queue<Packet*> packets; //packets variable to store the packets in an queue

};

//server class constructor is called from networkobject class parameterized constructor

class Server : public NetworkObject

{

public:

Server(int objId): NetworkObject(objId){}

};

int main()

{

//declare 6 NetworkObjects with id 4,8,16, 32, 64, 128.

NetworkObject at[6] = {{4}, {8}, {16}, {32}, {64}, {128}};

//Instantiate two objects of type Packet

Packet *pckt1 = new Packet(8,4,"8 to 4");

Packet *pckt2 = new Packet(8,5,"8 to 5");

//push the above created packets in the queue

at[1].setPacket(pckt1);

at[1].setPacket(pckt2);

for(int i=0; i<6;i++)

{

//prints the object IDs of the network objects along with packet information

cout << " Object ID of Network Object: "<< at[i].getObjectId() << endl;

at[i].getPacketInfo();

}

So now I am posting project three question and based from the above code and the question for project three do it my project three but do not do it the same as the code in the above please

Here the question number three you can use it every thing from the above codes but make it totally different in variable and other staff that helps tor run the code but you can use the same function and and other that suppose to be the same in the code

Project 3 Due: April 22, 2018 at 11:55 PM This project concludes the network-oriented series that we began at the start of the semester. Its purpose is to act as a foundation to a simulation you can easily expand upon and add features to, while demonstrating a large number of the concepts we’ve covered so far in the course. FOR 50% EXTRA CREDIT ON THIS PROJECT: ?In the last lecture, we discussed the use of the averaging many random trials to determine the expected behavior of a system. In order to do this, we can sample the important variables of the system from a (often uniform) probability distribution for each computation. After each “run” of the system with random values, we can compute the results we’re interested in and take an average. The average results we’re interested in for the extra credit are: 1. Average percentage of packets lost. 2. Average travel time of a packet. Regardless of whether or not you would like to do the extra credit, ?we’ll want to generate the following variables randomly. Where they are generated should be fairly obvious based on what they do. 1. numberOfNodes?: The number of nodes in the linked list (i.e. the number of network objects). 2. probabilityOfPacketLoss?: How often a node will drop a packet 3. maxPackets?: How many packets each NetworkObject can hold. This should be the size of your packets? Queue. For simplicity, this value can apply to all NetworkObject nodes, rather than generating a different value for each node. For your own practice, you might try doing this anyway. For simplicity in this project, we will hold the packet source and target fixed at the beginning and end of the linked list. The modifications for this project can take place in main() and whatever helper functions you see fit to create. However, the following additions must be made to the NetworkObject class: NetworkObject 1. Define the randomly generated integer “maxPackets?” 2. Define a function addPackets?, which adds an array of packet objects to the packets? queue. 3. Define a function getPackets?, which returns a number n ?packets from the packets? queue. The packet objects should obviously be removed from the queue, then returned. 4. Define a function update, ?which removes as many packets as possible, up to the “maxPackets?” value, and adds them to the “packets?” queue in the next node. For each packet, use the “probabilityOfPacketLoss”? variable to determine if a packet should be added to the next NetworkObject, or simply removed. Keep count of how many packets are dropped?. This will be important later. Note: ?There are a few things to consider here: a. There may not be a next node. In that case, the packets should just be removed from the queue. b. Do you want to compute travel time in this function when there is no next node? c. The nextNetworkObject may not be able to accept all of those packets! Only remove the packets that can be added successfully to the nextNetworkObject’s queue. Main 1. Define a random number of NetworkObjects and link them together in a Linked List as we’ve been doing in the previous projects. 2. Loop over the following operations a large number of times (e.g. 1,000 times): a. Add a random number of packet objects to the first? NetworkObject. Keep a running total of this number. b. Call the update() ?function on every? NetworkObject in the linked list. 3. When the loop is done, output the following: a. How many nodes were in the linked list b. How many packets traveled through the system c. How many packets were lost. This can be expressed as a percentage by dividing the total number of packets lost by the total number of packets created, and multiplying by 100. 4. For the extra credit, perform steps 1, 2, and 3 a large number of times, and output the average of the results above.

Explanation / Answer

#include<iostream>
#include<queue>

#include "Packet.h"
using namespace std;

class NetworkObject

//beginning Network Object class definition

{

public:

//Constructor

NetworkObject(int objId): packets(),objectId(objId){

}

//Parameterized constructor

NetworkObject();

//push packet into the queue that belong to one particular NetworkObject
void setPacket(Packet *pckt)
{
packets.push(pckt);
}

//pop packet one by one that belongs one particular NetworkObject
Packet *popPacket()
{
Packet *pkt;
pkt = packets.front();
packets.pop();
return pkt;
}

//retrieve all the packets of a particular NetworkObject
void getPacketInfo()
{
Packet *pkt;
while(!packets.empty())
{
pkt = popPacket();
cout <<" Packets from source "<<pkt->getSourceID()<< " to destination "<<pkt->getTargetID() <<" with data "<<pkt->getData();
}
}

//returns objectId

int getObjectId(){

return objectId;

}

private:

//private member

int objectId;
queue<Packet*> packets; //packets variable to store the packets in an queue
};

//server class constructor is called from networkobject class parameterized constructor

class Server : public NetworkObject

{

public:

Server(int objId): NetworkObject(objId){}

};

int main()

{

  

//declare 6 NetworkObjects with id 4,8,16, 32, 64, 128.

NetworkObject at[6] = {{4}, {8}, {16}, {32}, {64}, {128}};

//Instantiate two objects of type Packet
Packet *pckt1 = new Packet(8,4,"8 to 4");
Packet *pckt2 = new Packet(8,5,"8 to 5");

//push the above created packets in the queue
at[1].setPacket(pckt1);
at[1].setPacket(pckt2);

for(int i=0; i<6;i++)

{

//prints the object IDs of the network objects along with packet information

cout << " Object ID of Network Object: "<< at[i].getObjectId() << endl;
at[i].getPacketInfo();
  
}

}

-----------------------------

Packet.h

#include <string>
using namespace std;
class Packet
{
public:
//constructor
Packet(int srcId, int trgId, string dt);
// set method for sourceid
void setSourceID(int srcID);
// get method for sourceid
int getSourceID();
// set method for targetid
void setTargetID(int trgID);
// get method for targetid
int getTargetID();
// set method for data
void setData(string dt);
// get method for data
string getData();

private:
int targetID;
int sourceID;
string data;
};

------------------------------

Packet.cpp

#include "Packet.h"

//constructor to initialize member variables
  
Packet::Packet(int srcId, int trgId, string dt)
{
sourceID = srcId;
targetID = trgId;
data = dt;
}

//set method for sourceID
void Packet::setSourceID(int srcID)
{
sourceID = srcID;   
}

//get method for sourceID
int Packet::getSourceID()
{
return sourceID;
}

//set method for targetID
void Packet::setTargetID(int trgID)
{
targetID = trgID;
}

//get method for targetID
int Packet::getTargetID()
{
return targetID;
}

//set method for data
void Packet::setData(string dt)
{
data = dt;
}

//get method for data
string Packet::getData()
{
return data;
}

-----------------

Output

Object ID of Network Object: 4                                                                                                   

                                                                                                                                 

Object ID of Network Object: 8                                                                                                   

                                                                                                                                 

Packets from source 8 to destination 4 with data 8 to 4                                                                             

Packets from source 8 to destination 5 with data 8 to 5                                                                             

Object ID of Network Object: 16                                                                                                  

                                                                                                                                 

Object ID of Network Object: 32                                                                                                  

                                                                                                                                 

Object ID of Network Object: 64                                                                                                  

                                                                                                                                 

Object ID of Network Object: 128