You are on page 1of 3

ASSIGNMENT ON OVERLOAD METHODS

Question 1 (2015)
Design a class to overload a function Joystring() as follows:
I. void Joystring(String s, char ch1, char ch2): with one string argument and two
character arguments that replaces the ch1 with the character argument ch1 in the
given string s and prints the new string.
Example:
Input value of s=”TECHNALOGY”
Ch1=’A’
Ch2=’O’
Output :” TECHNOLOGY”
II. void Joystring(String s) with one string argument that prints the position of the
first space and the last space of the given string s.
Example:
Input value of =”Cloud computing means Internet based computing”
Output :First index : 5
Last index : 36
III. void Joystring(String s1, String s2): with two string arguments that combine the
two string with a space between them and print the resultant string.
Example :
Input value of s1= “COMMON WEALTH”
Input value of s2=”GAMES”
Output : “COMMON WELATH GAMES”

Question 2 (2012)
Design a class to overload the function polygon() as follows:
i) void Polygon(int n, int ch) : with one integer argument and one character type
argument that draws a filled square of size n using the character store in ch
ii) void Polygon(int x, int y): with 2 integer arguments that draws a filled rectangle
of length x and breadth y using the symbol ‘@’.
iii) void Polygon(): with no arguments draws a fill triangle as shown below.
Output:
*
**
* * *

Question 3(2011)
Design a overload function compare as follows:
i. void compare(int, int): to compute 2 integer values and print the greater of two
integer.
ii. void compute(char, char): to compare numeric values of two character and print
the character with higher numeric value.
iii. void compute(String, String) : To compare the length of the two strings and print
the longest of the two.

2010 No question on overload Method

91
Question 4(2009)
Design a class to overload a function num_calc() as follows:
a) void num_calc(int num, char ch): with one integer argument and one character
argument computes the square of the integer argument if choice ch is ‘s’ else finds its
cube.
b) void num_calc(int a, int b, char ch): with 2 integer argument and a character
argument. It computes the product of integer argu ment if ch=’y’ else adds the
integers
c) void num_calc(String s1, String s2): with 2 string argument it prints whether the
string are equal or not.

Question 5(2008)
Write a class with the name volume using function overloading that computes the volume of a
cube, a sphere and a cuboid
Example : volume of a cube (vc) = s*s*s
Volume of sphere (vs) = 4/3*𝜋*r*r*r
Volume of a cuboid(vcd)=1/2*b*h

Question 6(2014)
Design a class to overload the function area as follows:
i) double area(double a, double b, double c) with 3double arguments, returns the area
ofa scalen triangle using the formula:
a+b+c
area= s( s − a)( s − b)( s − c) where s=
2

ii) double area(int a, int b,int height) :with 3 integer arguments, returns the area of a
tripizem using the formula:
1
area= height(a + b)
2
iii) double area(double diagnol1, double diagnpl2): with 2 two double double
arguments returns the area of a tripeziun using the formula:
1
area = * diagnol1* diagnol2
2

Question 7(2016)
Design a class to overload a function SumSeries() as follows:
i) void SumSeries( int n, double x) – with one integer argument and one double
argument to find the sum of the series given below:
x x x x
s = − + − ..... to n terms
1 2 3 4
ii) void Sumseries() – To find and display the sum of the following series:
iii) s= 1 + (1x2) + (1x2x3)………(1x2x3……20)

Question 8(2017)
Design a class to overload a function check() as follows:
i) void check(String str, char ch)- to find and print the frequency of a character in a
String
Example:
Input: Output:
Str=”Success Number of s present is = 3
92
ch = ‘s’
ii) void check(String s1)- to display only vowels from string s1, after converting it to
lower case.
Example :
Input :
S1= “computer” Output: o u e

Question 9(2018)
Design a class to overload the function Voulume as follows:
Double Volume(double r): with argument R returns the volume of the sphere using the
formula
V = 4/3 X 22/7 x R3
Double volume(double H, double R) : with height and volume returns the volume of the
cylinder
V = 22/7 x R2 x H
Double volume(double L, double B, double H): with 3 double
arguments returns the volume of cuboid
V = LxBxH

Question 10(2019)

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 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 1 1 1
+ + ……
2 3 4 10

93

You might also like