一、试验内容
1.将示例代码用电脑运行,并展示运行结果。
2.声明一个SortArray继承类MyArray,在类中定义一个函数,具有将输入的整数从小到大进行排序的功能。
二、试验步骤
1.运行示例代码,并运行
#include<iostream>
#include<string>
using namespace std;
class MyArray
{
public:
MyArray(int leng);
~MyArray();
void Input();
void Display(string);
protected:
int* alist;
int length;
};
MyArray::MyArray(int leng)
{
if (leng <= 0)
{
cout << "error length";
exit(1);
}
length = leng;
alist = new int[length];
if (alist == NULL)
{
cout << "assign failure";
exit(1);
}
cout << "MyArray类对象已创建" << endl;
}
MyArray::~MyArray()
{
delete[]alist;
cout << "MyArray类对象已撤销" << endl;
}
void MyArray::Display(string str)
{
int i;
int* p = alist;
cout << str << length << "个整数";
for (i = 0; i < length; i++, p++)
{
cou