Showing posts with label Function. Show all posts
Showing posts with label Function. Show all posts

Tuesday, 1 May 2012

Program Of Call By Value Using C

#include<stdio.h>
#include<conio.h>


main()

{

int x,y,z;

clrscr();

printf("Enter First NUmber=");

scanf("%d",&x);

printf("Enter Second NUmber=");

scanf("%d",&y);

z=sum(x,y);

printf("\n Answer=%d",z);

getch();

}


{

int c;

c=a+b;

return c;
}

Program Of Call By Address Using c

#include<stdio.h>
#include<conio.h>

main()

{

int x,y,z;

clrscr();

printf("ENter First NUmber=");

scanf("%d",&x);

printf("ENter Second NUmber=");

scanf("%d",&y);

z=sum(&x,&y);

printf("\n Answer=%d",z);

getch();

}

{
int c;

c= *a + *b;

return c;

}

Program Of Call By Refrence in c

#include<stdio.h>
#include<conio.h>


main()

{

int x,y,z;

clrscr();

printf("ENter First NUmber=");

scanf("%d",&x);

printf("ENter Second NUmber=");

scanf("%d",&y);

z=sum(x,y);

printf("\n Answer=%d",z);

getch();

}


{

int c;

c= a + b;

return c;
}

Friday, 27 April 2012

Program Of Template Class In C++

#include<iostream.h> 

#include<conio.h>
template<class T> 

class add{ private: T a,b;
public:    
   void getdata(T x,T y) 
{  
 a=x; 
 b=y; 
}
void display() 
{
cout<<"a="<<a; 
cout<<"b="<<b;
}
};
void main()
{ 
add <int> a1;
clrscr(); 
a1.getdata(4,6);
a1.display();
add <float> a2;
a2.getdata(3.4,4.5);
a2.display();
getch();
}

Program To Remove The Problems of Function Overloading



#include<iostream.h>
#include<conio.h>
template<class T>
class add
{
private:
T a;
public:
       void getdatab(T x)
{
 a=x;
}
void displayb()
{
cout<<"a="<<a;
}
};
template<class T>
{
private:
T b;
public:
       void getdatad(T y)
{
 b=y;
}
void displayd()
{
cout<<"\n b="<<b;
}
};
void main()
{
sub <int> a1;
clrscr();
a1.getdatab(4);
a1.displayb();
a1.getdatad(6);
a1.displayd();
getch();
}