Problem A: Array Class (II)

Source: Internet
Author: User
Tags array length

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 NHintappend Code

#include <iostream>
using namespace Std;
Template<class t>
Class Array
{
Private
T *sss;
int si;
Public
Array (int L): Si (l) {sss=new t[si];}
~array () {if (sss!=null) delete []sss;}
int size () {return si;}
void put (int n)
{
int i,j;
for (i=0;i<si-1;i++)//next to each other, the last one is not.
{
for (j=i+1;j<si;j++)//From the next start, to the last
{
if (Sss[i]<sss[j])
{
T T=sss[i];
SSS[I]=SSS[J];
sss[j]=t;
}
}
}
if (N&GT;SI)
N=si;
cout<<sss[0];
for (int i=1;i<n;i++)
cout<< "" <<sss[i];
cout<<endl;
}
t& operator[] (int n)//Less a reference, I go
{
return sss[n];
}
};
int main ()
{
int cases, Len;
CIN >> cases;
for (int CA = 1; CA <= cases; ca++)
{
Cin >> Len;
if (ca% 3 = = 0)
{
Array<char> Chr_arr (len);
for (int i = 0; i < chr_arr.size (); i++)
CIN >> Chr_arr[i];
Chr_arr.put (10);
}
if (ca% 3 = = 1)
{
Array<int> Int_arr (len);
for (int i = 0; i < int_arr.size (); i++)
CIN >> Int_arr[i];
Int_arr.put (10);
}
if (ca% 3 = = 2)
{
Array<double> Dbl_arr (len);
for (int i = 0; i < dbl_arr.size (); i++)
CIN >> Dbl_arr[i];
Dbl_arr.put (10);
}
}
}

Problem A: Array Class (II)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.