16th Week OJ Brush question--problem K: Fill in the Blanks: class template---to find the maximum value of an array

Source: Internet
Author: User

The Description class template---The maximum value of an array to find the maximum value of an element in an array, with an array size of 10. An array element type (implemented with a class template) as a parameter to a class template. Input

10 Data of type int

10 Data of type double

10 Char type data

Model 10gestring Data

Output

Maximum value of 10 int type data

Maximum value of 10 double type data

Maximum value of 10 char data

Maximum value of 10 string type data

Sample Input
1 3 5 7 9 8 6 4 2 01.2 3.4 5.66 7.8 9.9 13.4-2.5 6.7 0-10a B 1 2 +  -A b p Zguo Li   
Sample Output
913.4pzhou
/* All rights reserved.  * File name: Test.cpp * Chen Dani * Completion Date: June 27, 2015 * Version number: v1.0 * * #include <iostream> #include <string>using namespace  Std;template <class t>class Array_max//Declaration class Template {public://The following 3 behavior member function prototype declaration void Set_value (    );    Sets the value of the array element T Max_value ();         Find the largest element in the array private:t array[10];               T-type array T-Max;    Max is used to hold the maximum value in the array};template <class t>void array_max<t>::set_value () {int i;    for (i=0;i<10;i++) {cin>>array[i];    }}template <class t>t array_max<t>::max_value () {int i;    MAX=ARRAY[0];    for (i=0; i<10; i++) {if (Array[i]>max) max=array[i]; } return max;      int main () {array_max<int> arrmax_int;//Defines the object Arrmax_int, in which the array element type is integer arrmax_int.set_value ();  Call Arrmax_int's Set_value function, enter a value to the array element Cout<<arrmax_int.max_value () <<endl; Call Arrmax_int's Max_value function to find the maximum value in the array element array_max<double>   arrmax_double;      Defines the object arrmax_double, in which the array element type is a double-arrmax_double.set_value ();  Call Arrmax_double's Set_value function, enter a value to the array element Cout<<arrmax_double.max_value () <<endl; Call Arrmax_double's Max_value function to find the maximum value of the array element array_max<char> Arrmax_char;      Defines the object Arrmax_char, in which the array element type is character-type arrmax_char.set_value ();  Call Arrmax_char's Set_value function, enter a value to the array element Cout<<arrmax_char.max_value () <<endl; Call Arrmax_char's Max_value function to find the maximum value of the array element array_max<string> arrmax_string;      Defines the object arrmax_string, in which the array element type is string-type arrmax_string.set_value ();  Call Arrmax_string's Set_value function, enter a value to the array element Cout<<arrmax_string.max_value () <<endl; Call arrmax_string, the Max_value function, to find the maximum value of the array element, return 0;}
Learning experience: Good, continue to work hard, hard to understand a type of problem, it must be useful!!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

16th Week OJ Brush question--problem K: Fill in the Blanks: class template---to find the maximum value of an array

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.