COMPUTER SCIENCE C++

2006 Delhi:

1.a) Name the header file to which the following below: (i) abs( ) (ii) isupper( )

1

Ans) (i) abs( ) - math.h, stdlib.h, complex.h ,(ii)isupper( ) - ctype.h

1.e) Find the output of the following program.

#include<iostream.h>
void main( )
{ long NUM=1234543;
int F=0,S=0;
do
{ int R=NUM % 10;
if (R %2 != 0)
F += R;
else
S += R;
NUM / = 10;
} while (NUM>0);
cout<<F-S;
}

2

Ans: Output: 2

2006 Outside Delhi:

1.a) Name the header file to which thefollowing belong: 1(i) pow ( ) (ii)random( )

2

Ans: i) abs( ) - math.h, stdlib.h, complex.h (ii)random( ) - stdlib.h

1.e) Find the output of the following program.

#include<iostream.h
void main( )
{ long Number=7583241;
int First = 0, Second =0;
do
{ int R=Number%10;
if(R%2 ==0)
First += R;
else
Second += R;
Number / = 10;
} while (Number > 0);
cout<<First-Second;
}

2

Ans: Output -2

2005 Delhi:

1.a) Differentiate between a Call by Value and Call by Reference, giving suitable examples of each.

2

Ans: Call by value: In call by value method,tte called function creates a new set of variables and copies the values of arguments into them. The function does not have access to the original variables (actual parameters)and can only work on the copies of values it created. Passing arguments by value is useful when the original values are not to be modified.
In call by reference method: a reference to the actual argument (original variable) is passed to the called function. (Reference is an alias for a predefined variable. Ie the same variable value can be accessed by any of the two names: the original variable’s name and the reference name.) Thus, in call by reference method, the changes are reflected back to the original values. The call by reference methodis useful in situations where the values of the original variables are to be changed using a function.

Program to illustrate the call by value method of function invoking:

#include<iostream.h>
#include<conio.h>
int change(int);
void main( )
{ clrscr( );
int orig=10;
cout<<”\nThe original value is”<<orig<<”\n”;
cout<<”\nReturn value of function change()is “<<change(orig)<<”\n”;
cout<<”\nThe value after function change() is over”<<orig<<”\n;
getch();
}
int change(int duplicate)
{ duplicate=20;
return duplicate;
}

Ans:

Output: The original value is 10.Return value of function change() is 20.The value after function change() is over 10.

Program to illustrate the call by Reference method of function invoking:

#include<iostream.h>
#include<conio.h>
int change(int&);
void main( )
{ clrscr( );
int orig=10;
cout<<”\nThe original value is”<<orig<<”\n”;
cout<<”\nReturn value of function change()is “<<change(orig)<<”\n”;
cout<<”\nThe value after function change() is over”<<orig<<”\n;
getch();
}
int change(int &duplicate)
{ duplicate=20;
return duplicate;}

Output: The original value is 10. Return value of function change() is 20. The value after function change() is over 20.

 

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( mrkdata@yahoo.com )


Warning: include_once(../../ebooks-footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp9.php on line 170

Warning: include_once(): Failed opening '../../ebooks-footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp9.php on line 170

Warning: include_once(../../../footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp9.php on line 172

Warning: include_once(): Failed opening '../../../footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp9.php on line 172