Thursday, April 29, 2021

simple program using templates (OOP) (81)

#include<iostream>

using namespace std;

template <typename s> //here i make a template for a square function

s square(s x) 

{

s sq;

    sq=x;

    return sq*sq;

}

int main()

{

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

cout<<endl;

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

cout<<endl;

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

cout<<endl;

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

cout<<endl;

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

cout<<endl;

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

} 

No comments:

Post a Comment