加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

《数据结构》实验一 (2)

发布时间:2020-12-15 06:06:51 所属栏目:安全 来源:网络整理
导读:第二题的源代码(运用函数模板): #includeiostream #includestdlib.h #includeiomanip using namespace std; templateclass T T add(T a,T b) { return a+b; } templateclass T T multiply(T m,T n) { return m*n; } int main() { int x=4; int y=5; int z

第二题的源代码(运用函数模板):

#include<iostream>
#include<stdlib.h>
#include<iomanip>
using namespace std;

template<class T>
T add(T a,T b)
{
return a+b;
}
template<class T>
T multiply(T m,T n)
{
return m*n;
}
int main()
{
int x=4;int y=5;int z;
float i=4.5,j=3;float k;
k=add(i,j);
z=add(x,y);
cout<<"4+5="<<z<<endl;
cout<<"4.5+3="<<k<<endl;
cout<<"4*5="<<multiply(x,y)<<endl;
cout<<"4.5*3="<<multiply(i,j)<<endl;
system("pause");
return 0;
}

调试结果截图:


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读