2015年第六周项目二:我的数组类
来源:互联网 发布:js 基础类型 编辑:程序博客网 时间:2024/06/05 18:37
#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( ); //返回数组中的最大值};int MyArray::getValue(int i){ //获得数组中下标为i的元素的值 return arrayAddr[i];}int MyArray::getLen(){ //返回数组长度 return len;}int MyArray::getMax( ) { //返回数组中的最大值 return max;}MyArray::MyArray(int *a,int n){ len=n; arrayAddr=new int[n]; max=*a; for(int i=0;i<n;i++) { *(arrayAddr+i)=*(a+i); if(*(a+i)>*a) { *(a+i)=max; } }}MyArray::~MyArray(){ delete []arrayAddr;}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
- 2015年第六周项目二:我的数组类
- 第六周项目二:我的数组类
- 第六周——项目二我的数组类
- 第六周 项目二:我的数组类
- 第六周项目二:-我的数组类
- 第六周项目二—我的数组类
- 第六周项目二我的数组类
- 第六周项目二--我的数组类
- 第六周 项目二-我的数组类
- 第六周 项目二--我的数组类
- 第六周项目二——我的数组类
- 第六周项目二我的数组类
- 第六周项目二 我的数组类
- 第六周项目二 我的数组类
- 第六周项目二 我的数组类
- 第六周项目二之我的数组类
- 第六周 项目二 我的数组类
- 第六周 项目二-我的数组类
- UI 自定义视图 Label_TextField
- Java之美[从菜鸟到高手演变]之设计模式二
- live555接收实时视频流+ffmpeg解
- 我的第一篇博客
- POJ1423 HDU1018 Big Number【斯特林公式】【高精度】
- 2015年第六周项目二:我的数组类
- Android WebView属性设置
- mfc 自定义消息
- 发的哈佛
- [Project]Restful高性能服务平台
- 代码的艺术
- poj 1997 trie树
- -bash: make: command not found
- GUI