一、试验内容
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++)
{
cout << *p << " ";
}
cout << endl;
}
void MyArray::Input()
{
cout << "请从键盘输入" << l
5万+


&spm=1001.2101.3001.11974&articleId=121895822&d=1&t=3&u=1884f05ee367429ba5b5a2711c5c04dc)

被折叠的 条评论
为什么被折叠?



