错在哪里了呢

来源:百度知道 编辑:UC知道 时间:2024/06/07 18:23:38
#include <iostream>
using namespace std;
class MyArray
{
public:
int array[10];
int length;
public:
MyArray( int len);
~MyArray();
void input();
void display();
};

MyArray::MyArray(int len) : length(len)
{}
MyArray::~MyArray()
{}
void MyArray::input()
{
cout << "请输入: " << length << " 个数字: ";
cout<<endl;
for (int i=0; i<length; ++i)
cin >> array[i];
}

void MyArray::display()
{
for(int i=0;i<length;i++)
cout<<array[i]<<endl;
cout << endl;
}

class averArray : public MyArray
{
public:
averArray(int len) : MyArray(len)
{
display();
}
void display()
{
input();
MyArray::display();
float avg = 0;
for (int i=0; i<length;i++)
avg += array[i];

#include <iostream>
using namespace std;
class MyArray
{
public:
int array[10]; //建议动态分配内存。析构用虚析构,delete内粗就可以了
int length;
public:
MyArray( int len);
~MyArray();
void input();
void display();
};

MyArray::MyArray(int len) : length(len)
{}
MyArray::~MyArray()
{}
void MyArray::input()
{
cout << "请输入: " << length << " 个数字: ";
cout<<endl;
for (int i=0; i<length; ++i)
cin >> array[i];
}

void MyArray::display()
{
for(int i=0;i<length;i++)
cout<<array[i]<<endl;
cout << endl;
}

class averArray : public MyArray
{
public:
averArray(int len) : MyArray(len)
{
display();
}
void display()
{
input();
MyArray::display();
float avg = 0;