Thursday, April 29, 2021

simple program using templates (OOP) (82)

#include<iostream>

using namespace std;

template <typename c> //here i make a template for a cube function

c cube(c y) 

{

c cub;

    cub=y;

    return cub*cub*cub;

}

int main()

{

cout<<"after passing the integer value as a argument in a function:"<<endl;

cout<<endl;

cout<<"the cube of interger data type: "<<cube(4)<<endl;

cout<<endl;

cout<<"after passing the float value as a argument in a function:"<<endl;

cout<<endl;

cout<<"the cube of float data type: "<<cube(2.5)<<endl;

cout<<endl;

cout<<"after passing the double value as a argument in a function:"<<endl;

cout<<endl;

cout<<"the cube of double data type: "<<cube(9.8)<<endl;

} 

No comments:

Post a Comment