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

(Please give all the solutions and steps, if you give the answer by picture plea

ID: 3919892 • Letter: #

Question

(Please give all the solutions and steps, if you give the answer by picture please post a clear picture. Please don't answer the question if you can't do all the questions, THANKS).

4. (30 points) Fibonnaci numbers are a series of numbers where the current element is calculated as a sum of the previous 2 elements. The first two elements are 0 and 1 and are fixed. The next element is their sum (0 + 1 = 1), and so on. The list of the first few Fibonnaci numbers is as follows: 0,1, 1, 2, 3, 5, 8, 13, 21, 34, 55, Write a function that generates a list of n Fibonnaci numbers based on input from the console and stores it in a map with the index starting at 1 (and incrementing by 1 for each Fibonacci number) Output the entire list to the console after generating it. You may benefit from using the following constructs: map ne«Map; // Creates newMap that can be indexed with key and // stores data map: :iterator myIterator; II Declares a new iterator to step // through each element in a map newMap.beginO; // Iterator pointing to the start of a map named newMap newMap.endo I Logical value to indicate whether the end of a map has // been reached myIterator->first; // Returns a map's key using iterator myIterator myIterator->second; // Returns a map's data using iterator myIterator

Explanation / Answer

#include<iostream>

#include<map>

using namespace std;

int main()

{

int n,i;

cout<<"Enter number of elements needed"<<endl;

cin>>n;

map<int,int> m;

m[1]=0;

m[2]=1;

for(i=3;i<=n;i++)

{

m[i]=m[i-1]+m[i-2];

}

map<int,int>::iterator it;

for(it=m.begin();it!=m.end();it++)

{

cout<<it->second<<" ";

}

cout<<endl;

}