template< class T , class U ,class X >
void Printoutput( T value ,U value , X value ){
cout << value << value << value << endl;
}
int main(){
Printoutput("***",47,"***");
}
//Write a main() function that tests the function with char, int, double, and string arguments.
/*Write a code Symbolic.cpp that contains
a function template to display a value preceded
and followed by n elements of a symbol x on a line. Write a main() function
that tests the function with char, int, double, and string arguments.
The output could be, for example:
***47***
00039.25000
aaaaBobaaaa*/
and here is my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <string>
usingnamespace std;
template< class T , class U ,class X >
void Printoutput( T value ,U value2 , X value3 ){
cout << value << value2 << value3 << endl;
}
int main(){
Printoutput("***",47,"***");
Printoutput("000",39.25,"000");
Printoutput("aaaa","Bob","aaaa");
system( "pause" );//system pause
return 0;//Exit program
}
but from here . i know that my code didn't fullfill the question for contains a function template to display a value preceded and followed by n elements of a symbol x on a line. . Not really get understand about the question. can someone help? thanks
contains a function template to display a value preceded and followed by n elements of a symbol x on a line.
It'd look like this:
1 2 3 4 5 6 7
template< class T >
void Printoutput( T value , char symbol_before_and_after_value, int how_often_the_symbol_is_repeated){
// insert the first loop for outputting the symbol here
cout << value;
// insert the second loop for outputting the symbol here
cout << endl;
}
template< class T , class U ,class X >
void Printoutput( T value ,U elements , X timesRepeated ){
for( int i = 0 ; i < timesRepeated ; i++ )
cout << elements ;
cout << value;
for( int i = 0 ; i < timesRepeated ; i++ )
cout << elements;
cout << endl;
}
int main(){
Printoutput(47,'*',3);
Printoutput(39.25,0,3);
Printoutput("Bob",'a',4);
system( "pause" );//system pause
return 0;//Exit program
}
am i right?
after observe it , templates quite usefull!