代写C++代码 代做C++程序 C++辅导 C++教学

C++网络家教 远程写代码 在线Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

 Write C++ code that will convert files into a queue of packets and reassemble a queue of packets back into the original file. Both of these functions will be used in homework 8 where we will simulate sending files through a network as packets and reassembling them at their destinations.




File to Packets (1 point)


queue<Packet> fileToPackets(string filename, int maxPayloadSize);


Implement this function in fileToPackets.cpp which takes a file and max payload and returns a queue of packets containing all the data of the file with no packet containing more than maxPayloadSize number of bytes in its payload which is stored as a vector of chars. Each packet will also store the original filename as well as a sequence number which maintains the order in which the packets will be reassembled.

The packet class is provided in hw7.zip. Refer to the code for further details on the Packet class.



File to Packets Program (1 point)


./a.out inputFilename outputFilename payloadSize


Write a main function in FileToPackets.cpp that will be used with these command line parameters and will save a queue of packets generated from the input file and save it as the output file. To accomplish this you should call the fileToPackets function from the previous part to convert the file to packets, then call the savePackets functions provided in the Packet.cpp/h files which saves the queue to disk.

This part will be checked by running the a.out generated by the following compiler call:

g++ FileToPackets.cpp Packet.cpp



Packets to File (1 point)


vector<char> packetsToFile(queue<Packet> packets);


Implement packetsToFile to reassemble a file from a queue of packets. This is effectively the reverse operation as fileToPackets. You can assume that the packets are all given in sequence and you should combine the payload of each packet into a vector of chars with all the contents of the original file.



Packets to File Program (1 point)


./a.out inputFilename outputFilename


Write a main function in PacketsToFile.cpp that will be used with these command line parameters and will read the input file as a queue of packet using the provided loadPackets functions and reassembles the original file by calling packetsToFile. The reassembled file will be saved as the output file.

This part will be checked by running the a.out generated by the following compiler call:

g++ PacketsToFile.cpp Packet.cpp


To verify that your code is functioning properly you should convert a file to packets by running FileToPackets, then call PacketsToFile and check it the original file was reconstructed.


相关推荐