The description encapsulates a template array class for storing array and processing related functions, and supports the following operations: 1. Array::array (int L) Construction method: Creates a group object of length L. 2. Array::size () Method: Returns the number of elements in an Array object. 3. Array::p ut (int n) method: Output The first n large elements in order from large to small, and output all elements from large to small if the array length is less than N. 4. Subscript operator: Returns the element to which the subscript refers. -----------------------------------------------------------------------------you design a template array class array so that the main () function works correctly. The function call format is shown in append.cc. The main () function has been given in append.cc.
The first integer n of input inputs, indicating that there are n sets of test data. Each subsequent line begins with an integer k, indicating that there are k elements of the same type followed. There are three types of array elements: integers, floating-point numbers, and characters, and appear in fixed sequential intervals.
Output the input array, by value from large to small outputs the first 10 elements, if the input less than 10 output. Each row of data corresponds to one output. The format is shown in Sample.
Sample Input3 1 2 3 4 5 6 7 8 9 0 5 1.1 2.2 3.3 4.4 5.5Sample Output9 8 7 6 5 4 3 2 1 0 5.5 4.4 3.3 2.2 1.1 Y X W V U T S R P NHINT Append codeappend.cc,
1#include <iostream>2#include <algorithm>3 using namespacestd;4Template <classT>5 classarray{6 Private:7S Mp;8 intlength;9 Public:TenArray (intl) One { Ap=Newt[l+1]; -Length=l; - } the voidPutintN) - { - inti; - for(intk=0; k<length-1; k++) + for(intj=k+1; j<length;j++) - if(p[k]<P[j]) + swap (p[k],p[j]); A at if(n>=length) - { - for(i=0; i<length-1; i++) -cout<<p[i]<<" "; -cout<<p[i]<<Endl; - } in Else - { to for(i=0; i<n-1; i++) +cout<<p[i]<<" "; -cout<<p[i]<<Endl; the } * } $ intsize ()Panax Notoginseng { - returnlength; the } +t&operator[](intN) A { the returnP[n]; + } -Friend istream&operator>> (IStream & is, Array &c) $ { $ T B; - is>>b; - return is; the } -~Array ()Wuyi { the Delete[]p; - } Wu }; - About intMain () $ { - intcases, Len; -CIN >>cases; - for(intCA =1; CA <= cases; ca++) A { +CIN >>Len; the if(ca%3==0) - { $array<Char>Chr_arr (len); the for(inti =0; I < chr_arr.size (); i++) theCIN >>Chr_arr[i]; theChr_arr.put (Ten); the } - if(ca%3==1) in { thearray<int>Int_arr (len); the for(inti =0; I < int_arr.size (); i++) AboutCIN >>Int_arr[i]; theInt_arr.put (Ten); the } the if(ca%3==2) + { -array<Double>Dbl_arr (len); the for(inti =0; I < dbl_arr.size (); i++)BayiCIN >>Dbl_arr[i]; theDbl_arr.put (Ten); the } - } -}
Experimental 6:problem B: Array Class (II)