FatimaZRahman Computers Project
FatimaZRahman Computers Project
Page 1
INDEX
Program
Topic Page no.
no.
5 Norm of a Number 12
6 Patterns 14
Page 2
fi
fi
fi
fi
fi
fi
PROGRAM 1
De ne a class with the given speci cations and calculate the bill amount for a private Cab
service company which provides services within the city at the following rates:
Member methods:
void accept( ) - Accepts car_type and km
void calculate( ) - Calculates the bill as per the rules given above.
void display( ) - Displays the bill
SOURCE CODE
Page 3
fi
fi
VARIABLE DESCRIPTION TABLE
Page 4
OUTPUT
1)
2)
3)
4)
Page 5
PROGRAM 2
De ne a class to store 10 integers (including positive and negative numbers) in a Single
Dimensional Array (SDA). Display all the negative numbers followed by the positive
numbers. Also display the sum of the positive numbers.
SOURCE CODE
Page 6
fi
VARIABLE DESCRIPTION TABLE
OUTPUT
1)
2)
Page 7
PROGRAM 3
De ne a class to declare an array of double data type to store the following percentages
of marks scored by 10 students in an exam:
{98.3, 82.4, 99.0, 78.5, 89.1, 92.8, 99.8, 96.2, 97.6, 62.4}.
Declare another array of character data type which stores the corresponding grades as
per the following rules:
MARKS GRADE
95 or above A+
Below 70 C
SOURCE CODE
Page 8
fi
VARIABLE DESCRIPTION TABLE
OUTPUT
1)
Page 9
PROGRAM 4
De ne a class to declare an array of long data type to accept the registration numbers of
10 students in ascending order. Perform the Binary Search to search for an element
entered by the user. If it is found, display the message “Element found” along with its
position. Otherwise display the message “Search element not found”.
SOURCE CODE
Page 10
fi
VARIABLE DESCRIPTION TABLE
OUTPUT
1)
2)
Page 11
PROGRAM 5
De ne a class to input an integer. Calculate and display the Norm of the number. The
Norm of a number is the square root of the sum of squares of all digits of the number.
Example : The Norm of 68 is 10.
6 x 6 + 8 x 8 = 36 + 64 = 100 ; square root of 100 is 10.
SOURCE CODE
Page 12
fi
OUTPUT
1)
2)
Page 13
PROGRAM 6
Write a menu-driven program to display the pattern as per the user’s choice.
Pattern 1 Pattern 2
1 2 3 4 @@@@@
5 6 7 8 @@@@
9 10 11 12 @@@
13 14 15 16 @@
17 18 19 20 @
SOURCE CODE
Page 14
VARIABLE DESCRIPTION TABLE
Page 15
OUTPUT
1)
2)
3)
Page 16
PROGRAM 7
A Computer showroom has announced festival discounts and the gifts on the purchase of
items, based on the total cost as given below:
Member methods:
void input( ) - Input the total_cost and the model name of the product (using Scanner
class only)
void discount( ) - Calculate the amount to be paid by the customer as per the rules given
above and also allot the gift item for the customer.
Page 17
fi
fi
SOURCE CODE
Page 18
VARIABLE DESCRIPTION TABLE
Page 19
OUTPUT
1)
2)
3)
4)
Page 20
PROGRAM 8
Write a program to declare a 4 x 5 double dimensional array that stores integer numbers
as given below. Write a program to nd the sum of all odd numbers and the product of all
even numbers.
9 20 14 75 81
191 8 10 55 90
23 41 36 82 57
83 53 20 100 5
SOURCE CODE
Page 21
fi
OUTPUT
i int for(i)
j int for(j)
Page 22
PROGRAM 9
Write a program to declare two 3 x 3 double-dimensional arrays of integer type. Accept all
the elements for both the arrays. Create another 3 x 3 double-dimensional integer array,
which stores the sum of each corresponding position. Display the elements of the third
array. For example:
1 2 3 10 11 15 11 13 18
4 5 6 1 4 2 5 9 8
+ =
7 8 9 6 3 9 13 11 18
SOURCE CODE
Page 23
OUTPUT
Page 24
VARIABLE DESCRIPTION TABLE
Page 25
PROGRAM 10
Write a program to declare a two-dimensional array of double data type. The number of
rows and columns are accepted from the user. Also enter the array elements. Display the
sum of the elements of each row separately.
SOURCE CODE
Page 26
OUTPUT
Page 27
PROGRAM 11
Design a class named ShowRoom with the following descriptions:
Member methods:
• ShowRoom( ) – constructor to initialize data members
• void input( ) – to input customer’s name, mobile number, cost
• void calculate( ) – to calculate discount on the cost of purchased items, based on the
following criteria:
Discount (in
Cost
percentage %)
• void display( ) - to display the customer’s name, mobile number, amount to be paid after
discount.
Write a main method to create an object of the class and call the above member
methods.
Page 28
SOURCE CODE
Page 29
OUTPUT
1)
2)
3)
4)
Page 30
VARIABLE DESCRIPTION TABLE
Page 31
PROGRAM 12
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
following series:
(ii) double series( ) with no argument and returns the sum of the series.
SOURCE CODE
Page 32
VARIABLE DESCRIPTION TABLE
Page 33
PROGRAM 13
De ne a class Bill that calculates the telephone bill of a consumer with the following
description:
Instance variables / Data members:
• int bno : bill number
• String name : name of the consumer
• int call : no. of calls consumed in a month
• double amt : bill amount to be paid by the person
Member methods:
• Bill( ) – constructor to initialize data members with default initial value
• Bill(...) – parameterized constructor to accept billno., name and no. of calls consumed.
• void Calculate( ) – to calculate the monthly telephone bill for a consumer as per the
following condition:
Create two objects in the main( ) method to invoke two constructors. Using the rst object
invoke the other member methods to perform the desired task.
Page 34
fi
fi
SOURCE CODE
Page 35
OUTPUT
Page 36
PROGRAM 14
Write a program to input 10 numbers in a SDA (Single Dimensional Array) of double data
type. Sort the numbers in ascending order using Bubble Sort technique. Display the
sorted array.
SOURCE CODE
Page 37
OUTPUT
1)
2)
Page 38
PROGRAM 15
De ne a class to accept a string and convert it into Uppercase. Display the string by
replacing the vowels by their immediate next consonant.
SOURCE CODE
OUTPUT
1)
2)
Page 39
fi
VARIABLE DESCRIPTION TABLE
Page 40
PROGRAM 16
Design a class to overload a function palindrome( ) as follows:
(i) boolean palindrome(int n) – checks whether the number n is a palindrome or
not.
SOURCE CODE
Page 41
VARIABLE DESCRIPTION TABLE
Page 42
PROGRAM 17
Write a program to store 5 names in SDA. Display only those names which begin with the
letter ‘a’ or ‘A’ and also ends with the letter ‘a’ or ‘A’.
SOURCE CODE
OUTPUT
1)
2)
Page 43
VARIABLE DESCRIPTION TABLE
Page 44
PROGRAM 18
Write a program to store the following words in an array. Display the words with highest
and lowest number of characters.
SOURCE CODE
OUTPUT
Page 45
VARIABLE DESCRIPTION TABLE
Page 46
PROGRAM 19
Write a program to input a sentence. Convert it into upper case. Display the frequency of
characters in alphabetical order.
SOURCE CODE
Page 47
OUTPUT
1)
2)
Page 48
PROGRAM 20
Write a menu driven program to display the pattern as per the user’s choice.
Pattern 1 Pattern 2
K 1
KO 22
KOL 333
KOLK 4444
KOLKA 55555
KOLKAT 666666
KOLKATA 7777777
In Pattern 1, the string is accepted from the user and in Pattern 2, the no. of rows is
accepted from the user. For an incorrect option, an appropriate error message should be
displayed.
SOURCE CODE
Page 49
OUTPUT
1)
2)
Page 50