use c++ and complete this lab
#include <iostream>
using namespace std;
class FibObj
{
public:
void setSize()
{
cout << "Enter an integer larger than 2: ";
cin >> size;
}
int getSize()
{
return size;
}
void fibTerms(int x) // Write a recursive function
{
}
explicit FibObj() // Default constructor was made explicit to avoid possible implicit type conversion
{
setSize();
int *arr;
arr = new int[getSize()];
arr[0] = 1;
arr[1] = 1;
// Call recursive function here
// The next two lines will fill the array with the Fibonacci numbers; however, this is not recursive
for (int i = 2; i < size; i++)
arr[i] = arr[i - 1] + arr[i - 2];
for(int j = 0; j < getSize(); j++)
cout << arr[j] << " ";
};
private:
int size;
};
Please find the modified code below.
#include <iostream>
using namespace std;
class FibObj
{
public:
void setSize()
{
cout << "Enter an integer larger than 2: ";
cin >> size;
}
int getSize()
{
return size;
}
void fibTerms(int x)
{
static long int first = 0, second = 1, sum;
if(x > 1)
{
sum = first + second;
first = second;
second = sum;
cout << sum;
fibTerms(x-1); // recursive call
}
else
{
// after the elements, for line break
cout << endl;
}
}
explicit FibObj() // Default constructor was made explicit to avoid possible implicit type conversion
{
setSize();
int *arr;
arr = new int[getSize()];
arr[0] = 1;
arr[1] = 1;
// Call recursive function here
fibTerms(size);
// The next two lines will fill the array with the Fibonacci numbers; however, this is not recursive
for (int i = 2; i < size; i++)
arr[i] = arr[i - 1] + arr[i - 2];
for(int j = 0; j < getSize(); j++)
cout << arr[j] << " ";
};
private:
int size;
};
use c++ and complete this lab #include <iostream> using namespace std; class FibObj { public: void...
Question 1: Fix the 2D dynamic array initialization in following code #include <iostream> using namespace std; int main(){ int rows = 5; int cols = 5; int x; int** arr = new int[rows][cols] cin >> x; arr[x][x] = x; cout << "arr[x][x] = " << arr[x][x]; return 0; } Question 2: Fix the code to initialize the 2D array elements to x #include <iostream> using namespace std; int main(){ int rows; int cols; int x;...
//C++ program #include<iostream> using namespace std; template<typename T> class list{ private: T*arr; int size; int capacity; void resize(){ capacity*=2; T * newArr = new T[capacity]; for(int i=0;i<size;i++){ newArr[i] = arr[i]; } delete(arr); arr = newArr; } public: ...
#include <iostream> using namespace std; int main(void) { int SIZE; cout<<"Enter the size of the array"<<endl; cin>>SIZE; int *numlist = new int[SIZE]; // Read SIZE integers from the keyboard for (int i = 0; i<SIZE; i++ ) { cout << "Enter value #" << i+1 << ": "; cin >> numlist[i]; } // Display the numbers in a reverse order for (int i = SIZE; i > 0; i--...
#include <iostream> using namespace std; bool binarySearch(int arr[], int start, int end, int target){ //your code here } void fill(int arr[], int count){ for(int i = 0; i < count; i++){ cout << "Enter number: "; cin >> arr[i]; } } void display(int arr[], int count){ for(int i = 0; i < count; i++){ cout << arr[i] << endl; } } int main() { cout << "How many items: "; int count; cin >> count; int * arr = new...
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...
//Find two smallest integers #include <iostream> #include <string> using namespace std; // implement printArray here // implement findTwoSmallest here // DO NOT WRITE ANY CODE BELOW THIS LINE (EXCEPT FOR TESTING - REMOVE BEFORE SUBMITTING) int main() { int n; int arr[100]; cout << "Enter number of integers: "; cin >> n; cout << "Enter " << n << " integers: "; for(int i = 0; i < n; i++) { ...
Complete the mult() and printArr() functions
#include <iostream> using namespace std; void init(int arr]05], int x)t //initialization loop for row 1 and 2 for(int i = 0; i < 2; i++){ arr i][j] x; void mult(int arr JSD //multiply the elements of row 2 by row 1, and store result in row3 void printArr int arr ][5]) // a loop to print out all the elements of the array int main) int arr[3105] 31 int x 32 34 // initialize...
c++ #include using namespace std; int main() { int n, x, num, j = 0; cin >> n >> x; int*arr = new int[n]; for (int i = 0; i < n; i++) { cin >> num; if (num < x) { arr[j] = num; j++; } } for (int i = 0; i < j; i++) {...
Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) { int Num1; cout << "Enter 2 numbers: "; cin >> Num2; if (Num1 < Num2) cout << "Smallest number is " << Num1; else cout << "Smallest number is " << Num2; return 0; }
C++
#include <iostream>
using namespace std;
bool checkinventoryid(int id)
{
return id > 0;
}
bool checkinventoryprice(float price)
{
return price > 0;
}
void endProgram()
{
system("pause");
exit(0);
}
void errorID(string str)
{
cout << "Invalid Id!!! " << str
<< " should be greater than 0" << endl;
}
void errorPrice(string str)
{
cout << "Invalid Price!!!" << str
<< " should be greater than 0" << endl;
}
int inputId()
{...