PROGRAM TO IMPLEMENT DEFAULT ARGUMENTS

/*PROGRAM TO IMPLEMENT DEFAULT ARGUMENTS*/

#include<conio.h>

#include<iostream.h>

class deflt_arg

{

int a,b;

public:

void input();

void process(int a=2,int b=3,int c=5,int d=6);

};

void deflt_arg::input()

{

cout<<“Enter any two numbers: “;

cin>>a>>b;

cout<<“Sum of numbers using default and user given arguments:\n”;

process(a,b);

cout<<“Sum of numbers using all default arguments:\n”;

process();

 

};

void deflt_arg::process(int a,int b,int c,int d)

{

int sum;

cout<<“Numbers are: a=”<<a<<”  b=”<<b<<”  c=”<<c<<“d=”<<d<<endl;

sum=a+b+c+d;

cout<<“Sum of numbers is: “<<sum<<endl;

}

void main()

{

deflt_arg d1;

clrscr();

d1.input();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *