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

what is the output, please explain the code. 1.) template <typename T> void fun(

ID: 3820863 • Letter: W

Question

what is the output, please explain the code.

1.)

template <typename T>

void fun(const T&x)

{

static int count = 0;

cout << "x = " << x << count << endl;

++ count;

return;

}

int main()

{

fun <int> (1);

cout << endl;

fun<int>(1);

cout <<endl;

fun<double>(1.1);

cout << endl << endl << endl;

return 0;

}

2.)

What is the ouput?

template<class T>

class Test

{

private:

T val;

public:

static int count;

Test() { count++;}

};

template<class T>

int Test<T>::count = 0;

int main()

{

Test<int> a;

Test<int> b;

Test<double>c;

cout<< Test<int>::count <<endl;

cout<< Test<double>::count <<endl;

return 0;

  

}

3.)

What is the ouput?

void f (int n )

{

  

for (int i = 1 ; i < n ; i++ )

  

cout << n * i << " " ;

  

cout << " ";

  

  

  

if (n > 1)

  

f(n-1);

  

cout<< n << " " ;

  

}

Explanation / Answer

Answer.1 output fo program 1 is follows as it compile and execute.

x=10

x=11

x=1.1

Answer.2 output for program 2 is follows as it compile and execute.

2

1