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

Can I get help with code? I need it in C++ not java. Due 3/10/18 at 11:55pm! Her

ID: 3727376 • Letter: C

Question

Can I get help with code? I need it in C++ not java. Due 3/10/18 at 11:55pm! Here's my code from project 1:

#include "stdafx.h"
#include<iostream>
using namespace std;
class NetworkObject
{
private:
int objectId;   //private member
public:
NetworkObject(int oid) : objectId(oid) {}   //constructor
int getObjectId()    
{
  return objectId; //returns objectId
}
};
class Server : public NetworkObject       
{
public:
Server(int oid) : NetworkObject(oid) {}
};
int main()
{
NetworkObject a[4] = { { 1 },{ 2 },{ 3 },{ 4 } };     //declare 4 NetworkObjects with id 1,2,3,4
for (int i = 0; i < 4; i++)
{                                                                            
  std::cout << "Object ID of Network Object #%d: %d " << i + 1 << a[i].getObjectId(); //prints the object IDs of the 4 objects
}
return 0;
}
//end code

In Project 1 we laid the foundation of what will become a simple network packet transmission simulation. This project will build upon this foundation, utilizing a queue structure to store atomic packets of data which will travel across the network. The advantage of a queue is that, once a routing system is constructed in Project 3, latency will naturally be minimized as packets are essentially prioritized by wait time. Please construct the following class, defined in a file named Packet.h, and define the function bodies in a separate Packet.cpp file: Packet This class should contain the following private variables. You should define public functions which get and set the values of these variables. • An integer called targetID • An integer called sourceID • A string called data Network Object This class (from Project 1) should be modified to contain a private queue variable called packets. I'm trusting that you will recall the form of a FIFO queue from CSC 220 Data Structures. For those who do not recall, the queue will be an easy subject to Google and learn about.

How you decide to implement the queue is up to you, so long as it functions according to the normal FIFO expectations of a queue and stores packet objects. More accurately, you will find that storing pointers to packet objects will be far superior than the actual packet object. As we discussed in class, the power of the pointer is in its ability to reference large objects in a compact, easily accessed way.
We will use this queue of packets in Project 3 to begin routing packets between network objects and begin to simulate communication between network objects.

Explanation / Answer

-----------------------------packets.h

#ifndef PACKETS_H_INCLUDED
#define PACKETS_H_INCLUDED
#include <string>
#include <iostream>
class Packets
{
int targetID;
int sourceID;
std::string data;
public:
Packets(int targetID, int sourceID,std::string data);
int getTragetID();
int getSourceID();
std::string getData();
};
#endif

------------------------------packets.cpp

#include <iostream>
#include <string>
#include "packets.h"
using namespace std;
Packets::Packets(int targetID, int sourceID,string data)
{
this->targetID=targetID;
this->sourceID=sourceID;
this->data=data;
}
int Packets::getTragetID()
{
return targetID;
}
int Packets:: getSourceID()
{
return sourceID;
}
string Packets::getData()
{
return data;
}

-----------------------------main.cpp
#include<iostream>
#include <queue>
#include "packets.h"
using namespace std;
class NetworkObject
{
private:
int objectId;
queue <Packets> pkt;
public:
NetworkObject(int oid): objectId(oid){}//constructor
NetworkObject()
{

}
void addNetworkObject(Packets p)
{
pkt.push(p);
}
int getObjectId()
{
return objectId;
}
void showq()
{
while (!pkt.empty()) {
cout <<"SourceID :"<<pkt.front().getSourceID() << " TargetID :#" << pkt.front().getTragetID()<<" Data: "<<pkt.front().getData()<< endl;
pkt.pop();
}
}
};

class Server : public NetworkObject
{
public:
Server(int oid): NetworkObject(oid){}
};

int main()
{
NetworkObject a[4] = {{1}, {2}, {3}, {4}};
Packets p1(a[0].getObjectId(),a[1].getObjectId(),"Message1");
Packets p2(a[2].getObjectId(),a[3].getObjectId(),"Message2");
NetworkObject no;
no.addNetworkObject(p1);
no.addNetworkObject(p2);
for(int j=0;j<4;j++)
{
cout<<"Obj_ID for Net Object: "<< j+1<<": "<< a[j].getObjectId()<<" ";
}
no.showq();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote