Monday, 16 February 2015

Function In c++(practicla 2)

Practical -2

  •  Wite a program to demonstrate inline function.
#include<iostream>
using namespace std;

inline float max1(float a,float b);
int main()
{
    float a,b;
    float result;
    cout<<"write the value of a";
    cin>>a;
    cout<<"write the value of b";
    cin>>b;
     result=max1(a,b);
    cout<<"max("<<a<<","<<b<<"):  "<<endl;
    cout<<result<<endl;

    return(0);

}
inline float max1(float a,float b)
{
    return(  (a>b)? a:b );
}

  • Wite a program to demonstrate overloading of function. 

#include<iostream>
using namespace std;
void test(int);           //function 1
void test(int ,float);   //function 2
void test(float);        //function 3
int main()
{

    int a=50;
    float b=23.26;
    test(a);   //call fun1
    test(b);    //call fun3
    test(a,b);  //call fun2

    return(0);


}

void test(int a )
{
    cout<<"Integer number: "<<a<<endl;
}

void test(float var)
{
    cout<<"Float number: "<<var<<endl;
}

void test(int var1, float var2)
{
    cout<<"Integer number: "<<var1<<endl;
    cout<<" And float number:"<<var2<<endl;
}
 

No comments:

Post a Comment