ASSIGNMENT ON FUNCTION-X
Q1.Define a function. What is meant by function prototype?
Q2.What are the two ways of invoking functions?
Q3.When a function is invoked how many values can be returned from the function?
Q4.Debug 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);
Q5.Write down the main function which calls the following function:
int square(int a)
{
return(a*a);
}
Q6.What happens when a function is passed by reference? Explain.
Q7. Differentiate between pure and impure functions.
Q8.Write 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.
Q9.Differentiate between call by value and call by reference.
Q10 What are the advantages of defining a method in a program?
Q11.What 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
Q13.Explain the function of a return statement in Java programming.
Q14.Differentiate between formal parameter and actual parameter.
Q15 What is the role of the keyword void in declaring functions?
Q16.If a function contains several return statements, how many of them will be executed?
Q17.Which OOP principle implements function overloading?
18.Give 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++) System.out.println( (int) c);
if(n%x == 0) }
System. out.println(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(x.compareTo(y) > 0)
{ System.out.println(x);
if ( a > b) else
a = a — b; System.out.println(y);}
else
a = b — a;
}
System.out.println(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 : System.out.print(” Geography”);
break;
case 2 : System.out.print(“Chemistry”) break;
Default : System.6ut.print(“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 )
{
System.out.print (” % ” + 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 :
System.out.print(“The series is as follows – \n” ); for( int k = 710; k > 660; k – = 10)
{
System.out.println ( “XX ” + (k – 10) );
}
(g) Write the output of the following code :
double d = 100, c;
c = d;
while ( c > 20 )
{
System.out.println (“Value : : ” + c );
c – = 20;
}