Title Description
using function templates to find 4 number of the and.
Some of the code is given below, just submit the missing code.
#include <iostream>
using namespace Std;
/*
Supplemental Missing Code
*/
int main ()
{
Double result;
unsigned char c1,c2,c3,c4;
cin>>c1>>c2>>c3>>c4;
result = sum<unsigned char> (C1,C2,C3,C4);
Cout<<int (Result) <<endl;
int i1,i2,i3,i4;
cin>>i1>>i2>>i3>>i4;
result = Sum<int> (I1,I2,I3,I4);
cout<<result<<endl;
Double d1,d2,d3,d4;
cin>>d1>>d2>>d3>>d4;
result = Sum<double> (D1,D2,D3,D4);
cout<<result<<endl;
return 0;
}
Input
First line 4 of characters
Second Line 4 an integer
Third line 4 a decimal
Output
First line 4 of characters ASCII and the
Second Line 4 an integer and a
Third line 4 a decimal and
Sample input
Abcd
1 2 3 4
1.1 2.2 3.3 4.4
Sample output
138
10
11
The code is as follows:
#include <iostream>using namespace std;template <class t>t sum (T a,t b,t c,t d) { return a+b+c+d;} int main () { double result; unsigned char c1,c2,c3,c4; cin>>c1>>c2>>c3>>c4; result = sum<unsigned char> (C1,C2,C3,C4); Cout<<int (Result) <<endl; int i1,i2,i3,i4; cin>>i1>>i2>>i3>>i4; result = Sum<int> (I1,I2,I3,I4); cout<<result<<endl; Double d1,d2,d3,d4; cin>>d1>>d2>>d3>>d4; result = Sum<double> (D1,D2,D3,D4); cout<<result<<endl; return 0;}
Operation Result:
Always thought that the function template is just an example of the book, the teacher here also did not say much, also did not care,,, and the result of this project put me to the pit ...
"Function template--sum of number of n" of OJ Brush problem