"Function template--sum of number of n" of OJ Brush problem

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.