7 like 0 dislike

This exercise is an example of the use of a template. Templates allow you to write code (e.g., functions) which does not require a priori knowledge of variable types, e.g., int, double, or a user-defined class object.

Please use template to create function allow input 2 value and output their combine.

We need to use main function as follow:

int main()
{
	string sA="Peer";
	string sB="-Interaction";
	printIt(9,2);
	printIt(5.5,2.2);
	printIt(sA,sB);
}

Expected output:

11
7.7
Peer-Interaction

Notice: You output might get 100/100, but your code matters!

asked in Templates by (11.8k points) | 33 views
0 1
Called for Help
0 0
Called for Help
0 0
Called for Help

28 Answers

0 like 0 dislike
Hidden content!
** * * *** *** * *
* ** ***** *



using namespace std;



template <class T>



void printIt(T a, T b)

{
* * ** * * ** **** result;
** * *** ** *** = (a+b);
* ** * ***** ******* * * ** *** ** *** *** ** *

}



int main()

{
* ** ****** ** * * * *** * ** ** *** * *
** * * ** ** **** * ****** * * **** *
** ****** * ** * * *** *
* **** * * *** ** ** ** * *
**** * * ******* ** * * ** ** ** * ***

}
answered by (-74 points)
0 like 0 dislike
Hidden content!
* * * * ** **



using namespace std;



template *** * T>

void printIt(T x, T y){
*** * *** *** * *** ** * * ** * * * *

}



int main()

{
* ** ***** ** * * * ** **** ** ** ** * * **
* * **** * * **** ***** * * ** * *** **** ** *
** * * * * **** *** ** * * *******
** * ** *** **** **** ** * **
* * *** * ** * * **** *** ** * *

}
answered by (-434 points)
0 like 0 dislike
Hidden content!
#include ** * ** * * **

using namespace std;


* ** ** ** * ** *

void printIt( T a, T b)

{
** * * * **** *** * * c = a + b;
* * *** *** ** **** **** * * * c * * ** * ** endl;

}



int main()

{
******* ** ** ** * * *** * ** * ** ** *
** ** * * ** * * **** * * * *** *** ** ** * *
* * ******* *** * * * *********
* * **** * ** *** * * ***
** * * ** ** *** * ** * * ***

}
answered by (-136 points)
0 like 0 dislike
Hidden content!
#include *** *** *** * * *

#include ** ** ***

using *** * std;


* * ** *** * ***

void ** * * * a, T b)

{
* * ** * ** * * * *** ** * * a + b * * *** endl;

}



int main()

{
* ** * **** * * * sA = ** * ** ** *
** * *** * *** sB = * *** **** ** ** *
* *** * ** *** * ** * ** ** * 2);
* ***** * ****** *** * ** ** 2.2);
** *** ******** ** ** ** ** sB);
*** * ** * *** * ***** 0;

}
answered by (-45 points)
0 like 0 dislike
Hidden content!
#include *** * * ** ***

using namespace std;


** * ** ** **** *** **

void printIt( T a, T b)

{
* * **** * **** * * * * c = a + b;
* * * *********** * **** * *** * *** c * * ** * endl;

}



int main()

{
* *** * ** * **** ** ** * * * **** *** *
** * * **** *** * ** * *** * ** * * * * ** *
* * ** * * * * * * ** *****
** ** * ****** *** ** ** *** **** ** *
** * ****** * * * *** ** * *

}
answered by (-134 points)
0 like 0 dislike
Hidden content!
* * * *** * * * *** ***
** **** * ** **** *

using * ** std ;


* **** * * *

T * a , T b)

{

T sum = a + b ;

return sum ;

}



int main()

{
* * * ** * ** *** ** ** *** * * ** ** ***** * *
* * * * ** * * * * * ** ** **
** * * * ** * * *** * * **
** ** * * **** * * ** * * *
****** ** * * **** *****

cout ** * *** * * * * endl ;

cout * **** * **** *** * *** * endl ;

cout * ** * ** * * ** * * **



}
answered by (-103 points)
0 like 0 dislike
Hidden content!
#include * ** ** ****

using namespace std;


* * * * ** * * *** * **

void printIt( T a, T b)

{
* ******** ** *** ** c = a + b;
** * * **** ***** * *** * * ** *** * c * ** endl;

}



int main()

{
* ** ** ** * *** * *** *** ** * * * * *
* * *** ** ** *** ***** ** **** * ** ** *
* ****** * ** * *** * *
* ** * * ** *** * * * **
* * * ** * ** * * * * * * * *

}
answered by (10.8k points)
0 like 0 dislike
Hidden content!
* ** ***** * * *
* ** ** * * * * ****

using namespace std;



template <class T>

void printIt(T a, T b){
*** * * *** ** ** * * **** *** * * * * **** *

}



int main(){
**** ** ** ** * ** ** *** ** * * **
* ** * * **** * * ** ***** *** ** ***
** * ***** ** ** ** * * * *
** * * * * * * **** * * *
** ** *** *** *** *** * **

}
answered by (122 points)
0 like 0 dislike
Hidden content!
#include * *** ** * * *

#include * * ***** * *

using namespace std;



template ** ** *** T>



T printIt(T num1, T num2)

{
** ** * ** ** * ** * * *******


* *** * * *** *** sum;

}







int main()

{
*** * *** **** * * ** * *** *** * *****
* ***** ***** * * ***** * * * * ** **
** * *** * *** * * * * ******** ** * * * ** **
** * * ****** * *** *** * * * **** ** *** * ** *
* ** * ** * ** ** * * *** * ** *** *

}
answered by (-11 points)
0 like 1 dislike
Hidden content!
* ***** ** ** *

using namespace std;



template<class T>

T printIt(T a, T b)

{
*** * * * ** * * * sum=a+b;
** *** *** *** *** * **** ** * * ** **



}

int main()

{
***** **** * **** ** ** * * ****** * * *
* ** * * ******* * ** **** *** ** ****
*** ** * *** * ** * *** *** *
* ** * *** ** * ** ****
****** * * **** ** ** * *


* * * * ** * ** * ** * ** 0;

}
answered by (-605 points)
Get it on Google Play Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.68.65.150
©2016-2018

Related questions

9 like 0 dislike
24 answers
asked May 24, 2016 in Templates by admin (9.7k points) | 53 views
6 like 1 dislike
45 answers
asked May 26, 2016 in Templates by thopd (11.8k points) | 60 views
5 like 1 dislike
28 answers
asked May 26, 2016 in Templates by thopd (11.8k points) | 31 views
2,974 questions
57,433 answers
29,089 comments
938 users