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

Overloading

Uploaded by

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

Overloading

Uploaded by

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

Programs on Overloading series.

Q1. Design a class to overload a sum = (1/a2) + (4/a5) + (7/a8) +


function compare( ) as follows: (10/a11) + .......... to n terms
1. void compare(int, int) — to Q4. Design a class to overload a
compare two integers values function area( ) as follows:
and print the greater of the two 1. double area (double a, double
integers. b, double c) with three double
2. void compare(char, char) — to arguments, returns the area of
compare the numeric value of a scalene triangle using the
two characters and print with formula:
the higher numeric value. area = √(s (s−a)(s−b)(s−c))
3. void compare(String, String) — where s = (a+b+c) / 2
to compare the length of the 2. double area (int a, int b, int
two strings and print the longer height) with three integer
of the two arguments, returns the area of
Q2. Design a class to overload a a trapezium using the formula:
function polygon() as follows: area = (1/2) x height x (a + b)
1. void polygon(int n, char ch) — 3. double area (double diagonal1,
with one integer and one double diagonal2) with two
character type argument to double arguments, returns the
draw a filled square of side n area of a rhombus using the
using the character stored in formula:
ch. area = ½ x (diagonal1 x
2. void polygon(int x, int y) — diagonal2)
with two integer arguments Q5. Design a class to overload a
that draws a filled rectangle of function Joystring( ) as follows:
length x and breadth y, using 1. void Joystring(String s, char
the symbol '@'. ch1, char ch2) with one string
3. void polygon() — with no argument and two character
argument that draws a filled arguments that replaces the
triangle shown below: character argument ch1 with
Example: the character argument ch2 in
Input value of n=2, ch = 'A' the given String s and prints
Output: AA the new string.
AA Example:
Input value of x = 2, y = 5 Input value of s =
Output: @@@@@ "TECHNALAGY"
@@@@@ ch1 = 'A'
Output: * ch2 = 'O'
** Output: "TECHNOLOGY"
*** 2. void Joystring(String s) with
Q3. Design a class to overload a one string argument that prints
function series( ) as follows: the position of the first space
1. double series(double n) with and the last space of the given
one double argument and String s.
returns the sum of the series. Example:
sum = (1/1) + (1/2) + (1/3) Input value of s = "Cloud
+ .......... + (1/n) computing means Internet
2. double series(double a, double based computing"
n) with two double arguments Output:
and returns the sum of the
First index: 5 12
Last Index: 36 123
3. void Joystring(String s1, String 1234
s2) with two string arguments 12345
that combines the two strings void display(int n): To print the
with a space between them square root of each digit of the given
and prints the resultant string. number.
Example: Example:
Input value of s1 = "COMMON n = 4329
WEALTH" Output – 3.0
Input value of s2 = "GAMES" 1.414213562
Output: COMMON WEALTH 1.732050808
GAMES 2.0
(Use library functions) Q9. Design a class to overload a
Q6. Design a class to overload a function Sum( ) as follows:
function check( ) as follows: (i) int Sum(int A, int B) – with two
1. void check (String str , char integer arguments (A and B)
ch ) — to find and print the calculate and return sum of all the
frequency of a character in a even numbers in the range of A and
string. B.
Example: Sample input: A=4 and B=16
Input: Sample output: sum = 4 + 6 + 8 +
str = "success" 10 + 12 + 14 + 16
ch = 's' (ii) double Sum( double N ) – with
Output: one double arguments(N) calculate
number of s present is = 3 and return the product of the
2. void check(String s1) — to following series:
display only vowels from string sum = 1.0 x 1.2 x 1.4 x …………. x N
s1, after converting it to lower (iii) int Sum(int N) - with one integer
case. argument (N) calculate and return
Example: sum of only odd digits of the number
Input: N.
s1 ="computer" Sample input : N=43961
Output : o u e Sample output : sum = 3 + 9 + 1 =
Q7. Design a class to overload a 13
function series( ) as follows: Write the main method to create an
(a) void series (int x, int n) – To object and invoke the above
display the sum of the series given methods
below: Q10. Design a class to overload a
x1 + x2 + x3 + .......... xn terms function pattern() as follows:
(b) void series (int p) – To display the (i) void pattern(char ch, int n) with
following series: one character and one integer
0, 7, 26, 63 .......... p terms argument and prints
(c) void series () – To display the sum 'n' lines containing the character
of the series given below: stored in 'ch' in the following pattern,
1/2 + 1/3 + 1/4 + .......... 1/10 If ch = @ and n = 3, then output:
Q8. Define a class to overload the @
method display as follows: @@
void display( ): To print the following @@@
format using nested loop
1
(ii) double pattern(double x, double
n) with two double arguments and
returns the sum
of the series,
x x x x x
S = n + n−1 + n−2 +… 2 + 1
Q11. Design a class to overload a
function series() as follows:
(i) double series(double n) with one
double argument and returns the
sum of the series,
1 1 1
S = 1+ + + …+
2! 3 ! n!
(ii) double series(double x, double n)
with two double arguments and
returns the sum
of the series,
2 3 n
x x x x
S = + + + …+ 2
1 4 9 n

You might also like