Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3967226
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:41:41+00:00 2026-05-20T03:41:41+00:00

Hey Guys. I need help understanding my hw assignment. I am starting out in

  • 0

Hey Guys. I need help understanding my hw assignment. I am starting out in C++ and don’t know that much. I do know the basics of a stack and fibonacci sequence. However I do not exactly understand the problem given to me and need not the code to solving the problem but help clarifying some steps. Here’s the hw:

“By completing this project you will become familiar with using recursion and creating ADTs in C++.

Create an integer stack ADT (you may Modify the IntStack ADT given to you in the lecture notes) such that it has a maximum capacity of at least 256 elements. Also add whatever is needed such that it will print out its contents (left-to-right, with the top of the stack on the right) if it is printed to a C++ ostream – such as cout). This stack should be designed such that it will only hold meaningful values greater than zero. Values less than or equal to zero should be printed out as a ‘?’.

Write a recursive implementation of the Fibonacci sequence discussed in class. Also – create an instance of your stack ADT that persists between calls (it can’t be a local variable), and at each step, push a non-meaningful value into it until the value at that stage is determined, then pop it off, and push in the determined value and print the entire stack before returning.

Your program should ask for the position N in the Fibonacci sequence to be determined and then it should output the result of the function call. Example output (including the output from your recursive function) follows:

Enter the position in the Fibonacci sequence to determine: 5

?-?-?-1
?-?-?-1
?-?-2
?-?-1
?-3
?-?-1
?-?-1
?-2
5

Fibonacci(5) = 5

What exactly is the output here? Is it printing out the stack as it calculates the 5th position? also Any ideas on how to implement the Fibonacci into a stack in C++? Should these values be stored in array, list or it doesn’t matter? I’m a noob so any help would be much appreciated. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:41:42+00:00Added an answer on May 20, 2026 at 3:41 am

    Yes, it’s calculating 5th fibonacci number (which happens to be 5, that’s a bit confusing), but look at what you calculate when you call fibonacci(5), assuming the following code for fibonacci:

    int fibonacci(int n) {
        if (n <= 1) return n;
        else if (n == 2) return 1;
        else return fibonacci(n-1) + fibonacci(n-2);
    }
    

    here are the function calls to calculate fibonacci(5):

    f(5)
     -> f(4)
         -> f(3)
             -> f(2)
             -> f(1)
         -> f(2)
     ->f(3)
        -> f(2)
        -> f(1)
    

    If you look at this as a binary tree, the output they gave you was a post-order tree traversal, with the amount of ? being the depth of that stack, and the number being the value of that node.

    So just do what the function does and every time you see return, write what you return (with the ?’s before it):

    • The first function that returns is the first f(2), at depth 4: print ?-?-?-1
    • The second return is the f(1) below it: print ?-?-?-1
    • The third return is the parent of f(2) and f(1), which has depth 3 and value f(2)+f(1)=2: print ?-?-2
    • And so on until you return f(5) at depth 0 and value 5
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys, I need help considering win32com in Python: I have a routine that
Hey guys! I need some help writing a code that creates an array in
Hey guys, thanks for all the help that you can provide. I need a
Hey Guys...need help. Working on a project and get this error on the Output
Hey guys. I need help for a project for school. Essentially, I need to
Hey guys, if anybody can help me out i'd love it... What i have
Hey guys, I have this quick bit of code that I can't figure out
Hey guys I need a tad bit of help. I need my streamwriter to
Hey guys I need to know who to put these array objects into two
Hey guys need some more help I have 3 tables USERS, PROFILEINTERESTS and INTERESTS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.