Requirements: data members are private, a member function is public, each function corresponds to a member function,
Use an array to simulate a collection, using an integer variables to record the number of elements in the collection,
CodePudding user response:
This#include
using namespace std;
Const int inf=0 x3f3f3f3f;
The class Aggregate {
Private:
Int s [1005], ls, MAX, MIN,
Public:
Aggregate () {//initializes the
Ls=0, MAX=- inf, MIN=inf;
}
Void Push (int x) {//add
If (Judge (x)==false) {
MAX=MAX (MAX, x);
MIN=MIN (MIN, x);
S [ls++]=x;
}
}
Void the Sort () {//sorting
Sort (s, s + ls);
}
Bool Judge (int x) {//whether the element in the collection
for(int i=0; i
return true;
return false;
}
Int Max () {
Cout<" The maximum is: "& lt;
Int the Min () {
Cout<" Minimum value is: "& lt;
Void Cout () {//collection element
for(int i=0; i
};
Int main ()
{
Aggregate s;
For (int I=5; i>=1; - I)
Supachai panitchpakdi ush (I);
S.C out ();
S.S ort ();
S.C out ();
If (s.J udge (6)) cout<" 6 elements in the collection "& lt;
S.M ax ();
S.M in ();
return 0;
}