Consider the following code in c++
template <class T>
int F1(T* A, int n)
{
int v = 1;
for (int i = 0; i < n - 1; i++)
if (A[i] != A[i + 1])
v++;
return v;
}
int main()
{
string X[10] = { "aaa","bbb","bbb","bbb","bbb" };
int a = F1(X, 5);
return 0;
}
what is the value of the variable a?the value of the variable a = 2

#include <iostream>
using namespace std;
template <class T>
int F1(T* A, int n)
{
int v = 1;
for (int i = 0; i < n - 1; i++)
if (A[i] != A[i + 1])
v++;
return v;
}
int main()
{
string X[10] = { "aaa","bbb","bbb","bbb","bbb" };
int a = F1(X, 5);
cout<<a;
return 0;
}
Consider the following code in c++ template <class T> int F1(T* A, int n) { int...
Consider the following code: Void F1 (int n) { int a; for(int i = 0; i < n; i += 2) a = i; } Which of the following characterization, in terms of n, of the running time of the above code (F1) is correct? Θ(n3/2) · O(1/n) · O(n) · Ω(n2) Consider the following code: Void F1 (int n) { int a; for(int i = 0; i < n; i += 2) a = i; }...
C++ ONLY! Consider the following code and
answer the questions in the table below.
#include <iostream>
template <typename T, int N=10>
class Array {
private:
T array[N+1];
public:
Array() {
for(int i=0; i<N+1; i++) array[i] =
0;
}
T& operator [] (int index) {
if (index>N || index < 0)
return array[N];
else
return array[index];
}
template <typename S>
Array<T,N>& operator= (S &other) {
for(int i=0; i<N+1; i++)
array[i] =
other[i];
return *this;
}
};
template <typename T, typename...
please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...
(a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0) return 0; 3 return (n-1 + g(n-1)); 4} (b) Consider the following C++ function: 1 bool Function (const vector <int >& a) { 2 for (int i = 0; i < a. size ()-1; i ++) { 3 for (int j = i +1; j < a. size (); j ++) { 4 if (a[i] == a[j]) return false; 5 6 } 7 return...
b) Consider the following code. public static int f(int n) if (n == 1) return 0; else if (n % 2 == 0). return g(n/2); else return g(n+1); public static int g(int n) int r = n % 3; if (r == 0) return f(n/3); else if (r == 1) return f(n+2); else return f(2 * n); // (HERE) public static void main(String[] args) { int x = 3; System.out.println(f(x)); (1) (5 points) Draw the call stack as it would...
Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...
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?
20) What is the output of the following segment of C code: int avg(int n, int* a); int main () { int array[4]={1,0,6,9}; printf("%d", avg(4, array)+ 1); system("pause"); return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...
Submissions) Part A Type and run the Array class template discussed in lecture (Templates notes). Modify the class by adding sort member function (refer to Algorithm Analysis notes for sorting algorithms) Sample usage: a. sort(); Add the needed code in main to test your function. template <class T> 1/you can use keyword typename instead of class class Array { private: T *ptr; int size; public: Array(T arr[], int s); void print(); template <class T> Array<T>:: Array (T arr[], int s)...
#include <stdio.h> #include <stdlib.h> int aaa(); int main() { int ddd,eee = aaa (ddd,eee); printf("new num 1 = %d, new num2 = %d.\n", ddd,eee); return 0; } int aaa(int bbb,int ccc) { bbb = 111; ccc = 222; printf("num 1 = %d, num 2 = %d.\n", bbb,ccc); return bbb ,ccc; } Output: num 1 = 111, num 2 = 222. new num 1 = 0, new num2 = 222. ************************************************************** I am learning function in C....