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]
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<typename type>
type shape(type base, type height, string name){
cout<<"Name: "<<name<<endl;
cout<<"Base: "<<base<<"\nHeight: "<<height<<endl;
cout<<"Area: "<<base * height<<endl;
return base * height;
}
template<typename type>
type show_master(int i, type array[10]){
return array[i];
}
int main(){
string triangle = "triangle", rectangle = "rectangle";
shape<float>(8, 4, triangle);
shape<int>(5, 5, rectangle);
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
cout<<show_master<int>(5, arr);
return 0;
}
Comments
Leave a comment