Template

1.     What will be the output of each of the following program when it is executed. (a)

#include using namespace std;

template > T sum (T array[3][3], int n)

T temp = 0;

for (int i =0; i<= n-1;=””>

for (int j = 0; j <= n-1;=”” ++j)=”” temp=””>

return(temp);

int main()

int n = 3, sum1; oat sum2;

static int a[3][3] = 1,2,3,

4,5,6,

7,8,9

;

static double b[3][3] = 1.1,2.2,3.3,

4.4,5.5,6.6,

7.7,8.8,9.9

;

(b)

sum1 = sum(a,n);

cout < “=”” sum=”” of=”” the=”” integers=”””>< sum1=””> endl; sum2 = sum(b,n);

cout < “=””> of the oating point numbers = ” <>sum2; cout endl;

return 0;

#include using namespace std; template class sample

private:

T a,b; public:

T  nd_min (T a, T b);

;

template

T sample ::  nd_min (T a, T b)

return ( a < b=”” a=”” :=””>

int main()

                €

int a = 10, b = 20; sample obj1;

int temp1 = obj1. Nd_min(a,b);

cout < “a=”””>< a=””>< “=”” b=”””>< b;=”” cout=””>< “=”” minimum=”””>< temp1=””>< endl;=”” double=”” x=”1.1,” y=””>

sample obj2;

double temp2 = obj2. Nd_min(x,y); cout < “x=”””>< x=””>< “=”” y=”””><>

cout < “=”” minimum=”””>< temp2=””>< endl;=”” return=””>

#include using namespace std; template class abc

private:

T value; public:

abc()

cout < “default=”” constructor=””>

abc (int a)

cout < “constructor=”” with=”” int=”” argument=””>

abc ( oat af)

cout “constructor with oating point n”;

;

int main()

                                                (d)

abc obj1(10);

abc< oat=””> obj2(-21.22f); return 0;

//using class template #include using namespace std; template class sample

public :

sample ();

inline void display();

;

template sample :: sample()

cout <“class template=”” –=”” constructor=””>

template

void sample :: display()

cout < “this=”” is=”” a=”” member=”” function=””>

int main()

                €

sample obj1; sample < oat=””>  obj2; sample obj3; sample obj4; return 0;

#include using namespace std; template class sample

private:

T value; public:

sample (T n) : value (n)

cout <>

;

~sample ()

cout < “destructor=””>

void display ()

cout < “=”” content=”” of=”” the=”” value=”””>< value=””><>

;

int main()

sample obj1(10);

cout < “=”” integer=”” :”=””>< endl;=””>

return 0;

WhatsApp
Hello! Need help with your assignments?

For faster services, inquiry about  new assignments submission or  follow ups on your assignments please text us/call us on +1 (251) 265-5102

🛡️ Worried About Plagiarism? Run a Free Turnitin Check Today!
Get peace of mind with a 100% AI-Free Report and expert editing assistance.

X