// ====================================================================================
// ========== package definition and function prototypes ==============================
// ====================================================================================
struct Package {
string sender;
string recipient;
string content;
string address;
float value;
};
// note that p is now a pointer to a package
void fillPkg(Package *p);
// note that p is now a pointer to a package
void printPkg(Package *p);
// ====================================================================================
// ========== queue definition and function prototypes ================================
// ====================================================================================
const int MaxPackages = 4;
struct Queue {
Package* pkgArray[MaxPackages]; // now this is an array of pointers for packages
int front;
int back;
int size;
};
void initQ(Queue &q);
int getSizeQ(Queue q);
// note the package parameter is now a pointer to a package
bool insertQ(Package *p, Queue &q);
// note the package parameter is now a pointer, passed by reference
bool removeQ(Package* &p, Queue &q);
void printQ(Queue q);
// ====================================================================================
// ========== command-handling definitions and function prototypes ====================
// ====================================================================================
const char Help = 'H';
const char Quit = 'Q';
const char Insert = 'I';
const char Remove = 'R';
const char Size = 'S';
const char Print = 'P';
const char Error = 'E';
void commandHelp();
char getCommand();
void processCommand(char command, Queue &Q);
// ====================================================================================
// ========== main routine ==========================================================
// ====================================================================================
int main()
{
// no changes needed from lab6.cpp
}
// ====================================================================================
// ========== command-handling function implementations ===============================
// ====================================================================================
void commandHelp()
{
// no changes needed from lab6.cpp
}
char getCommand()
{
// no changes needed from lab6.cpp
}
void processCommand(char command, Queue &Q)
{
// three changes needed:
// 1. pkg declaration now needs to use *pkg, so it's a pointer
// 2. before we actually call fillPkg during the insert
// we need to allocate memory for a new package, e.g.
// pkg = new Package
// 3. after we've printed the package content in a successful remove
// we need to deallocate the package's memory, e.g.
// delete pkg
}
// ====================================================================================
// ========== package function implementations ======================================
// ====================================================================================
float getValue()
{
// no changes needed from lab6.cpp
}
void fillPkg(Package *p)
{
// like fillPkg from lab6.cpp, but
// 1. print an error message and return if p == nullptr
// 2. we use p-> instead of p.
}
void printPkg(Package *p)
{
// like fillPkg from lab6.cpp, but
// 1. print an error message and return if p == nullptr
// 2. we use p-> instead of p.
}
// ====================================================================================
// ========== queue function implementations ========================================
// ====================================================================================
void initQ(Queue &q)
{
// no changes needed from lab6.cpp
}
int getSizeQ(Queue q)
{
// no changes needed from lab6.cpp
}
bool insertQ(Package *p, Queue &q)
{
// no changes needed from lab6.cpp
return true;
}
bool removeQ(Package* &p, Queue &q)
{
// no changes needed from lab6.cpp
return true;
}
void printQ(Queue q)
{
// no changes needed from lab6.cpp
}
|