(b) void num_calc (int a, int b, char ch) with two integer arguments and one
FUNCTION OVERLOADING character argument. It computes the product of integer arguments if ch is ‘p’
else adds the integers.
(c) void num_calc (String s1, String s2) with two string arguments. which prints
Q1. Design a class to overload a function polygon ( ) as follows: whether the strings are equal or not.
Q4. Design a class to overload a function series ( ) as follows:
(i) void polygon (int, n char ch) with one integer argument and one (i) double series (double n) with one double argument and returns the sum of the
character type argument that draws a 1 1
series, sum = + + + … . +
1 1
filled square of side n using the character 1 2 3 𝑛
(ii) double series (double a, double n) with two double arguments and returns the
stored in ch. 1 4 7 10
(ii) void polygon (int x, int y) with two integer arguments that draws a sum of the series, sum = 2 + 5 + 8 + 11 + …… to n terms
𝑎 𝑎 𝑎 𝑎
filled rectangle of length x and breadth Q5. Design a class to overload a function area ( ) as follows:
y, using the symbol ‘@’ (i) double area (double a, double b, double c) with three double arguments,
(iii) void polygon ( ) with no argument that draws a filled returns the area of a scalene triangle using the formula:
triangle shown below.
area = √𝑠(𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐)
𝑎+𝑏+𝑐
Example: where s =
(i) Input value of n=2, ch= ‘O’ 2
(ii) double area (int a, int b, int height) with three integer arguments, returns the
Output: OO
area of a trapezium using the formula:
OO 1
(ii) Input value of x=2, y=5 area = height (a+b)
2
Output : @@@@@ (iii) double area (double diagonal 1, double diagonal 2) with two double
@@@@@ arguments returns the area of a rhombus using the formula:
(iii) Output: * 1
** area = (diagonal 1 x diagonal 2)
2
*** Q6. Design a class to overload a function Joystring ( ) as follows:
Q2. Design a class to overload a function compare( ) as follows: (i) void Joystring (String s, char ch1, char ch2) with one string argument and two
(a) void compare - to compare two integer values and print character arguments that replaces the character argument ch1 with the
(int, int) the greater of the two integers. character argument ch2 in the given string s and prints the new string.
(b) void compare - to compare the numeric value of two Example:
(char, char) characters and print the character with Input value of s = “TECHNALAGY”
higher numeric value. ch1 = ‘A’
(c) void compare - to compare the length of the two strings ch2 = ‘O’
(String, String) and print the longer of the two.
Output : “TECHNOLOGY”
Q3. Design a class to overload a function num_calc ( ) as follows: (ii) void Joystring (String s) with one string argument that prints the position of
(a) void num_calc (int num, char ch) with one integer argument and one the first space and the last space of the given string s.
character argument, computes the square of integer argument if choice ch is Example:
‘s’ otherwise finds its cube. 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 combines (iii) double volume (double L, double B, double H) – with length (L),
the two strings with a space between them and prints the resultant string. breadth(B) and Height(H) as the arguments, returns the volume of
Example:
Input value of s1 = “COMMON WEALTH” a cuboid using the formula.
Input value of s2 = “GAMES” V=LxBxH
Output: COMMON WEALTH GAMES
(use library functions) Q10. Design a class to overload a function series ( ) as follows:
Q7. Design a class to overload a function SumSeries( ) as follows: (a) void series ( int x, int n) – To display the sum of the series given
(i) void SumSeries(int n, double x) – with one integer argument and one below:
double argument to find and display the sum of the series given below: x1 + x2 + x2 + ………………… xn terms
𝑥 𝑥 𝑥 𝑥 𝑥
𝑆 = − + − + … … … to n terms (b) void series (int p) – To display the following series:
1 2 3 4 5
(ii) void SumSeries( ) – To find and display the sum of the following 0, 7, 26, 63………………….. p terms
series: (c) void series ( ) – To display the sum of the series given below:
s = 1 + (1 x 2) + (1 x 2 x 3) + … …… + (1 x 2 x 3 x 4 … … … x 20) 1 1 1 1
+ + ………..
2 3 4 10
Q8. 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
Example:
Input : Output:
str = “success” number of s present is = 3
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
Q9. 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 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