Overload Function-past papers.docx
Overload Function-past papers.docx
void compare(int, int) — to compare two integers values and print the greater of the two
integers.
void compare(char, char) — to compare the numeric value of two characters and print with the
higher numeric value.
void compare(String, String) — to compare the length of the two strings and print the longer of
the two.
void polygon(int n, char ch) — with one integer and one character type argument to draw a filled
square of side n using the character stored in ch.
void polygon(int x, int y) — with two integer arguments that draws a filled rectangle of length x
and breadth y, using the symbol '@'.
void polygon() — with no argument that draws a filled triangle shown below:
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 s =
Output:
First index: 5
Last Index: 36
void Joystring(String s1, String s2) with two string arguments that combines the two strings with
a space between them and prints the resultant string.
Example:
Input value of s1 = "COMMON WEALTH"
Input value of s2 = "GAMES"
Output: COMMON WEALTH GAMES
(Use library functions)
Example:
Input:
str = "success"
ch = 's'
Output:
number of s present is = 3
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
double volume (double R) – with radius (R) as an argument, returns the volume of sphere using
the formula.
V = 4/3 x 22/7 x R3
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
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
8. 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
(c) void series () – To display the sum of the series given below:
void display(int n): To print the square root of each digit of the given number.
Example:
n = 4329
Output
– 3.0
1.414213562
1.732050808
2.0