Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that implements a stack using an array. Your user will decide ho

ID: 3550382 • Letter: W

Question

Write a program that implements a stack using an array. Your user will decide how large an array to create for your stack. The stack will hold only positive integer numbers.

Your program should keep track of the stack's attributes, size and top.
Size is an integer that holds the number of elements currently stored in the stack and top is a pointer that holds the address where the next element in the stack will be added. These attributes can be implemented as global variables eliminating the need to pass their values to your functions.  You can also globally declare a pointer variable that will be used to point to your stack and an int variable to contain its capacity. Initialize the stack pointer value to NULL.
Suggested global variable declarations:
       int * stack - always points to the location of the first element in the stack
       int * top - points to the location where the next element will be stored (push and pop will increment/decrement this address)
       int capacity - the number of elements that can be stored in the stack (user will provide this value, it never changes because you're implementing a static stack)
       int size - the number of elements actually stored in the stack (push and pop will increment/decrement this value)

Present the user with a menu containing the following options: Create, Push, Pop, Count, Display and Exit. Your program should loop continuously until the user chooses Exit.

Two helper functions should also be created that will be used by your push, pop and display functions. They are:

Write a program that implements a stack using an array. Your user will decide how large an array to create for your stack. The stack will hold only positive integer numbers. Your program should keep track of the stack's attributes, size and top. Size is an integer that holds the number of elements currently stored in the stack and top is a pointer that holds the address where the next element in the stack will be added. These attributes can be implemented as global variables eliminating the need to pass their values to your functions. You can also globally declare a pointer variable that will be used to point to your stack and an int variable to contain its capacity. Initialize the stack pointer value to NULL. Suggested global variable declarations: int * stack - always points to the location of the first element in the stack int * top - points to the location where the next element will be stored (push and pop will increment/decrement this address) int capacity - the number of elements that can be stored in the stack (user will provide this value, it never changes because you're implementing a static stack) int size - the number of elements actually stored in the stack (push and pop will increment/decrement this value) Present the user with a menu containing the following options: Create, Push, Pop, Count, Display and Exit. Your program should loop continuously until the user chooses Exit. The Create option prompts the user for the size of the array to create and calls a function that accepts an integer argument and returns a pointer to an array of ints all initialized to -1. This pointer should be assigned to your global stack pointer variable. You do not want to create any memory leaks in your program so before dynamically creating the array, check to see if your stack pointer is NULL (meaning no memory has been allocated yet). If it doesn't, then you should free the memory that the stack pointer currently points to before reassigning it to point to new memory. Notify your users that you are deleting their old stack. The Push option prompts the user for a number to add to the stack and calls a function that accepts an integer argument and pushes it onto the top of the stack. The stack attributes, top and size should also be updated. If the stack is full, no changes should be made to top and size and an error message should display. The Pop option calls a function that prints the last element added to the stack followed by a newline and removes it from the stack by overwriting its value with -1. The stack attributes, top and size should also be updated. If the stack is empty, no changes should be made to top and size and an error message should display. The Count option should display the number of elements currently stored on the stack. The Display option should print the entire stack starting from the top. Each number should be on a separate line followed by a newline. If the stack is empty, then an appropriate message should be printed. Two helper functions should also be created that will be used by your push, pop and display functions. They are: isEmpty(): should return true if the stack is empty and false otherwise. HINT: You've got a global variable that will help determine this isFull(): should return true if the stack is full and false otherwise. HINT:A little pointer arithmetic with your global pointers will solve this one

Explanation / Answer

Hello,I am 14 years experienced Computer Science Tutor and Assignment Helper. I am ready to get your assignment done but you have to pay fee for it. I solve each assignment personally and don't post copied solutions from internet like other experts do. For further discussion email me at nettuitions@hotmail.com or discuss with me in Skype. Skype id is hardeep_sp

Thanks





Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote