资源简介
c编程练习题目及答案(2).zip

代码片段和文件信息
#include
using namespace std;
class MyArray
{
private:
int n;
int *p;
public:
MyArray( int x);
~MyArray();
int& operator[](int x);
//友元函数重载运算符
friend ostream& operator<<(ostream&os MyArray&intArray)
{
int i;
for(i=0;i {
os< }
return os;
}
};
//构造函数,初始化
MyArray::MyArray( int x)
{
n=x;
p=new int[n];
}
//析构函数,删除动态数组
MyArray::~MyArray()
{
delete[] p;
}
//重载[]判断当[]内下标大于n时,显示溢出
int& MyArray::operator[]( int x)
{
static int i=0;
if( x>=n || x<0)
{
cout<< “下标为“<< x <<“溢出“< return i;
}
return p[x];
}
//主函数
void main()
{
MyArray intArray(10); // Here 10 is the number of intArray‘s elements.
for (int i=0; i<10; i++)
intArray[i] = i * i; // Initialize the intArray‘s elements
cout << intArray; // Print every element in the intArray
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 961 2013-05-11 15:12 11.cpp
文件 1098 2013-05-11 15:57 22.cpp
文件 1740 2013-05-11 17:30 33.cpp
文件 2175 2013-05-11 18:23 44.cpp
文件 614 2013-05-10 15:00 Exercise 1:MyArray.txt
文件 487 2013-05-10 15:10 Exercise 2:Goods.txt
文件 851 2013-05-10 15:02 Exercise 3:MyString.txt
文件 460 2013-05-10 15:05 Exercise 4:InternetURL with MyString.txt
- 上一篇:mvstats包、数据
- 下一篇:Modbus主从站仿真程序
相关资源
- PID_AutoTune_v0.rar
- vspd7.2.308.zip
- 价值2k的H漫画小说系统
- Pythonamp;课堂amp;笔记(高淇amp;400;集第
- ddos压力测试工具99657
- UML建模大全
- 开源1A锂电池充电板TP4056原理图+PCB
- m1卡 ic卡可选择扇区初始化加密软件
- TSCC.exe
- FTP课程设计(服务端+客户端)
- 计算机图形学 边填充算法实现代码
- 电力系统潮流计算程序集合
- oracle数据迁移项目实施方案
- Web Api 通过文件流 文件到本地
- Visio图标-最新最全的网络通信图标库
- Spire API文档
- OpenGL参考手册
- Python中Numpy库最新教程
- SPD博士V5.3.exe
- 直流无刷电机方波驱动 stm32 例程代码
- layui后台管理模板
- 仿知乎界面小程序源代码
- 云平台-阿里云详细介绍
- photoshop经典1000例
- scratch垃圾分类源码(最终版本).sb
- IAR ARM 7.8破解
- TI CCS V5.4 安装步骤及破解文件
- 松下plc FP-XH的驱动
- 局域网硬件信息收集工具
- 加快Windows XP操作系统开机速度
评论
共有 条评论