Create this menu based program in C++ creating the Fibonacci sequence using Doub
ID: 3603072 • Letter: C
Question
Create this menu based program in C++ creating the Fibonacci sequence using Doubly Linked Lists. Looking for help!
Task: Create the Fibonacci sequence. This sequence is made by multiplying the first number by 3 and subtracting the second number.
Example: num1 = 4, num2 = 2
Sequence: 4, 2, 10, -4, 38, etc.
Processing: Calculate the Fibonacci sequence and store the numbers in a doubly linked list.
Menu:
Ask for the first 2 numbers of the sequence (assume they don’t match) and how many terms there should be in the sequence. Then create the sequence.
Print the sequence of numbers.
Check to see if a number is in the sequence of numbers and how many times it occurs.
Display the two numbers that were added to make all occurrence of a number in the sequence.
Display the two numbers in the sequence that will use a number to create them. Ask the user for the number. Only need to check for the first occurrence.
Delete all occurrences of a number from the sequence. (Some of the other options in the menu will no longer make sense.)
Exit.
Program is to be well documented both internally and externally.
Explanation / Answer
Function to insert at the end
void insertEnd(struct Node** start, int value)
{
// If the list is empty, create a single node
// circular and doubly list
if (*start == NULL)
{
struct Node* new_node = new Node;
new_node->data = value;
new_node->next = new_node->prev = new_node;
*start = new_node;
return;
}
// If list is not empty
/* Find last node */
Node *last = (*start)->prev;
// Create Node dynamically
struct Node* new_node = new Node;
new_node->data = value;
// Start is going to be next of new_node
new_node->next = *start;
// Make new node previous of start
(*start)->prev = new_node;
// Make last preivous of new node
new_node->prev = last;
// Make new node next of old last
last->next = new_node;
}