0% found this document useful (0 votes)
19 views3 pages

Method Overloading

The document outlines various programming tasks focused on function overloading in classes. It includes designing classes for calculating areas and volumes of different geometrical shapes, finding minimum values, comparing values, and generating series. Each task specifies the required functions and their respective formulas or logic.

Uploaded by

anushara26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Method Overloading

The document outlines various programming tasks focused on function overloading in classes. It includes designing classes for calculating areas and volumes of different geometrical shapes, finding minimum values, comparing values, and generating series. Each task specifies the required functions and their respective formulas or logic.

Uploaded by

anushara26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Class : X FUNCTION OVERLOADING Page.

1
1. Design a class overload a function area( ) as follows.
(i) double area(double a, double b, double c) with three double arguments, returns the area of a scalene
triangle using the formula.
Area = s (s – a)(s – b)(s – c)
where s = a+b+c
2
(ii) double area(int a, int b, int height) with three integer arguments, returns the area of a trapezium using

R
the formula.
Area = 1 height(a + b)
2

TE
(iii) double area(double diagonal1, double diagonal2) with two double arguments, returns the area of a
rhombus using the formula:
Area = 1 (diagonal1 x diagonal2)
2
2. Design a class finder with following overloaded functions:

AS(i) int findMin(int a, int b) – to decides and return the smallest from a and b. if both the numbers are same
then return 0.
(ii) int findMin(int a, int b,int c) – to decides and return the smallest from a, b and c. If all the numbers are
same then return 0.
Write main function to input three numbers a ,b,c and by invoking above functions. Print smallest from a
EM
and b and smallest in a, b and c.

3. Design a class Area to find the area of following geometrical figures to illustrate function overloading.
invoke them.
● Area of circle = π𝑟2
● Area of square = a2
● Area of rectangle = length * breadth
OR


4. Design a class with the name volume using function overloading that computes the volume of cube, sphere
and a cuboid.
Formula: Volume of cube(vc) = s * s * s
Volume of sphere(vs) = 4 * π * r3
Volume of cuboid(vcd) = l * b * h
sC

5. Design a class to overload a function SumSeries( ) as follows:


(i) void SumSeries(int n, double x) – with one integer arguments and one double argument to find and
display the sum of the series given below:
S = x – x + x – x to _ _ _ _ _ _ _ _ n terms.
1 2 3 4

Class : X FUNCTION OVERLOADING Page.2


(ii) void SumSeries( ) – to find and display the sum of the series given below:
S = 1 + (1*2) + (1*2*3) + _ _ _ _ _ _ _ _ + (1*2*3*4---------*20)

6. Design a class with the name Perimeter using function overloading that computes the perimeter of a square, a
rectangle and a circle.
Formula: Perimeter of a square = 4*s
Perimeter of rectangle = 2*(l+b)
Perimeter of a circle = 2* π*r

7. Design a class to overload a function compare ( ) as follows:

R
(i) void compare(int, int) : to compare two integer values and print the greater of the two integers.
(ii) void compare(char, char) : to compare the numeric value of two characters and print with the higher
numeric value:

TE
(iii) void compare(String, String) : to compare the length of the two strings and print the longer of the two.

8. Design a class to overload a function series( ) as follows


(i) double series(double n) with one double arguments and returns the sum of the series
sum = 1 + 1 + 1 + ………………… + 1

AS 1 2 3 n
(ii) double series(double a, double n) with two double arguments and returns the sum of the series.
sum = 1 + 4 + 7 + 10 + ………………………. To n terms
a2 a5 a8 a11
EM
9. Design a program to overload a method hline()
void hline(int n ) – draw a horizontal line n character long using the character “*” to draw the triangle.
*
***
*****
*******
void hline(int n, char c) – draw a horizontal line n characters long using character stored in c to draw the line.
OR

A
BB
CCC
DDDD
EEEEE
sC

10. Define overloaded methods as:


boolean isPal(int n) – returns true if n is palindrome else returns false.
boolean isPal(String word) – returns true if word is palindrome else returns false.
Write a method main to accept an integer and a word and using above two methods check whether they
are palindromes.

Class : X FUNCTION OVERLOADING Page.3


11. WAP to overload a function volume( ) as follows:
i. double volume(double R) – with radius (R) as an argument, return the volume of sphere using the formula.
V = 4/3 x 22/7 x R3
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.
V = 22/7 x R2 x H
iii. double volume (double L, double B, double H) – with length(L), breadth(B) and Height(H) as the arguments,
returns the volume of a cuboid using the formula.
V=LxBxH

R
12. 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:
x1 + x2 + x3 + ………………… xn

TE
(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:

AS 1 + 1 + 1 ………………… 1
1 2 3 10
EM
OR
sC

You might also like