0% found this document useful (0 votes)
1 views

Devus 2

Uploaded by

mdevayani83
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Devus 2

Uploaded by

mdevayani83
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Devayani MM

2313711058011

CALLBY REFERENCE (METHOD 2)


#include<iostream.h>
#include<conio.h>
void main()
{
int x1,x2;
void swap(int *,int *);
clrscr();
cout<<"enter two integers values:";
cin>>x1>>x2;
clrscr();
cout<<"PROGRAM TO PERFORM CALL BY REFERENCE(METHOD 2)"<<endl;
cout<<"NUMBER 1 AND NUMBER 2 BEFORE FUNCTION
CALL:"<<endl<<x1<<endl<<x2<<endl;
swap(&x1,&x2);
cout<<"NUMBER 1 AND NUMBER 2 AFTER FUNCTION CALL:"<<endl<<x1<<endl<<x2<<endl;
}
void swap(int *a,int *b)
{
int t;
t=*a;
*a=*b;
*b=t;
cout<<"NUMBER 1 AND NUMBER 2 INSIDE THE FUNCTION:"<<endl<<a<<endl<<b<<endl;

}
Devayani MM
2313711058011

RETURN BY REFERENCE
#include<iostream.h>
#include<conio.h>
void main()
{
int x1,x2;
int & max(int&,int&);
clrscr();
cout<<"enter two integers values:";
cin>>x1>>x2;
clrscr();
cout<<"NAME:PADMASRI" <<endl<<"REGNO:2313711058034"<<endl;
cout<<"PROGRAM TO PERFORM RETURN BY REFERENCE"<<endl;
cout<<"NUMBER 1 AND NUMBER 2:"<<endl<<x1<<endl<<x2<<endl;
cout<<"MAXIMUM OF TWO NUMBERS IS "<<max(x1,x2)<<endl;
}
int & max(int &a,int &b)
{
if(a>b)
return a;
else
return b;
}
Devayani MM
2313711058011

DEFAULT FUNCTION
#include<iostream.h>
#include<conio.h>
void main()
{
int amt,y;
float r;
double interest(int,float,int years=1);
clrscr();
cout<<"enter amount, rate of interest and no of years:";
cin>>amt>>r>>y;
clrscr();
cout<<"PROGRAM TO ILLUSTRATE DEFAULT FUNCTION"<<endl;
cout<<"AMOUNT:"<<amt<<endl;
cout<<"RATE OF INTEREST:"<<r<<endl;
cout<<"NO OF YEARS:"<<y<<endl;
cout<<"INTEREST WITHOUT DEFAULT YEARS:"<<interest(amt,r,y)<<endl;
cout<<"INTEREST WITH DEFAULT YEARS:"<<interest(amt,r)<<endl;
}
double interest(int a,float roi,int years)
{
float s_interest;
s_interest=a*(roi/100)*years;
return s_interest;
}
Devayani MM
2313711058011

FUNCTION OVERLODING
#include<iostream.h>
#include<conio.h>
int add(int a,int b)
{
return (a+b);
}
int add(int a,int b,int c)
{
return (a+b+c);
}
double add(int a,double b)
{
return (a+b);
}
double add(double a,int b)
{
return (a+b);
}
double add(double a,double b)
{
return (a+b);
}
double add(double a,double b,double c)
{
return (a+b+c);
}
void main()
{
int x1,x2,x3;
double y1,y2,y3;
int add(int,int);
int add(int,int,int);
double add(int,double);
double add(double,int);
double add(double,double);
double add(double,double,double);
clrscr();
cout<<"enter three integers and three double values:";
cin>>x1>>x2>>x3>>y1>>y2>>y3;
clrscr();
cout<<"NAME:PADMASRI" <<endl<<"REGNO:2313711058034"<<endl;
cout<<"PROGRAM TO PERFORM FUNCTION OVERLOADING"<<endl;
cout<<"INTEGERS:"<<endl<<x1<<endl<<x2<<endl<<x3<<endl;
cout<<"DOUBLE:"<<endl<<y1<<endl<<y2<<endl<<y3<<endl;
cout<<"Add function having two integer as
arguments:"<<endl<<"Result:"<<add(x1,x2)<<endl;
cout<<"Add function having three integer as
arguments:"<<endl<<"Result:"<<add(x1,x2,x3)<<endl;
cout<<"Add function having one integer and one double value as
arguments:"<<endl<<"Result:"<<add(x1,y1)<<endl;
cout<<"Add function having one double and one integer as
arguments:"<<endl<<"Result:"<<add(y1,x1)<<endl;
cout<<"Add function having two double values as
arguments:"<<endl<<"Result:"<<add(y1,y2)<<endl;
cout<<"Add function having three double values as
arguments:"<<endl<<"Result:"<<add(y1,y2,y3)<<endl;
}

You might also like