Home > Back-end >  The program design for help
The program design for help

Time:09-25

Adopts object-oriented design method, design an integer collection class, element has enter the collection, sorting, add elements, whether elements in the collection, maximum value, minimum value, the output display set elements such as function,
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; iIf (s==x [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; iCoutCout}
};
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; The else cout<" Element six is not in the collection "& lt; If (s.J udge (5)) cout<" Five elements in the collection "& lt; The else cout<" Elements may not in the collection "& lt; Supachai panitchpakdi ush (0);
S.M ax ();
S.M in ();
return 0;
}
  • Related