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

Make an Implementation .cpp file, specification .h file should contain functions

ID: 3601353 • Letter: M

Question

Make an Implementation .cpp file, specification .h file should contain functions and Constructor. and driver main.cpp file separately. The program should compile in project. Please read the question carefully before you answer it. Do not forget to cover all answers that asked in the questions. Task: Create the Fahrinacci sequence in C++. This Fahrinacci 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 Fahrinacci sequence and store the numbers in a doubly linked list. Menu: 1. 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. 2. Print the sequence of numbers. 3. Check to see if a number is in the sequence of numbers and how many times it occurs. 4. Display the two numbers that were added to make all occurrence of a number in the sequence. 5. 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. 6. Delete all occurrences of a number from the sequence. (Some of the other options in the menu will no longer make sense.) 7. Exit. Program is to be well documented both internally and externally

Make an Implementation .cpp file, specification .h file and driver main.cpp file separately.

The program should compile in project.

Explanation / Answer

#include<iostream>
#include<stdlib.h>

using namespace std;

struct DoublyListNode
{  

   int dataElement;
   struct DoublyListNode *previousNode;
   struct DoublyListNode *nextNode;
};

struct DoublyListNode *create_list(struct DoublyListNode *root);
void displayList(struct DoublyListNode *root);
struct DoublyListNode *addToList(struct DoublyListNode *root,int data);

int main()
{
   //Declare all required variables

   int firstNum,secondNum;
   int totalTerms;
   struct DoublyListNode *root=NULL;  
  
   //Read data from user
  
cout<<"-- Fahrinacci Sequence -- ";
   cout<<"Enter first number: ";
   cin>>firstNum;
  
   //Add first number to list
  
root=addToList(root,firstNum);
  
   cout<<"Enter second number: ";
   cin>>secondNum;
  
   //Add second number to list
  
root=addToList(root,secondNum);
  
   cout<<"Enter total numner of terms: ";
   cin>>totalTerms;
  
   int a=firstNum;
   int b=secondNum;
   int c;  
   for(int i=1;i<=totalTerms-2;i++) {
  
    c = 3*a-b;
       a=b;
       b=c;
      //Add generated number to list
  
    root=addToList(root,c);
  
   }
   //Finally display list
  
displayList(root);
   return 0;
}

//Method to add data to list
struct DoublyListNode *addToList(struct DoublyListNode *root,int data)
{

   if(root==NULL)
   {
  
    struct DoublyListNode *tempNode;  
       tempNode=(struct DoublyListNode *)malloc(sizeof(struct DoublyListNode));
       tempNode->dataElement=data;
       tempNode->previousNode=NULL;
       tempNode->nextNode=NULL;
       root=tempNode;
       return root;
   }
   else
   {
  
    struct DoublyListNode *tempNode,*pNode;
       tempNode=new struct DoublyListNode;
       tempNode->dataElement=data;
       pNode=root;
       while(pNode->nextNode!=NULL)
           pNode=pNode->nextNode;
       pNode->nextNode=tempNode;
       tempNode->nextNode=NULL;
       tempNode->previousNode=pNode;
       return root;
   }
}


//Method to disply list
void displayList(struct DoublyListNode *root)
{

   struct DoublyListNode *pNode;
   if(root==NULL)
   {  

       cout<<"List is empty ";
       return;
   }
   pNode=root;
   cout<<"List is : ";
   while(pNode!=NULL)
   {

       cout<<pNode->dataElement<<" ";
       pNode=pNode->nextNode;
   }
   cout<<" ";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote