Page 256 - CA_Blue( J )_Class10
P. 256
9. Write the return data type of the following functions:
(i) endsWith() (ii) log() [2018]
Ans. (i) boolean (ii) double
10. What are the two ways of invoking functions? [2017]
Ans. Call by value and call by reference.
SECTION B
11. Design a class to overload a function series () as follows:
(a) void series (int x, int n): to display the sum of the series given below:
3
n
1
2
x + x + x + … + x terms
(b) void series (int p): to display the following series:
0, 7, 26, 63, … p terms.
(c) void series (): to display the sum of the series given below:
1/2 + 1/3 + 1/4 + … + 1/10 [2019]
Ans. class overloading
{
void series(int x, int n) {
int i;
double s = 0.0;
for(i = 1; i <= n; i++)
{
s = s+(double)Math.pow(x, i);
}
System.out.println("Result = " + s);
}
void series(int p) {
int i,t;
for(i = 1; i <= p; i++) {
t = (i*i*i) - 1;
System.out.print(t + ",");
}
}
void series() {
double s = 0.0;
int i;
for(i = 2; i <= 10; i++)
{
s = s + 1.0 / i;
}
System.out.println("Result = " + s);
}
public static void main()
{
overloading obj = new overloading();
obj.series(2,5);
obj.series(5);
obj.series();
}
}
12. Design a class to overload a function volume() as follows:
(i) double volume(double r) – with radius 'r' as an argument, returns the volume of sphere using the formula:
v = 4 / 3 × 22 / 7 × r 3
(ii) double volume(double h, double r) – with height 'h' and radius 'r' as the arguments, returns the volume of a cylinder
using the formula:
2
v = 22 / 7 × r × h
254254 Touchpad Computer Applications-X

