ASSIGNMENT ON FUNCTION-X
[Link] a function. What is meant by function prototype?
[Link] are the two ways of invoking functions?
[Link] a function is invoked how many values can be returned from the function?
[Link] the errors and rewrite the following function prototypes:
(a) int sum(x,y);
(b) float product(a,int y);
(c) float operate(int x, float=3.4);
(d) float sum(int x,y);
[Link] down the main function which calls the following function:
int square(int a)
{
return(a*a);
}
[Link] happens when a function is passed by reference? Explain.
Q7. Differentiate between pure and impure functions.
[Link] a function which is used to swap the values of two memory locations.
(a) by using a third variable.
(b) without using a third variable.
[Link] between call by value and call by reference.
Q10 What are the advantages of defining a method in a program?
[Link] is meant by function overloading? In what way it is advantageous?
Q12 Define the following:
(a) Return data type (b) Access specifier (c) Parameter list (d) Method signature
[Link] the function of a return statement in Java programming.
[Link] between formal parameter and actual parameter.
Q15 What is the role of the keyword void in declaring functions?
[Link] a function contains several return statements, how many of them will be executed?
[Link] OOP principle implements function overloading?
[Link] output of the following function definitions and also write what mathematical operations
they carry out
Question 1 Question 3
void test1(int n) void test3(char c)
{ {
for(int x=1; x<=n; x++) [Link]( (int) c);
if(n%x == 0) }
System. [Link](x); if 'm' is passed to c.
} if 12 is passed to n.
Question 4
Question 2
void test4(String x, String y)
void test2(int a, int b)
{
{
while( a != b) if([Link](y) > 0)
{ [Link](x);
if ( a > b) else
a = a — b; [Link](y);}
else
a = b — a;
}
[Link](a);
}
if 4 and 17 are passed to the function.
(Attempt all questions) CLASS-IX
Question 1.
Answer the following in brief.
(a) Write two integer primitive data types.
(b) Write two java keywords.
(c) What is a token in Java ?
(d) State any two harms caused by software piracy.
(e) What do you mean by Intellectual property rights ?
Question 2.
Answer with respect to given code.
(a) What will be the value of b, c when nl = 10, n2 = 0, given that:
int b = (nl < n2) ? nl : n2 ;
double c = (n2 != 0) ? (nl/n2) : (nl * 2);
(b) Given the initial value of r = 5 in the following expression :
v = r++ + 2*r + 2*r++
Write the final value in v and r.
(c) Given the initial value of a = 10, k = 2 in the following expression :
k+ = a++ + ++a/2;
Write the final value in k and a.
(d) Rewrite the following code after debugging (underline the changes made) :
switch (wn) ;
{
case 1 : [Link](” Geography”);
break;
case 2 : [Link](“Chemistry”) break;
Default : [Link](“Mathematics”);
}
Question 3.
(a) Differentiate between Entry controlled and Exit controlled loop.
(b) Differentiate between data type int and data type double.
(c) Differentiate between constructor and other methods of a class.
(d) Write the following code by using while loop :
for (k = 501; k <= 521; k = k+2 )
{
[Link] (” % ” + k );
}
(e) Write the following code by using if .. else statement:
P = ( g == 9.8) ? 0 : 1;
(f) Write the output of the following code :
[Link](“The series is as follows – \n” ); for( int k = 710; k > 660; k – = 10)
{
[Link] ( “XX ” + (k – 10) );
}
(g) Write the output of the following code :
double d = 100, c;
c = d;
while ( c > 20 )
{
[Link] (“Value : : ” + c );
c – = 20;
}