Question: Write a method called stackSum that returns an int and has no parameters which will find the sum of a stack using a recursive technique

Write a method called stackSum that returns an int and has no parameters which will find the sum of a stack using a recursive technique and leave the stack unchanged. Test the method in a driver program with the following items pushed onto a stack in the following hardcoded order: -6, 4, 2, 10, 8. The output of the program should display the sum in a message to the console. Assume the method is a member of a linked stack class called LinkedStack that has a private data member: top, and methods: getInfo() and getLink(). The data member top is of type: LSNode (linked stack node), and each LSNode has data members: info and link.

Must include the following:

Create the basic template common to all C++ programs.

Give the correct signature for the specified method/function.

Access the calling objects stack.

Effectively accesses the data members and methods.

Implement a base case and recursive case in the solution.

Effectively return the correct sum of a stack using recursion.

Leave the calling objects stack unchanged.

Test the recursive function/method using a main driver.

Check the program for errors and omissions and debug.

Successfully execute the file with the appropriate output to the console.

C++

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!