大学c 习题答案习题0304答案

上传人:bin****86 文档编号:55167390 上传时间:2018-09-25 格式:DOC 页数:13 大小:89KB
返回 下载 相关 举报
大学c  习题答案习题0304答案_第1页
第1页 / 共13页
大学c  习题答案习题0304答案_第2页
第2页 / 共13页
大学c  习题答案习题0304答案_第3页
第3页 / 共13页
大学c  习题答案习题0304答案_第4页
第4页 / 共13页
大学c  习题答案习题0304答案_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《大学c 习题答案习题0304答案》由会员分享,可在线阅读,更多相关《大学c 习题答案习题0304答案(13页珍藏版)》请在金锄头文库上搜索。

1、习题 313 75 8 或者 3 7 5 8 (注: 为空格、Tab 键或者回车键)2 #include “iostream.h“void main() int a, b, c, d;cin.ignore(1); cin a hex b ; cin dec c ; cin.ignore(3); cin d;coutabc; s = (a+b+c)/2; area = sqrt(s*(s-a)*(s-b)*(s-c);coutabc; if(ab) max=a; else max=b;if(max=1000n+1nsum+nsum结束YNcoutscore; if(score100 | scor

2、e=90) cout=80) cout=70) cout=60) coutscore; if(score100 | scoremoney; if(money=m+1) cout0;j-,i-=2) for(m=0;m /定义函数模板的模板说明部分 Type power(Type var1, Type var2) /定义函数模板的函数说明部分 return pow(var1,var2); void main( ) int m1,m2;double n1,n2;coutn1n2;m1=n1; m2=n2;cout /定义函数模板的模板说明部分 Type sum(Type* p, int count

3、) /定义函数模板的函数说明部分 int i; Type s=0;for(i=0;i class CValue private: Type data5; /数据成员public: CValue(); /构造函数 Type Max(void); /成员函数Type Min(void); ;template CValue : CValue() coutdatai; template Type CValue : Max(void) Type m=data0; for(int i=1;i Type CValue : Min(void) Type m=data0; for(int i=0;idatai)

4、 m=datai; return m; void main( ) cout a;cout b;cout class CValue private: Type data5; /数据成员public: CValue(); /构造函数 friend Type Max(CValue v); /友元函数friend Type Min(CValue v); ;template CValue : CValue() coutdatai; template Type Max(CValue v) Type m=v.data0; for(int i=1;i Type Min(CValue v) Type m=v.d

5、ata0; for(int i=0;iv.datai) m=v.datai; return m; void main( ) cout a;cout b;cout class CArray private: Type* data; /数据成员int size; public: CArray(const int n); /构造函数 CArray(); /析构函数 void Input(); /成员函数void Output(); Type Max(); Type Min(); Type Sum(); Type Average(); ;template inline CArray : CArray(

6、const int n) size = n; data = new Typesize; for(int i=0; i inline CArray : CArray() delete data; template void CArray : Input() coutdatai; template void CArray : Output() cout Type CArray : Max() Type m=data0; for(int i=1;i Type CArray : Min() Type m=data0; for(int i=0;idatai) m=datai; return m; tem

7、plate Type CArray : Sum() Type sum=0; for(int i=0;i Type CArray : Average() Type avg=0; for(int i=0;i a(5);CArray b(5);cout“整数对象a,“;a.Input(); cout“浮点数对象b,“;b.Input();cout“整数数组对象a的元素最大值为:“a.Max()endl;cout“整数数组对象a的元素最小值为:“a.Min()endl; cout“整数数组对象a的元素累加和为:“a.Sum()endl;cout“整数数组对象a的元素平均值为:“a.Average()endl;cout“浮点数数组对象b的元素最大值为:“b.Max()endl;cout“浮点数数组对象b的元素最小值为:“b.Min()endl; cout“浮点数数组对象b的元素累加和为:“b.Sum()endl;cout“浮点数数组对象b的元素平均值为:“b.Average()endl;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号