Hi guys,
I need a help on my assignment.
Background
A data transmission system typically breaks a large message into smaller packets. In some
systems, the packets can arrive at the destination computer out of order, so that before the
application requesting the data can process it, the communications program must ensure that
the message is assembled in its proper form.
For this program, the data packets will be read from a file. Each packet will contain the
following fields, separated by colons:
Message ID number. This will always contain either 3 digits or the word END.
Packet sequence number. This will consist of exactly three digits.
Text. No text line will exceed ninety characters. The text may contain any characters,
including colons.
Some examples of packets are:
101:021:"Greetings, earthlings, I have come to rule you!"
232:013:Hello, Mother, I can't talk right now,
101:017:Here is a message from an important visitor:
232:015:I am being harangued by a little green thingy.
END
All packets with a particular ID number belong to a single message. Sequence numbers may
not be contiguous, but the correct ordering for a message will always be in ascending order of
sequence numbers.
To simplify the task, it can be assumed:
All messages will be complete: each message will have at least one data packet.
Each packet will have a unique sequence number: a sequence number will not be used
again for a subsequent packet.
The END packet will always be the last packet received: this means you do not have to
know the number of packets in a message, or wait for pending packets once an END
packet has arrived.
All message IDs and sequence numbers will be correct: you do not have to check
messages for valid characters, etc.
Packets will be contained in a file. Each line of the file will contain one packet, but as
indicated above, the packets will be in random order (except for the END packet). There
will be no blank lines.
Program Action
1. Your program will get the name of the file containing the packets as a command line
argument.
2. It will then read the file and build up all the messages in a linked list of linked lists using
the fgets function. For each message ID, you should maintain a linked list of packets
received, and each new packet for the message should be inserted into the linked list in
the correct place, so the list is always correctly sorted.
3. When the END packet is received, all the messages should be printed, one packet to a
line, in correct order, with a header giving the 3 digit message ID. The message ID should
be padded with 0’s if it is numerically less than 100. A blank line will separate out each
message ID.
4. As a final step, the program should then correctly free up all the memory used in the
linked lists.
For example, the output of the message above would look like
Message 101
Here is a message from an important visitor:
"Greetings, earthlings, I have come to rule you!"
Message 232
Hello, Mother, I can't talk right now,
I am being harangued by a little green thingy.
Those are the requirements of what the program should do...
#include <iostream>
#include <list>
#include <ctype.h>
using namespace std;
void printList(const list<char> &myList);
void fillList(list<char> &myList, const string &vowels);
void changeCase(list <char> &myList);
int main (int argc, char *argv[])
{
string vowels = "aeiou";
list<char> myList;
fillList(myList, vowels);
printList(myList);
changeCase(myList);
printList(myList);
return 0;
}
void printList(const list<char> &myList)
{
list<char>::const_iterator itr;
for (itr = myList.begin(); itr != myList.end(); itr++ ) {
cout << ' ' << *itr;
}
cout << '\n';
}
void fillList(list<char> &myList, const string &vowels)
{
for (int i = 0; i<vowels.length(); i++) {
myList.push_back(vowels[i]);
}
}
void changeCase(list <char> &myList)
{
list<char>::iterator itr;
for (itr = myList.begin(); itr != myList.end(); itr++ ) {
if (islower(*itr)) *itr = toupper(*itr);
else *itr = toupper(*itr);
}
}
Above is the template/skeleton given by professor.
Eventually, the changeCase function need to be changed since it's only an example.
I understand this step:
1. Your program will get the name of the file containing the packets as a command line argument.
But now I'm stuck with:
2. It will then read the file and build up all the messages in a linked list of linked lists using
the fgets function. For each message ID, you should maintain a linked list of packets
received, and each new packet for the message should be inserted into the linked list in
the correct place, so the list is always correctly sorted.
i'm confused, how to build up message in linked list of linked list?
Professor said, there will be at least 2 classes: one class for message and another one for packets.
What does these classes do actually? are they linked list class? and how to structure the classes?