Program in C++ Task: Create the Fahrinacci sequence. This sequence is made by mu
ID: 3599291 • Letter: P
Question
Program in C++ Task: Create the Fahrinacci 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 Fahrinacci 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
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
/*node declaration*/
struct node
{
int info;
struct node *next;
struct node *prev;
}*start;
class FahrinacciSeq
{
public:
void create_list(int value);
void add_begin(int value);
void add_after(int value,int pos);
void delete_element(int value);
FahrinacciSeq(){
start=NULL;
}
};
int main(){
int choice,num1,num2,pos;
FahrinacciSeq seq;
while(1){
cout << "................."<<endl;
cout << "Enter First Number ";
cin >> num1;
cout << "Enter Second Number ";
cin >> num2;
cout << "1. create a doubly list " << endl;
cout << "2. delete list " << endl;
cout << "3 Exit"<< endl;
cin >> choice;
switch (choice){
case 1:
int myArray[10];
for(int i=0;i<10;i++){
{
if(i==0){
myArray[i]=num1;
}
else if(i==1){
myArray[i]=num2;
}
else if(i!=0 && i!=1){
myArray[i]=3*myArray[i-2]-myArray[i-1];
}
for(int i=0;i<10;i++){
seq.create_list(myArray[i]);
}
for(int j=0;j<10;j++){
printf("%d",myArray[j]);
}
}
break;
case 2:
if(start==NULL)
{
cout << "List empty " << endl;
}
break;
case 3:
exit(1);
default :
cout<< "Wrong choice " << endl;
}
}
}
void seq::create_list(int value){
struct node *s, *temp;
temp=new(struct node);
temp->info=value;
temp->next=null;
if(start==null){
temp->prev=null;
start=temp;
}
else{
s=start;
while(s->next!=null)
s=s->next;
s->next=temp;
temp->prev=s;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.