Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using template to define a class which has two member functions: sorting() and m

ID: 3824648 • Letter: U

Question

Using template to define a class which has two member functions: sorting() and max_min_mean(). The 1st function take an array parameter in template data type and sorts the data, the 2nd function also take an array parameter in template data type and find the max, min, and mean values of the array and print them. In main(), declare one int array and one double array and assign the array with integer and real numbers, then declare two object variables using the class defined above and initialize one’s template type to int and the other to double. After that, complete: (1) use the first object variable’s member function sort() to sort the int array and print the sorted result, and then use the first object varilable’s member function max_min_mean() to output the three key values of the int array; (2) use the 2nd object variable’s member function sort() and max_min_mean() to do the same as in (1) to the double array; (note, you can choose either bubble or selection sort).

Explanation / Answer

//EXAMPLE PROGRAM FOR TEMPLATE FUNCTIONS WITH MULTIPLE
//TEMPLATES
#include<iostream.h>
#include<conio.h>
template <class A, class B>
A add(A x,B y)
{
return x+y;
}
void main()
{
int m;
float f;
long l;
clrscr();
cout<<"ENTER AN INTEGER "<<endl;
cin>>m;
cout<<"ENTER A FLOAT "<<endl;
cin>>f;
cout<<"ENTER A LONG "<<endl;
cin>>l;
clrscr();
cout<<"INTEGER VALUE IS "<<m<<endl;
cout<<"FLOAT VALUE IS "<<f<<endl;
cout<<"LONG VALUE IS "<<l<<endl;
cout<<"SUM OF INTEGER AND FLOAT "<<add(m,f)<<endl;
cout<<"SUM OF FLOAT AND INTEGER "<<add(f,m)<<endl;
cout<<"SUM OF LONG AND FLOAT "<<add(l,f)<<endl;
cout<<"SUM OF FLOAT AND LONG "<<add(f,l)<<endl;
cout<<"SUM OF LONG AND INT "<<add(l,m)<<endl;
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote