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;](http://img.homeworklib.com/images/36aaf971-1e00-44ee-8c68-c42da4f483f2.png?x-oss-process=image/resize,w_560)

C++ code
============================================================================================
#include<iostream>
using namespace std;
void init(int arr[][5],int x)
{
for(int i=0;i<2;i++)
{
for(int j=0;j<5;j++)
{
arr[i][j]=x;
}
++x;
}
}
void mult(int arr[][5])
{
//multiply row 2 by row 1
for(int i=0;i<5;i++)
{
arr[2][i]=arr[0][i]*arr[1][i];
}
}
void printArr(int arr[][5])
{
//loop to print elements of the array
for(int i=0;i<3;i++)
{
for(int j=0;j<5;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
}
int main()
{
int arr[3][5];
int x;
cin>>x;
init(arr,x);
mult(arr);
printArr(arr);
return 0;
}
============================================================================================
Output

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]...
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;...
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...
#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...
#include <iostream> using namespace std; void drawTriangle(int x) {} int main() {} Complete the program so that it produces a right-angle triangle of a user-specified height. For example: Enter a height for the triangle: 5 Result: * ** *** **** *****
Write loop(s) that print ALL the content of the following 2D array #include <iostream> using namespace std; int main(){ int rows; int cols; int offset; cin >> rows; cin >> cols; cin >> offset; int** arr = new int*[rows]; for(int i = 0; i < rows; ++i) arr[i] = new int[cols]; for(int i = 0; i < rows; i++) // initialization for(int j = 0; j < cols; j++) arr[i][j] = offset + i; // printing, your code goes here ...
C++
1.
A?B?C?D? which one is correct
2.
3A, 3B
#include<iostream> using namespace std; void swap0(int* ptri, int* ptr2) { int *temp; temp = ptr1; ptr1 = ptr2; ptr2 = temp; void swap1(int ptri, int ptr2){ int temp; temp = ptri; ptr1 = ptr2; ptr2 = temp; portion void swap2(int *&ptri, int *&ptr2){ int* temp; temp = ptr1; ptr1 = ptr2; ptr2 = temp; void swap3(int &ptri, int &ptr2) { int temp; temp = ptr1; ptr1 = ptr2; ptr2 =...
//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: ...
Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int); int main() { f1(10); return 0; } void f1(int n) { f2(n + 5); } void f2(int n) { f3(n - 2); } void f3(int n) { cout << n << endl; // LINE 1 } Just before the program statement marked with the comment "LINE 1" is executed, how many stack frames will be on the program call stack?
#include <iostream> using namespace std; int main() { int sumOdd = 0; // For accumulating odd numbers, init to 0 int sumEven = 0; // For accumulating even numbers, init to 0 int upperbound; // Sum from 1 to this upperbound // Prompt user for an upperbound cout << "Enter the upperbound: "; cin >> upperbound; // Use a loop to repeatedly add 1, 2, 3,..., up to upperbound int number =...
#include <iostream> using namespace std; void drawTriangle(int w) {} int main() {} Complete the program so that it produces a centered, isosceles triangle of a user-specified width. For example: Enter a width: 5 Result: ***** *** *