第9周项目2——我的数组类
来源:互联网 发布:魅可mac加盟电话 编辑:程序博客网 时间:2024/05/17 03:36
/**Copyright (c) 2016,烟台大学计算机学院*All rights reserved.*文件名称 :*作 者 : 刘云*完成日期 : 2016年4月24号*版 本 号 : v1.0**问题描述 : 阅读下面程序,补足未完成的注释*输入描述 : 无*程序输出 :*/#include<iostream>using namespace std;class MyArry{private: int *arrayAddr; //保存一个有len个整形元素的数组的首地址 int len; //记录动态数组的长度 int max; //动态数组中的最大值(并非动态数组中必须要的数据成员)public: MyArry(int *a,int n); ~MyArry(); int getValue(int i); //获得数组中下标为i的元素的值 int getLen(); //返回数组长度 int getMax(); //返回数组中的最大值}; //下面是各成员函数的定义 MyArry::MyArry(int *a,int n) { int i; arrayAddr=new int[n]; len=n; for(i=0;i<n;i++) arrayAddr[i]=a[i]; } int MyArry::getValue(int i) { return arrayAddr[i]; }MyArry::~MyArry() { delete []arrayAddr; }int MyArry::getLen() { return len; } int MyArry::getMax() { int i,max=arrayAddr[0]; for(i=1;i<len;i++) { if(arrayAddr[i]>max) max=arrayAddr[i]; } return max; }int main(){ int b[10]={75,99,90,93,38,15,5,7,52,4}; MyArry 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}; MyArry 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
- 第9周项目2—我的数组类
- 第9周-项目2-我的数组类
- 第9周项目2:我的数组类
- 第9周项目2 我的数组类
- 第9周项目2-我的数组类
- 第9周项目2-我的数组类
- 第9周项目2- 我的数组类
- 第9周项目2-我的数组类
- 第9周项目2——我的数组类
- C++第9周项目 数组和指针 【项目2-我的数组类】(复习新版)
- 第6周项目2——我的数组类
- 第9周项目二-我的数组类
- 第6周项目2我的数组类
- 第6周项目2-我的数组类
- 第5周项目2-我的数组类
- 第6周项目2-我的数组类
- 第6周项目2-我的数组类
- 2015-第6周项目2-我的数组类
- 二维码使用原理
- Common Multiple and Least Common Multiple(LCM)
- The 13th Zhejiang Provincial Collegiate Programming Contest
- svn
- 案例分析:福彩双色球
- 第9周项目2——我的数组类
- [JZOJ4468][JSOI2016?]轻重路径
- 专题二 1012
- Space Shooter之子弹和敌人碰撞检测、爆炸特效以及敌人的运动
- putchar
- poj 1952buy low, buy lower
- hdoj 5671 Matrix 【思维】
- C++作业4
- 计算文本的实际大小