0% found this document useful (0 votes)
305 views

Q1. Output: Write A Function Template That Finds The Minimum Value in The Array and Return It

The document contains 3 code templates: 1. A function template to find the minimum value in an array and return it. 2. A function template to accept 3 parameters and display them in reverse order. 3. A class template to input values into an array, accept an index, and display the value at that index.

Uploaded by

Ahmad Mahmood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
305 views

Q1. Output: Write A Function Template That Finds The Minimum Value in The Array and Return It

The document contains 3 code templates: 1. A function template to find the minimum value in an array and return it. 2. A function template to accept 3 parameters and display them in reverse order. 3. A class template to input values into an array, accept an index, and display the value at that index.

Uploaded by

Ahmad Mahmood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

TEMPLATES

Q1.Write a Function template that finds the minimum value in the array and return it.
#include<iostream>
using namespace std; Output
Enter five integer:
template<class Type> 1
Type Max(Type a[ ],int I) 2
{ 3
Type max=a[0]; 4
for(int i=0;i<I;i++) 5
Maxmium value:5
if(a[i]>max)
Enter five floating point number:
max=a[i];
1.2
return max;
3.4
} 4.5
main() 6.7
{ 8.9
system("cls"); Maximum value: 8.9
int n[5],m,i;
float avg[5],am;
cout<<"Enter five integer:"<<endl;
for(i=0;i<5;i++)
cin>>n[i];
m=Max(n,5);
cout<<"Maximum value :"<<m<<endl;
cout<<"Enter five floating point number :"<<endl;
for(i=0;i<5;i++)
cin>>avg[i];
am=Max(avg,5);
cout<<"Maximum value:"<<am<<endl;}
Q2.Write a Function template that accept three parameter and display them in reverse order.
#include<iostream>
using namespace std;
template <class Type>
void Reverse(Type a, Type b, Type c)
{ Output
cout<<"The value in reverse order:"<<endl;
cout<<c<<" "<<b<<" "<<a<<endl; Enter three integer:
12 3 2
The value in reverse order:
2 3 12
Enter three Floating point
}
int main()
{
int x,y,z;
float d,e,f;
cout<<"Enter three integer:"<<endl;
cin>>x>>y>>z;
Reverse(x,y,z);
cout<<"Enter three Floating point number :"<<endl;
cin>>d>>e>>f;
Reverse(d,e,f);
}
Q3.Write a class template that input the index of the array and display the value in the specific
index
#include<iostream>
using namespace std; Enter five integers:
template<class Type> 23456
class Test{ Enter an index:
private: 0
Type arr[5]; The value at required index : 2
public:
void input() Enter five characters :
{ ahmad
for(int i=0;i<5;i++) Enter an index:
cin>>arr[i]; 1
} The value at required index: h
void show()
{
int i;
cout<<" Enter an index:"<<endl;
cin>>i;
cout<<"The value at required index:"<<arr[i]<<endl;
}
};
int main()
{
Test <int>x;
Test<char>y;
cout<<"Enter five integers:"<<endl;
x.input();
x.show();
cout<<"\nEnter five Characters:"<<endl;
y.input();
y.show();
}

You might also like