Question: In this problem we are going to implement C modules that implement what is (hopefully) reusable functionality. Each of the modules should make use of
In this problem we are going to implement C modules that implement what is (hopefully) reusable functionality. Each of the modules should make use of abstraction and information hiding where appropriate and include a header file (.h) and a source code file (.c). As discussed in class, the header file should define the API for your module. You may model these modules from the Java versions I reviewed in classonly write them in C. Make use of the static class to control access to variables and functions that you do not want to make visible to clients of your modules. These modules should be standalone, that is, they should not contain a main(). We will write a main() (or two main()s if you want to test the modules separately) to test your modulesbut not until part c. Note: I kept the definition of these modules simple so their functionality will be somewhat limited because you can only have a single stack or a single queue (the array containing the stack or queue is declared inside the module). If youd like to do better check out the Extra Credit at the end of the assignment. a. (15 pts) Code a C module and a header file that encapsulates the functionality of a Stack of doubles using an array of 10 elements. Your stack module should implement these functions as a minimum, but you may expand the API to include additional functionality if youd like. int push(double d) inserts the d onto the stack. Returns 1 if the insertion was successful, 0 otherwise. double pop(void) returns the double on the top of the stack and deletes it from the stack. Returns NaN (https://www.quora.com/What-is-NaN-in-C-programming) if the stack is empty. double peek(void) returns the double on the top of the stack but does not delete it from the stack. Returns NaN if the stack is empty. int isEmpty(void) returns 1 if the stack is empty, 0 otherwise. int isFull(void) returns 1 if the stack is full, 0 otherwise. int listStackContents(void) Displays the contents of the stack on stdout (the console). The entries on the stack should be listed one per line. Does not delete any entries from the stack. Returns the number of entries that were displayed. b. (15 pts) Code a C module and a header file that encapsulates the functionality of a Queue of char. The Queue should be implemented as a circular array of 10 elements. Your Queue module should implement these functions as a minimum, but you may expand the API to include additional functionality if youd like. int enqueue(char d) inserts the char d at the end of the queue. Returns 1 if the insertion was successful (i.e. the Queue was not full), 0 otherwise. char dequeue(void) returns the char on the front of the queue and deletes it from the queue. int isEmpty(void) returns 1 if the queue is empty, 0 otherwise. int isFull(void) returns 1 if the queue is full, 0 otherwise. int listQueueContents(void) Displays the contents of the queue on stdout. The entries on the stack should be listed one per line. Does not delete any entries from the queue. Returns the number of entries that were displayed.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
