Page 286 - ComputerScience_Class_11
P. 286
void geometry(int x, int y) : With two integer arguments that draw a filled rectangle of length x and breadth y, using the
symbol ‘a’
void geometry() : With no arguments that draws a filled triangle shown below
For example:
(i) Input value of n = 3, ch = 'x'
Output:
xxx
xxx
xxx
(ii) Input value of x = 3, y = 4
Output:
aaaa
aaaa
aaaa
(iii) Output:
$
$$$
$$$$$
$$$$$$$
2. Design a class to overload a function area() with the specifications given as follows:
(i) 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
(ii) 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)
(iii) double area(double diagonal1, double diagonal2) with two double arguments, returns the area of a rhombus using the
formula:
area = 1/2 × (diagonal1 × diagonal2)
3. Using the Overloading function series(), do the following:
(i) int series (int n) : Returns the sum of the series
s= 11 + 22 + 33 + 44 + 55 + ……+ nn
(ii) void series (int x, int n) : Prints the sum of the series
s= (x-1)+(x-3) + (x-5) + …….nth term
(iii) double series (double n) : Prints the following series
1,4,9,16,25,……… nth term
G. Find the output of the following programs:
1. class sum_average {
void calculate(int m, int n) {
int sum = m + n;
double average = sum / 2.0;
System.out.println("Sum: " + sum + " and Average: " + average);
}
public static void main(String[] args) {
sum_average obj = new sum_average();
284 Touchpad Computer Science (Ver. 3.0)-XI

