YTU 2618: B 求类中数据成员的最大值-类模板

网友投稿 260 2022-08-29

YTU 2618: B 求类中数据成员的最大值-类模板

2618: B 求类中数据成员的最大值-类模板

时间限制: 1 Sec   内存限制: 128 MB

提交: 430

解决: 300

题目描述

template class Max { public: Max(numtype a,numtype b,numtype c); numtype getMax(); private: numtype x,y,z; }; 请在下面的程序段基础上完成整个设计: #include #include using namespace std; template class Max { public: Max(numtype a,numtype b,numtype c); numtype getMax(); private: numtype x,y,z; };//将程序需要的其他成份写在下面,只提交begin到end部分的代码 //******************** begin ******************** //********************* end ******************** int main() { int i1,i2,i3; cin>>i1>>i2>>i3; Max max1(i1,i2,i3); cout<>f1>>f2>>f3; Max max2(f1,f2,f3); cout<>c1>>c2>>c3; Max max3(c1,c2,c3); cout<

输入

分别输入3个整数,3个浮点数,3个字符

输出

3个整数的最大值 3个浮点数中的最大值 3个字符中的最大值

样例输入

9 5 61.1 3.4 0.9a b c

样例输出

93.40c

提示

在类模板外定义各成员函数。 只提交begin到end部分的代码。

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#include #include using namespace std;templateclass Max{public: Max(numtype a,numtype b,numtype c); numtype getMax();private: numtype x,y,z;};templateMax::Max(numtype a,numtype b,numtype c){ x=a; y=b; z=c;}templatenumtype Max::getMax(){ return (x>y&&x>z)?x:(y>x&&y>z)?y:z;}int main(){ int i1,i2,i3; cin>>i1>>i2>>i3; Max max1(i1,i2,i3); cout<>f1>>f2>>f3; Max max2(f1,f2,f3); cout<>c1>>c2>>c3; Max max3(c1,c2,c3); cout<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:YTU 2616: A代码完善--简易二元运算
下一篇:董明珠的营销游戏!(董明珠营销策略)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~