Home > Back-end >  Inheritance and derived
Inheritance and derived

Time:10-11

1. Short-answer questions
Orderly Array SortArray class 1, the Array orderly Array SortArray derived class, SortArray in an orderly Array of class,

Known Array class definition is as follows (not allowed to add a member function) :

The class Array

{

Public:

Array ();//constructor, initialized to an empty array (length 0)

Int Length ();//get the actual length of the array

Double the Get (int pos);//get the data value of the subscript for pos element in

Void Insert (int pos, double x);//in the subscript pos insert x

Void the Display ();//output linear table

Private:

Double data [MaxSize];//storage elements (MaxSize constants)

int length;//the actual length of the array

};



SortArray classes are defined as follows (are not allowed to add member functions) :

The class SortArray: private Array

{

Public:

SortArray ();

Int Length ();//get the actual length of the array

Double the Get (int pos);//get the data value of the subscript for pos element in

Void the Display ();//output linear table

Void Insert (double x);/increasing/insert orderly array x, the sequence is ordered

};

Please implement Array and SortArray class member function, the main type in several real Numbers, ends with a 0, utilizing SortArray Insert Insert their data, the function of an orderly sequence, reusing the Display function output orderly sequence, code (not allowed to change) as follows:

Int main ()

{

SortArray sa;

Double num.

While (1)

{

Cin> Num.

If (fabs (num) & lt; E=1-6) break;

Try

{

Sa. Insert (num);//

}

The catch (char * message)

{

cout
}

}

Sa. The Display ();



return 0;

}

Input: 2.5 6.7 8.3 2.8 6.53 6.82 7.33 0

Output:

The length: 7

The elements: 2.5 2.8 6.53 6.7 6.82 7.33 8.3

Input: 2, 3, 4, and 12 1 3 0

Output:

The length: 7

The elements: 1 2 3, 3, 4, 12 23



Input:

5.6 4.3 12.6 65.3 67.3 7.89 0

Output:

The length: 6

The elements: 4.3 5.6 7.89 12.6 65.3 67.3





Submit

How to write???????
  • Related