You have been developing a small commercial Software for numeric operations. You are working on the calculation of areas and volume of different shapes. Based on your software complete these tasks:
a) Create a function template named as shape() that accepts three arguments in such a way that first and second will be the dimension like base and height and the third will be the name of the shape. The shape() function displays the dimension values and the area of the shape. The function returns the area to the calling program; the area is the same data type as the parameter. [Note: Design a main program such that, it input the values of only those shapes whose area is computable on the bases of base and height only]
b) Create another function template named as show_master()that accepts two arguments. The first is index and the second argument is an array of 10 values. The show_master() function will returns the specified index value.
#include <iostream>
using namespace std;
template <class T>
T shape(T a, T b, T dName) {
T area;
cout<<a<<"\t"<<b<<"\n";
area=a*b;
cout<<"\nArea= "<<area;
return area;
}
template <class T>
T show_master(T i, T arr[10]) {
T n=arr[i];
return n;
}
int main()
{
int l,w;
shape<int>(l,w,1);
return 0;
}
Comments
Leave a comment