第六周实验报告 任务二
来源:互联网 发布:js contain 编辑:程序博客网 时间:2024/05/17 05:17
源程序:
#include<iostream>using namespace std;class A {private:int a;public:A() {a=0;} A(int aa):a(aa){} //定义构造函数,用参数aa初始化数据成员a};void main() {A *p;//定义类A的指针对象pp = new A(6); //用p指向动态对象并初始化为整数system("pause");}#include<iostream>using namespace std;class A {private:int * a; int n; int MaxLen;public:A(): a(0), n(0), MaxLen(0) {}A(int *aa, int nn, int MM);~A();int GetValue(int i) {return a[i];} };A::A(int *aa, int nn, int MM){n=nn;MaxLen=MM;if(n>MaxLen) exit(1);a=new int[MaxLen];for(int i = 0; i < n; ++ i){a[i] = aa[i]; //以i为循环变量把aa数组中每个元素值传送给a数组的对应元素中}}A::~A(){delete []a;}//析构函数的类外定义,释放指针型数据a所指向的空间void main(){int b[10] = {1,2,3,4,5,6,7,8,9,10};A r(b,10,10);int i,s = 0;for(i = 0; i < 10; ++ i){s = s + r.GetValue(i);}//以i为循环变量,把r对象的a数据成员中的每个元素值依次累加到s中cout<<"s = "<< s <<endl;system("pause");}
截图:
这个任务一开始有点摸不到头脑····后来一步一步做下去····不懂得就到百度上去查···结果一不小心居然找到了原题···罪过罪过···不过看明白了才做的~
- 第六周实验报告 任务二
- C++程序设计实验报告(四十四)---第六周任务二
- 第六周实验报告(任务二)【补充代码】
- 第六周实验报告二
- 第六周实验报告 任务一
- 《第六周实验报告任务1》
- 《第六周实验报告任务2》
- 《第六周实验报告任务3》
- 《第六周实验报告任务4》
- 第六周实验报告(任务1)
- 第六周实验报告(任务2)
- 第六周实验报告(任务3)
- 第六周实验报告 任务四
- 第六周实验报告(任务4)
- 第六周实验报告(任务5)
- 第六周实验报告任务1
- 第六周实验报告任务2
- 第六周实验报告任务3
- 解决.net类SoundPlayer播放.wav格式音频的错误
- B/S架构下applet,JNI实现对客户端硬件的读取
- Quartz的cron表达式
- 海量用户积分排名算法探讨
- java applet调用JNI
- 第六周实验报告 任务二
- Apple VS Google:Google完败于产品设计
- wordpress博客和z-blog博客自动留言表单填写方法
- 图片滚动
- 三国杀-周泰不屈的概率计算
- onConfigurationChanged 未被 调用 onConfigurationChanged not getting called
- 如果获取条形基础的基线?
- 大牛,从今天开始
- 装箱与拆箱的性能问题