第9周项目2-我的数组类
来源:互联网 发布:mac更新战网agent卡住 编辑:程序博客网 时间:2024/05/16 15:41
/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:text.cpp
*作者:陈腾
*完成日期:2016年6月09日
*版本号:v1.0
问题描述:我的数组类
*/
#include<iostream>
using namespace std;class MyArray
{
private:
int *arrayAddr;
int len;
int max;
public:
MyArray(int *a, int n);
~MyArray();
int getValue(int i);
int getLen();
int getMax( );
};
MyArray::MyArray(int *a,int n)
{
arrayAddr=a;
len=n;
}
MyArray::~MyArray(){}
int MyArray::getValue(int i)
{
int a;
a=arrayAddr[i];
return a;
}
int MyArray::getLen()
{
return len;
}
int MyArray::getMax()
{
int b=0,i;
for(i=0;i<len;i++)
{
if(b<*(arrayAddr+i))
{
b=*(arrayAddr+i) ;
}
}
max=b;
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
- 第9周-项目2-我的数组类
- 第9周项目2:我的数组类
- 第9周项目2 我的数组类
- 第9周项目2-我的数组类
- 第9周项目2—我的数组类
- 第9周项目2-我的数组类
- 第9周项目2- 我的数组类
- 第9周项目2-我的数组类
- C++第9周项目 数组和指针 【项目2-我的数组类】(复习新版)
- 第9周项目二-我的数组类
- 第6周项目2我的数组类
- 第6周项目2-我的数组类
- 第5周项目2-我的数组类
- 第6周项目2-我的数组类
- 第6周项目2-我的数组类
- 2015-第6周项目2-我的数组类
- 第6周项目2我的数组类
- 第9周项目2——我的数组类
- BMP图像编码格式
- LaTeX输入范式
- Codeforces Round356 div2 680AB 679ABC
- javascript数组详解
- Quartz2D使用
- 第9周项目2-我的数组类
- hdu3449(有限制条件的01背包)
- LaTeX集合运算相关命令
- KDE 桌面Konsole 光标错位解决方法
- LaTeX技巧
- Loader文件内外加载 信号槽方法属性
- unity5 动态创建时,比例保持不变
- SQLite的命令行操作
- 关于win8.1开热点