Assignment #2

CS 163 Data Structures

Submit your assignment to the D2L Dropbox (sign on via d2l.pdx.edu)

***Assignments in CS163 consists of written homework and programming***

***All parts are required to get a grade on this homework ***

 

HOMEWORK QUESTIONS:

1.      Create an Algorithm to remove the largest item in an un-sorted linear linked list.

 

Algorithms should be written using complete sentences in a way that is easy to follow – consider using outline form. Make sure to desk check the algorithm

 

2.      Definition of Terms. In your own words, define the following terms and provide examples of their use:

 

·         Algorithmic efficiency

·         Prefix vs. Postfix increment

·         Loop Invariant

·         Unit Testing

·         Recursion vs. Iteration

 

3.      Ethics. Part of computer ethics is providing software that is useable and understandable. In our case, we are building ADTs this term for other programmers to use as the foundation for their application development. The reason we build ADTs is that client programs can rely on these abstractions working without having to implement the details. Application programmers can then move on to more important problems.

 

Let’s take a look at D2L. Currently the new release has some bugs. One in particular is with the discussion editing tool (which deletes your text when entering a newline in some cases). It is clear that they did not use an ADT for the editing tool because not all uses demonstrate this same bug (e.g., D2L mail and the dropbox do not exhibit the same problem). Look at D2L and come up with THREE ADTs that should have been created to offload the application programmer from worrying about the details.

 


 

Programming – Problem Statement: Over the break I had to work considerably on rebuilding my email systems, since PSU is no longer supporting Computer Science email. Wouldn’t it be great if we could tailor our mail system to just what we want?  Your job for this second program will be to simulate some basic mail-type functionality using queues and stacks.

 

Think about how your mail is displayed? Usually, I have my mail displayed in the order that it comes in. So, the first message in the mail box is the most recently received and the last message in the mail box is the oldest message received. This sounds similar to a Last-in, First-out concept. The last one in will be the first one that I read, so we will be simulating messages using a stack ADT.

 

But there is additional functionality that would be useful. I enjoy being able to mark message (or flag them) as VIP. The problem is that in my normal mail system they remain Last-in, First-out and soon the flagged messages are lost in a sea of 1000’s of messages. I would prefer to queue up messages marked as important, using a First-in, First-out mechanism so that I make sure to handle all vital messages. These might be messages that require me to do some activity that I don’t want to forget about. We will be using a queue ADT to simulate VIP or flagged messages.

 

Functionality needed:

1.      Receive mail messages (this should push each message)

a.      I recommend reading them from an external data file).

b.      They should at a minimum contain the (a) sender’s name and email, (b) subject, (c) date, and (d) content of the message.

2.      Read a mail message (this should peek or pop the message). Consider having two functions for this – one to read and progress and one to just read.

a.      Both should supply the information about the message back to the calling routine, through the argument. (Refer to Lab3!)

3.      Remove a mail message (this should pop the message)

4.      Flag a message as VIP (this should enqueue the message)

5.      Read and Remove a VIP message (this should peek or dequeue)

6.      Display the contents of all mail messages

7.      Display the contents of all VIP messages

Programming – Data Structures: Your queue must be implemented using a circular linked list. Your queue must implement a dequeue, enqueue, displayall, and peek.

Your stack must be implemented using a linear linked list of arrays. Each element of the array will be an email message. Your stack must implement a push, pop, displayall, and peek.

Please keep in mind that because we are creating ADTs, the user of the program must not be aware that stacks and queues are being used – this is the job of the application program (your test program)! Make sure to thoroughly test each of the stack and queue functions!

 

Things you should know...as part of your program:

1)                  Do not use statically allocated arrays in your classes or structures. All memory must be dynamically allocated and kept to a minimum!

2)                  All data members in a class must be private

3)                  Never perform input operations from your class in CS163

4)                  Global variables are not allowed in CS163

5)   Do not use the String class! (use arrays of characters instead!) You may use the cstring library.

6)   Use modular design, separating the .h files from the .cpp files. Remember, .h files should contain the class header and any necessary prototypes. The .cpp files should contain function definitions. You must have at least 2 .h file and 3 .cpp files. Never "#include" .cpp files!

7)  Use the iostream library for all I/O; do not use stdio.h.

8) Make sure to define a constructor and destructor for your class. Your destructor must deallocate all dynamically allocated memory.

9) Remember that 20% of each program's grade is based on a written discussion of the design. Take a look at the style sheet which gives instruction on the topics that your write-up needs to cover.