Wednesday, March 23, 2011

Smallest Number using C++ Object

/*
Write a function called small_test() that is passed two arguments of type int as reference. the function should find the smaller
of the two numbers and change it to -1;
*/
# include "iostream"
using namespace std;

# include "stdio.h"
class SmallNumber
{

public:

int small_test(int *nOperand1, int *nOperand2)
{
if(*nOperand1 < *nOperand2)
{
return *nOperand1=-1;
}
else
{
return *nOperand2=-1;

}
}


};

int main()
{
SmallNumber Obj1;

int nOperand1 = 40;
int nOperand2 = 5;

printf(" Given number :: %d\t%d\n",nOperand1,nOperand2);
Obj1.small_test(&nOperand1,&nOperand2);

printf("Smallest number value changed as -1\n");
printf("%d\t%d\n",nOperand1,nOperand2);


return 0;
}

OUTPUT:

Given number :: 40 5
Smallest number value changed as -1
40 -1
Press any key to continue . . .

No comments:

Post a Comment