$29
Task #1
Take the Linked List implementation that you created from Homework #2 and add the following
member functions to create stack functionality:
1) ErrorCode pop(void) - the pop function takes the element off (erases) from the end of the list.
ErrorCode is returned. Error checking is performed for illegal operations.
2) ErrorCode top(ListElement & x) const - the top function places the value of the element at the end of
the list in x. ErrorCode is returned. Error checking is performed for illegal operations.
3) void push(const ListElement x) - the push function places the DataElement x on the end of the list.
You are provided a new StackMain.cpp file which has test cases to pass for these new functions.
You will compile your LinkedLink.cpp and LinkedList.h with the three provided files below.
After executing the program, the results will be output to the Stackresults.txt file in your working directory.
You need to maintain the existing List functionality that was created in Homework #2.
You are encouraged to use the public member functions of the LinkedLink class to implement the
Stack member functions.
Provided files:
StackMain.cpp
MyFileIO.cpp
MyFileIO.h
Submissions for task #1:
LinkedLink.cpp
LinkedList.h
Stackresults.txt
Task#2
Your task is to use a queue as a buffer between a data transmission source and a data receiver.
View the queue-diagram.pttx picture to better understand the problem description.
The data transmission source is implemented with the Sender class.
The data transmission source sends data at a rate of 500 characters per second.
Once a Sender object is created, it will be an open data stream and will attempt to send data at a
rate of 500 characters per second. When the Sender object is finished sending all of its data, the data
stream will be closed. The Sender member function isStreamOpen() gives the status of the data
stream (open or closed). For this assignment, the Sender object is attempting to transmit 131 characters.
The Sender object member function int readFromStream(int arrayLength, char rv[])
is how the data is acquired from the Sender object. If the Sender object has data to transmit,
then the data will be inserted, in order, starting from array index 0 into the rv[] array and
the number of characters sent is returned. If no characters were sent, then the return value is
zero. The caller needs to provide the array rv[] and the array length (arrayLength). The array
needs to be large enough to hold the maximum message length. For this task, make the array 200 characters
in length.
The data receiver is implemented with the Receiver class. The data receiver can receive data at
a rate of 200 characters per second. Once a Receiver object is created, it is able to receive data.
The Receiver object member function int howManyCharToRx() indicates the maximum number
of characters that Receiver object can receive at that time. You cannot send more data than
that number. The Receiver object member function void sendChars(int arrayLength, char x[])
sends the number of characters (specified by arrayLength) that are contained in array x[] to the
Receiver object.
In the main() function, a Sender object (called tx), a Receiver object (called rx) and a queue object
(called q) are created. The code should be added between the comments of "add your code here".
The objective of the software is to transmit the data from the sender to the receiver via a queue
in the fastest amount of time given the data rate constraints of the Sender object and the Receiver
object. The Queue class is provided to you. In the main() function, you should create
a polling loop. This polling loop should check the status of the Sender object to see if the
stream is open and if there are any characters that need to be sent. If characters are retrieved from the
Sender object, then they should be put on the queue. Next, the polling loop should check the status of the
Receiver object to see if characters can be received. If characters can be received and there are
characters on the queue to send, then take the number of allowed characters off the queue and send
them to the Receiver object. The polling loop should be terminated when the Sender class stream is closed
and the queue is empty. Implement your main polling loop in the indicated space in the Main.cpp file.
The results of your data transfer will be contained in the Qresults.txt file in the working directory.
Note, if you send chars to the Receiver object too fast, the chars will be ignored and the transmission
will not be complete. You can only send up to the number of chars the Receiver object is able to accept.
The files that are provided for this task are:
QMain.cpp
Sender.h
Sender.cpp
Receiver.h
Receiver.cpp
Queue.h
Queue.cpp
MyFileIO.h
MyFileIO.cpp
Only add code to the area in the Main.cpp that says "add your code here".
Do not change any interfaces or the code in the files that are provided.
Extra Credit
The maximum queue depth is the largest number of characters that were on the queue at any time
during the transfer process. This number is captured in the Qresults.txt file. Given the data
rates of the Sender and Receiver objects, calculate the theoretical maximum queue depth given
that the software processing in the polling loop has an insignificant contribution to the overall
transfer time. Show your work and compare that to the actual maximum queue depth you obtained
in the Qresults.txt file.
Submissions for task #2:
Main.cpp
Qresults.txt
extracredit.txt (if doing the extra credit, you write this)