Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 13PC
Program Plan Intro
Stack Based Fibonacci Function
Program Plan:
- Define the main function.
- Include required header files.
- Prompt user to enter a positive integer till which fibonacci series needs to be found.
- Print the Fibonacci series.
- Create a fibonacci function that computes the last term of the fibonacci sequence using stack operations.
- Push the first two terms of the Fibonacci sequence into a stack using the push () operation.
- Push the rest of the terms from 2 till last term into the stack.
- Pop last two elements off the stack using the stack pop() operation.
- The sum of element t1 and t2 is calculated and pushed onto the stack.
- Return element present at top of the stack.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In Go Lang
4. Program stack.
For the following code, answer the following questions. Assume we are putting everything for our function calls on the stack.
· Show what a stack frame/activation record for main() looks like
· Show what the stack frame/activation record for the 2nd call to ctTarg look like? (Yes, this means you can skip the other stack frames)
· We note that targ does not change value in any recursive call. Why doesn't the compiler just store targ once in one block of memory big enough to store a string?
int ctTarg(string* list, int len, string targ) {
if (len <= 0) return 0;
if (*list == targ)
return 1 + ctTarg(list + 1, len - 1, targ);
return ctTarg(list + 1, len - 1, targ);
}
int main()
{
string pets[] = {"cat", "dog", "mouse", "cat"};
cout << ctTarg(pets, 4, "cat") << endl;
}
Write 2 recursive functions
1. to count number of even values in an
array
2. to count number of even values in a
simply linked list
A tail recursion is a type of recursion in which the access of the tail pointer of a linked list is recursive
a) true
b)false
Chapter 18 Solutions
Starting Out with C++: Early Objects
Ch. 18.3 - Describe what LIFO means.Ch. 18.3 - What is the difference between static and dynamic...Ch. 18.3 - What are the two primary stack operations?...Ch. 18.3 - What STL types does the STL stack container adapt?Ch. 18 - Prob. 1RQECh. 18 - Prob. 2RQECh. 18 - What is the difference between a static stack and...Ch. 18 - Prob. 4RQECh. 18 - The STL stack is considered a container adapter....Ch. 18 - What types may the STL stack be based on? By...
Ch. 18 - Prob. 7RQECh. 18 - Prob. 8RQECh. 18 - Prob. 9RQECh. 18 - Prob. 10RQECh. 18 - Prob. 11RQECh. 18 - Prob. 12RQECh. 18 - Prob. 13RQECh. 18 - Prob. 14RQECh. 18 - Prob. 15RQECh. 18 - Prob. 16RQECh. 18 - Prob. 17RQECh. 18 - Prob. 18RQECh. 18 - Prob. 1PCCh. 18 - Prob. 2PCCh. 18 - Prob. 3PCCh. 18 - Prob. 4PCCh. 18 - Prob. 5PCCh. 18 - Prob. 6PCCh. 18 - Prob. 7PCCh. 18 - Prob. 8PCCh. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PC
Knowledge Booster
Similar questions
- Haskarrow_forwardComplete using Standard C programming. Implement a singly linked list that performs the following: Displays the maximum value in the linked list using recursion. Displays the linked list in reverse order using recursion. Merge two single linked lists and display.arrow_forwardalgorithm trace Write a recursive function to find summation of the first n positive numbers (for example, if n=5 then summation of 1+2+3+4+5=15). Then, trace its execution by showing stack contents.arrow_forward
- A drop-out stack is a data structure that acts just like a stack except that if the stack size is n, and the n + 1 element is pushed, the first element is lost. Using an array, create a drop-out stack. (Hint: A circular array implementation would be appropriate.)arrow_forwardExplain how to use a stack to remove recursion.arrow_forwardAs recursion is implemented using a stack, an object of class Stack must be declared and initialized in the program to hold the class objects of every recursive call? a)true b) falsearrow_forward
- As recursion is implemented using a stack, an object of class Stack must be declared and initialized in the program to hold the class objects of every recursive call? 1) true 2) falsearrow_forwardmultiply choice recursion questionarrow_forwardConsider the Stack ADT: Stack: push(x) adds x to top of stack pop() removes top element of stack and returns it size() returns number of elements in stack Select all options that allow for an efficient implementation based on the discussions from class. For any array implementation, you can assume the array is large enough so that making a larger one is not needed when pushing an item to the stack. Using an array with the top at the front of the array. Using an array with the top at the back of the array. Using a singly linked list with the top at the head of the list. Using a singly linked list with the top at the tail of the list. ENGarrow_forward
- Recursion and list processing Write a maxel that returns the maximum element in an arbitrarily complex list (e.g., list that may contain lists, which may contain lists, and so on). For example, (maxel '(((5)) (9 (3)) 7)-> 9arrow_forwardB) Write a recursive function to find summation of the first n positive numbers (for example, if n=5 then summation of 1+2+3+4+5=15). Then, trace its execution by showing stack contents.arrow_forwardImplement the stack code for following question Explain the logic with explanation!arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education