第九周项目三 我的数组类
来源:互联网 发布:网络买重庆时时彩违法 编辑:程序博客网 时间:2024/06/05 04:05
//第九周项目二 深复制函数(1)/*copyright(c)2016.烟台大学计算机学院 * All rights reserved, * 文件名称:text.Cpp * 作者:舒文超 * 完成日期:2016年4月17日 * 版本号:vc++6.0 * * 问题描述:阅读函数,请完成成员函数的定义,因为存在指 针型的数据成员,注意要深复制的构造函数。 */#include<iostream>using namespace std;class MyArray{private: int *arrayAddr; //保存一个有len个整型元素的数组的首地址 int len; //记录动态数组的长度 int max; //动态数组中的最大值(并非动态数组中必须要的数据成员)public: MyArray(int *a, int n); ~MyArray(); int getValue(int i); //获得数组中下标为i的元素的值 int getLen(); //返回数组长度 int getMax( ); //返回数组中的最大值};//写出各成员函数的定义MyArray::MyArray(int *a, int n){ int i; len=n; arrayAddr=new int[n]; max=*(a+0); for(i=0;i<n;i++) { *(arrayAddr+i)=*(a+i); if(*(a+i)>max) max=*(a+i); }}MyArray::~MyArray(){ delete [] arrayAddr;}int MyArray::getValue(int i) //获得数组中下标为i的元素的值{ return *(arrayAddr+i);}int MyArray::getLen() //返回数组长度{ return len;}int MyArray::getMax( ) //返回数组中的最大值{ return max;}int main(){ int b[10]= {75, 99, 90, 93, 38, 15, 5, 7, 52, 4}; MyArray r1(b,10); cout<<"最大值:"<<r1.getMax()<<endl; int c[15] = {18,68,10,52,3,19,12,100,56,96,95,97,1,4,93}; MyArray r2(c,15); int i,s=0; for(i=0; i<r2.getLen(); i++) s+=r2.getValue(i); cout<<"所有元素的和为:"<<s<<endl; return 0;}
0 0
- 第九周项目三 我的数组类
- 第九周项目2 我的数组类
- 第九周项目 2.1 我的数组类
- 第九周项目2-我的数组类
- 第九周项目3:我的数组类
- 第九周项目2—我的数组类
- 第九周项目二-我的数组类
- 第九周项目2 我的数组类
- 第九周项目2-我的数组类
- 第九周项目2——我的数组类
- 第九周【项目2-我的数组类】
- 第九周实践项目2-我的数组类
- 第九周项目二我的数组类
- 第九周项目3我的数组类
- 第九周 项目二-我的数组类
- 第九周项目2—我的数组类
- 第九周项目2-我的数组类
- 第九周项目(2)—我的数组类
- 三点顺序
- IOS设计: 图形性能分析
- C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
- 《Android 开发艺术探索》读书笔记五 IPC机制之Serialzable接口和Parcelable接口
- POJ2704 DP + 记忆化搜索 + 注意中间存储数据用long long不然WA
- 第九周项目三 我的数组类
- kruskal模板
- 网络编程_简单客户端和服务器实现
- Node.js开发入门(九)——使用AngularJS内置服务
- hive优化之------控制hive任务中的map数和reduce数
- HashMap的工作原理
- 输入一个字符串,计算字符串中子串出现的次数
- Node.js开发入门(十)——使用cookie保持登录
- Qt之图形(绘制文本)