Object-Oriented Programming Practice 6 (class and object) Time Limit: 1000 ms memory limit: 65536 K This topic describes how to use a class member function to input five integer array elements, sort them from small to large, and output the sorted array elements. Input 5 array elements. Output the results of sorting 5 array elements in ascending order. (There is no space or line feed after the last number) Example Input
8 9 1 5 4
Sample output
1 4 5 8 9
Prompt source zlh sample program
# Include <iostream> using namespace STD; // define the class type class shuzu {// define the private part private: int A [5]; // define the public part public: void input () // input member function {for (INT I = 0; I <5; I ++) CIN> A [I] ;} void Pai () // sorting member function {int I, j, P; // sort for (I = 0; I <4; I ++) for (j = 0; j <4-I; j ++) if (a [J]> A [J + 1]) {P = A [J]; A [J] = A [J + 1]; A [J + 1] = P ;}} void output () // output member function {cout <A [0]; for (INT I = 1; I <5; I ++) cout <"" <A [I] ;}; // always forget this semicolon // main function int main () {class shuzu s; S. input (); S. pai (); S. output (); Return 0 ;}
Sdut Object-Oriented Programming Practice 6 (class and object)