0% found this document useful (0 votes)
50 views4 pages

Overload Function-past papers.docx

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)
50 views4 pages

Overload Function-past papers.docx

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/ 4

Overload Function

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

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.

2. Design a class to overload a function polygon() as follows:

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:

Example: hello there!


Input value of n=2, ch = 'O'
Output:
OO
OO
Input value of x = 2, y = 5
Output:
@@@@@
@@@@@
Output:
*
**
***
1. Design a class to overload a function series( ) as follows:
double series(double n) with one double argument and returns the sum of the series.
sum = (1/1) + (1/2) + (1/3) + .......... + (1/n)
double series(double a, double n) with two double arguments and returns the sum of the series.
sum = (1/a2) + (4/a5) + (7/a8) + (10/a11) + .......... to n terms
2. Design a class to overload a function area( ) as follows:
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
double area (int a, int b, int height) with three integer arguments, returns the area of a
trapezium using the formula:
area = (1/2)height(a + b)
double area (double diagonal1, double diagonal2) with two double arguments, returns the area
of a rhombus using the formula:
area = 1/2(diagonal1 x diagonal2)

3. Design a class to overload a function Joystring( ) as follows:


4.
void Joystring(String s, char ch1, char ch2) with one string argument and two character
arguments that replaces the character argument ch1 with the character argument ch2 in the
given String s and prints the new string.
Example:
Input value of s = "TECHNALAGY"
ch1 = 'A'
ch2 = 'O'
Output: "TECHNOLOGY"

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)

5. 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
and display the sum of the series given below:
𝑥 𝑥 𝑥 𝑥
s= 1 - 2
+3 - 4
… … … …to n terms
(ii) void sumSeries(): to find and display the sum of the following series:
s=1+(1×2)+(1×2×3)+... ... ... +(1×2×3×4... ... ... ×20)
6. Design a class to overload a function check( ) as follows:
void check (String str , char ch ) — to find and print the frequency of a character in a string.

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

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

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

(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/2 + 1/3 + 1/4 + .......... 1/10

9. Define a class to overload the function print as follows:


void print() - to print the following format
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
void print(int n) - To check whether the number is a lead number. A lead number is the one
whose sum of even digits are equal to sum of odd digits.
e.g. 3669
odd digits sum = 3 + 9 = 12
even digits sum = 6 + 6 = 12
3669 is a lead number.

10. Define a class to overload the method display as follows:

void display( ): To print the following format using nested loop


1
12
123
1234
12345

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy