c++help please help requirement: FOR 50% EXTRA CREDIT ON THIS PROJECT: ?

c++help please help


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:


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.


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.

here is the previous code:

#include <string>

#include <queue>

#include <sstream>

#include <iostream>

using namespace std;

class Packet2{


int targetID;  

int sourceID;

string data_Network_Object;


void setTargetID(int t);

void setSourceID(int s);

void setDateNetworkObject(string d);

int getTargetID();

int getSourceID();

string getDatanetworkObject();


void Packet2::setTargetID(int t){



void Packet2::setSourceID(int s){



void Packet2::setDateNetworkObject(string d){



int Packet2::getTargetID(){

return targetID;


int Packet2::getSourceID(){

return sourceID;


string Packet2::getDatanetworkObject(){

return data_Network_Object;


//Server class is being derived from NetworkObject.

class NetworkObject{


NetworkObject(int objectId){this->objectId = objectId;}


int getObjectId(){return objectId;}

queue <Packet2*> getPacketQueue(){ return packets;}


int objectId;

queue <Packet2*> packets;


int main()


//declare 10 NetworkObjects with id 1,2,3,4,5,6,7,8,9.

NetworkObject objects1[10];

for(int i = 0; i <10 ; i++) {

objects1[i] = i;

cout << “objectId: ” << objects1[i].getObjectId()<< endl;


stringstream ss;

queue <Packet2*> q=objects1[0].getPacketQueue();

for(int i=1;i<=6;i++){

Packet2* p1=new Packet2();



int val=objects1[0].getObjectId();

ss << val;




cout<<“The size of queue is “<<q.size()<<endl;


cout<<“Removing packet with targetID and sourceID as : “<<(q.front())->getTargetID()<<” “<<(q.front())->getSourceID()<<endl;



return 0;


Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount

Similar Posts