KEMBAR78
Program Qns | PDF | Integer (Computer Science) | String (Computer Science)
0% found this document useful (0 votes)
36 views17 pages

Program Qns

The document outlines programming tasks and class definitions for various years from 2010 to 2014, focusing on concepts such as binary search, class creation, discounts, prime numbers, and string manipulations. Each task includes specific requirements for input, output, and functionality, demonstrating a range of programming skills. The tasks are designed to reinforce object-oriented programming principles and algorithmic thinking.

Uploaded by

monikamesh16
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)
36 views17 pages

Program Qns

The document outlines programming tasks and class definitions for various years from 2010 to 2014, focusing on concepts such as binary search, class creation, discounts, prime numbers, and string manipulations. Each task includes specific requirements for input, output, and functionality, demonstrating a range of programming skills. The tasks are designed to reinforce object-oriented programming principles and algorithmic thinking.

Uploaded by

monikamesh16
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/ 17

2010:

1. Write a program to perform binary search on a list of integers given below, to search for an element
input by the user. If it is found display the element along with its position, otherwise display the
message "Search element not found".
5, 7, 9, 11, 15, 20, 30, 45, 89, 97
2. Define a class Student as given below:
Data members/instance variables:
name, age, m1, m2, m3 (marks in 3 subjects), maximum, average
Member methods:
A parameterized constructor to initialize the data members.
To accept the details of a student.
To compute the average and the maximum out of three marks.
To display the name, age, marks in three subjects, maximum and average.
Write a main method to create an object of a class and call the above member methods.
3. Shasha Travels Pvt. Ltd. gives the following discount to its customers:
Ticket Amount Discount
Above Rs. 70000 18%
Rs. 55001 to Rs. 70000 16%
Rs. 35001 to Rs. 55000 12%
Rs. 25001 to Rs. 35000 10%
Less than Rs. 25001 2%
Write a program to input the name and ticket amount for the customer and calculate the discount
amount and net amount to be paid. Display the output in the following format for each customer:
Sl. No. Name Ticket Charges Discount Net Amount
(Assume that there are 15 customers, first customer is given the serial no (SI. No.) 1, next customer 2
…….. and so on)
4. Write a menu driven program to accept a number from the user and check whether it is a Prime
number or an Automorphic number.
(a) Prime number: (A number is said to be prime, if it is only divisible by 1 and itself)
Example: 3,5,7,11
(b) Automorphic number: (Automorphic number is the number which is contained in the last digit(s)
of its square.)
Example: 25 is an Automorphic number as its square is 625 and 25 is present as the last two digits.
5. Write a program to store 6 elements in an array P and 4 elements in an array Q. Now, produce a third
array R, containing all the elements of array P and Q. Display the resultant array.
Input Input Output
P[ ] Q[ ] R[ ]
4 19 4
6 23 6
1 7 1
2 8 2
3 3
10 10
19
23
7
8
6. Write a program to input a sentence. Count and display the frequency of each letter of the sentence in
alphabetical order.
Sample Input: COMPUTER APPLICATIONS
Sample Output:
Character Frequency Character Frequency
A 2 O 2
C 2 P 3
I 1 R 1
L 2 S 1
M 1 T 2
N 1 U 1

2011:
1. Define a class called 'Mobike' with the following specifications:
Data Members Purpose
int bno To store the bike number
int phno To store the phone number of the customer
String name To store the name of the customer
int days To store the number of days the bike is taken on rent
int charge To calculate and store the rental charge

Member Methods Purpose


void input() To input and store the details of the customer
void compute() To compute the rental charge
void display() To display the details in the given format

2. The rent for a mobike is charged on the following basis:


Days Charge
For first five days ₹500 per day
For next five days ₹400 per day
Rest of the days ₹200 per day
Output:
Bike No. Phone No. Name No. of days Charge
xxxxxxx xxxxxxxx xxxx xxx xxxxxx
Write a program to input and sort the weight of ten people. Sort and display them in descending
order using the selection sort technique.
3. Write a program to input a number and print whether the number is a special number or not.
(A number is said to be a special number, if the sum of the factorial of the digits of the number is
same as the original number).
Example:
145 is a special number, because 1! + 4! + 5! = 1 + 24 + 120 = 145.
(Where ! stands for factorial of the number and the factorial value of a number is the product of all
integers from 1 to that number, example 5! = 1 * 2 * 3 * 4 * 5 = 120)
4. Write a program to accept a word and convert it into lower case, if it is in upper case. Display the
new word by replacing only the vowels with the letter following it.
Sample Input: computer
Sample Output: cpmpvtfr
5. 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.
6. Write a menu driven program to perform the following tasks by using Switch case statement:
(a) To print the series:
0, 3, 8, 15, 24, ............ to n terms. (value of 'n' is to be an input by the user)
(b) To find the sum of the series:
S = (1/2) + (3/4) + (5/6) + (7/8) + ........... + (19/20)

2012:
1. Define a class called Library with the following description:
Instance Variables/Data Members:
int accNum — stores the accession number of the book.
String title — stores the title of the book.
String author — stores the name of the author.
Member methods:
void input() — To input and store the accession number, title and author.
void compute() — To accept the number of days late, calculate and display the fine charged at the
rate of Rs. 2 per day.
void display() — To display the details in the following format:
Accession Number Title Author
Write a main method to create an object of the class and call the above member methods.
2. Given below is a hypothetical table showing rates of income tax for male citizens below the age of
65 years:
Taxable income (TI) in ₹ Income Tax in ₹
Does not exceed Rs. 1,60,000 Nil
Is greater than Rs. 1,60,000 and less than or equal to Rs. 5,00,000. (TI - 1,60,000) x 10%
Is greater than Rs. 5,00,000 and less than or equal to Rs. 8,00,000 [(TI - 5,00,000) x 20%] + 34,000
Is greater than Rs. 8,00,000 [(TI - 8,00,000) x 30%] + 94,000
Write a program to input the age, gender (male or female) and Taxable Income of a person.
If the age is more than 65 years or the gender is female, display “wrong category”. If the age is less
than or equal to 65 years and the gender is male, compute and display the income tax payable as per
the table given above.
3. Write a program to accept a string. Convert the string into upper case letters. Count and output the
number of double letter sequences that exist in the string.
Sample Input: "SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE"
Sample Output: 4
4. 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:
Input value of n=2, ch = 'O'
Output:
OO
OO
Input value of x = 2, y = 5
Output:
@@@@@
@@@@@
Output:
*
**
***
5. Using a switch statement, write a menu driven program to:
(a) Generate and display the first 10 terms of the Fibonacci series
0, 1, 1, 2, 3, 5
The first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous
two.
(b) Find the sum of the digits of an integer that is input.
Sample Input: 15390
Sample Output: Sum of the digits = 18
For an incorrect choice, an appropriate error message should be displayed.
6. Write a program to accept the names of 10 cities in a single dimensional string array and their STD
(Subscribers Trunk Dialling) codes in another single dimension integer array. Search for the name of
a city input by the user in the list. If found, display "Search Successful" and print the name of the city
along with its STD code, or else display the message "Search unsuccessful, no such city in the list".

2013:
1. Define a class named FruitJuice with the following description:
Data Members Purpose
int product_code stores the product code number
String flavour stores the flavour of the juice (e.g., orange, apple, etc.)
String pack_type stores the type of packaging (e.g., tera-pack, PET bottle, etc.)
int pack_size stores package size (e.g., 200 mL, 400 mL, etc.)
int product_price stores the price of the product

Member Methods Purpose


FruitJuice() constructor to initialize integer data members to 0 and string data members to ""
void input() to input and store the product code, flavour, pack type, pack size and product price
void discount() to reduce the product price by 10
void display() to display the product code, flavour, pack type, pack size and product price

2. The International Standard Book Number (ISBN) is a unique numeric book identifier which is
printed on every book. The ISBN is based upon a 10-digit code.
The ISBN is legal if:
1 × digit1 + 2 × digit2 + 3 × digit3 + 4 × digit4 + 5 × digit5 + 6 × digit6 + 7 × digit7 + 8 × digit8 + 9
× digit9 + 10 × digit10 is divisible by 11.
Example:
For an ISBN 1401601499
Sum = 1 × 1 + 2 × 4 + 3 × 0 + 4 × 1 + 5 × 6 + 6 × 0 + 7 × 1 + 8 × 4 + 9 × 9 + 10 × 9 = 253 which is
divisible by 11.
Write a program to:
Input the ISBN code as a 10-digit integer.
If the ISBN is not a 10-digit integer, output the message "Illegal ISBN" and terminate the program.
If the number is divisible by 11, output the message "Legal ISBN". If the sum is not divisible by 11,
output the message "Illegal ISBN".
3. Write a program that encodes a word into Piglatin. To translate word into Piglatin word, convert the
word into uppercase and then place the first vowel of the original word as the start of the new word
along with the remaining alphabets. The alphabets present before the vowel being shifted towards the
end followed by "AY".
Sample Input 1: London
Output: ONDONLAY
Sample Input 2: Olympics
Output: OLYMPICSAY
4. Write a program to input 10 integer elements in an array and sort them in descending order using
bubble sort technique.
5. 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
6. Using the switch statement, write a menu driven program:
To check and display whether a number input by the user is a composite number or not.
A number is said to be composite, if it has one or more than one factors excluding 1 and the number
itself.
Example: 4, 6, 8, 9...
To find the smallest digit of an integer that is input:
Sample input: 6524
Sample output: Smallest digit is 2
For an incorrect choice, an appropriate error message should be displayed.

2014:
1. Define a class named movieMagic with the following description:
Data Members Purpose
int year To store the year of release of a movie
String title To store the title of the movie
float rating To store the popularity rating of the movie
(minimum rating=0.0 and maximum rating=5.0)

Member Methods Purpose


movieMagic() Default constructor to initialize numeric data members to 0 and String data member to "".
void accept() To input and store year, title and rating
void display() To display the title of the movie and a message based on the rating as per the table given
below
Ratings Table:
Rating Message to be displayed
0.0 to 2.0 Flop
2.1 to 3.4 Semi-Hit
3.5 to 4.4 Hit
4.5 to 5.0 Super-Hit
Write a main method to create an object of the class and call the above member methods.
2. A special two-digit number is such that when the sum of its digits is added to the product of its
digits, the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of digits = 5 * 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If
the value is equal to the number input, then display the message "Special two—digit number"
otherwise, display the message "Not a special two-digit number".
3. Write a program to assign a full path and file name as given below. Using library functions, extract
and output the file path, file name and file extension separately as shown.
Input
C:\Users\admin\Pictures\flower.jpg
Output
Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg
4. 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)
5. Using the switch statement, write a menu driven program to calculate the maturity amount of a Bank
Deposit.
The user is given the following options:
Term Deposit
Recurring Deposit
For option 1, accept principal (P), rate of interest(r) and time period in years(n). Calculate and output
the maturity amount(A) receivable using the formula:
A = P[1 + r / 100]n
For option 2, accept Monthly Installment (P), rate of interest (r) and time period in months (n).
Calculate and output the maturity amount (A) receivable using the formula:
A = P x n + P x (n(n+1) / 2) x r / 100 x 1 / 12
For an incorrect option, an appropriate error message should be displayed.
6. Write a program to accept the year of graduation from school as an integer value from the user.
Using the binary search technique on the sorted array of integers given below, output the message
"Record exists" if the value input is located in the array. If not, output the message "Record does not
exist".
Sample Input:
n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9]
1982 1987 1993 1996 1999 2003 2006 2007 2009 2010
2015:
1. Define a class called ParkingLot with the following description:
Instance variables/data members:
int vno — To store the vehicle number.
int hours — To store the number of hours the vehicle is parked in the parking lot.
double bill — To store the bill amount.
Member Methods:
void input() — To input and store the vno and hours.
void calculate() — To compute the parking charge at the rate of ₹3 for the first hour or part thereof,
and ₹1.50 for each additional hour or part thereof.
void display() — To display the detail.
Write a main() method to create an object of the class and call the above methods.
2. Write two separate programs to generate the following patterns using iteration (loop) statements:
(a)
*
* #
* # *
* # * #
* # * # *
(b)
54321
5432
543
54
5
3. Write a program to input and store roll numbers, names and marks in 3 subjects of n number of
students in five single dimensional arrays and display the remark based on average marks as given
below:
Average Marks Remark
85 — 100 Excellent
75 — 84 Distinction
60 — 74 First Class
40 — 59 Pass
Less than 40 Poor
4. Design a class to overload a function Joystring( ) as follows:
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 = "Cloud computing means Internet based computing"
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. Write a program to input twenty names in an array. Arrange these names in descending order of
letters, using the bubble sort technique.
6. Using switch statement, write a menu driven program to:
(i) To find and display all the factors of a number input by the user ( including 1 and the excluding
the number itself).
Example:
Sample Input : n = 15
Sample Output : 1, 3, 5
(ii) To find and display the factorial of a number input by the user (the factorial of a non-negative
integer n, denoted by n!, is the product of all integers less than or equal to n.)
Example:
Sample Input : n = 5
Sample Output : 5! = 1*2*3*4*5 = 120
For an incorrect choice, an appropriate error message should be displayed.

2016:
1. Define a class named BookFair with the following description:
Instance variables/Data members:
String Bname — stores the name of the book
double price — stores the price of the book
Member methods:
(i) BookFair() — Default constructor to initialize data members
(ii) void Input() — To input and store the name and the price of the book.
(iii) void calculate() — To calculate the price after discount. Discount is calculated based on the
following criteria.
Price Discount
Less than or equal to ₹1000 2% of price
More than ₹1000 and less than or equal to ₹3000 10% of price
More than ₹3000 15% of price
(iv) void display() — To display the name and price of the book after discount.
Write a main method to create an object of the class and call the above member methods.
2. Using the switch statement, write a menu driven program for the following:
(i) To print the Floyd’s triangle [Given below]
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
(b) To display the following pattern:
I
IC
ICS
ICSE
For an incorrect option, an appropriate error message should be displayed.
Special words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice-versa.
Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVIC
All palindromes are special words but all special words are not palindromes.
3. Write a program to accept a word. Check and display whether the word is a palindrome or only a
special word or none of them.
4. 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=x1−x2+x3−x4+x5... ... ... to n termss=1x−2x+3x−4x+5x... ... ... 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)s=1+(1×2)+(1×2×3)+... ... ... +(1×2×3×4... ... ...
×20)
5. Write a program to accept a number and check and display whether it is a Niven number or not.
(Niven number is that number which is divisible by its sum of digits.).
Example:
Consider the number 126. Sum of its digits is 1 + 2 + 6 = 9 and 126 is divisible by 9.
6. Write a program to initialize the seven Wonders of the World along with their locations in two
different arrays. Search for a name of the country input by the user. If found, display the name of the
country along with its Wonder, otherwise display "Sorry not found!".
Seven Wonders:
CHICHEN ITZA, CHRIST THE REDEEMER, TAJ MAHAL, GREAT WALL OF CHINA,
MACHU PICCHU, PETRA, COLOSSEUM
Locations:
MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Examples:
Country name: INDIA
Output: TAJ MAHAL
Country name: USA
Output: Sorry Not found!

2017:
1. Define a class ElectricBill with the following specifications:
class : ElectricBill
Instance variables / data member:
String n — to store the name of the customer
int units — to store the number of units consumed
double bill — to store the amount to be paid
Member methods:
void accept( ) — to accept the name of the customer and number of units consumed
void calculate( ) — to calculate the bill as per the following tariff:
Number of units Rate per unit
First 100 units Rs.2.00
Next 200 units Rs.3.00
Above 300 units Rs.5.00
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
void print( ) — To print the details as follows:
Name of the customer: ………………………
Number of units consumed: ………………………
Bill amount: ………………………
Write a main method to create an object of the class and call the above member methods.
2. Write a program to accept a number and check and display whether it is a spy number or not. (A
number is spy if the sum of its digits equals the product of its digits.)
Example: consider the number 1124.
Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1 x 1 x 2 x 4 = 8
3. Using switch statement, write a menu driven program for the following:
To find and display the sum of the series given below:
S = x1 - x2 + x3 - x4 + x5 .......... - x20
(where x = 2)
To display the following series:
1 11 111 1111 11111
For an incorrect option, an appropriate error message should be displayed.
4. Write a program to input integer elements into an array of size 20 and perform the following
operations:
Display largest number from the array.
Display smallest number from the array.
Display sum of all the elements of the array
5. 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
6. Write a program to input forty words in an array. Arrange these words in descending order of
alphabets, using selection sort technique. Print the sorted array.
2018:
1. Design a class RailwayTicket with following description:
Instance variables/data members:
String name — To store the name of the customer
String coach — To store the type of coach customer wants to travel
long mobno — To store customer’s mobile number
int amt — To store basic amount of ticket
int totalamt — To store the amount to be paid after updating the original amount
Member methods:
void accept() — To take input for name, coach, mobile number and amount.
void update() — To update the amount as per the coach selected (extra amount to be added in the
amount as follows)
Type of Coaches Amount
First_AC 700
Second_AC 500
Third_AC 250
sleeper None
void display() — To display all details of a customer such as name, coach, total amount and mobile
number.
Write a main method to create an object of the class and call the above member methods.
2. Write a program to input a number and check and print whether it is a Pronic number or not. (Pronic
number is the number which is the product of two consecutive integers)
Examples:
12 = 3 x 4
20 = 4 x 5
42 = 6 x 7

3. Write a program in Java to accept a string in lower case and change the first letter of every word to
upper case. Display the new string.
Sample input: we are in cyber world
Sample output: We Are In Cyber World
4. 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
5. Write a menu driven program to display the pattern as per user’s choice.
Pattern 1
ABCDE
ABCD
ABC
AB
A
Pattern 2
B
LL
UUU
EEEE
For an incorrect option, an appropriate error message should be displayed.
6. Write a program to accept name and total marks of N number of students in two single subscript
array name[] and totalmarks[].
Calculate and print:
The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students)/N]
Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]
2019:
1. Design a class name ShowRoom with the following description:
Instance variables / Data members:
String name — To store the name of the customer
long mobno — To store the mobile number of the customer
double cost — To store the cost of the items purchased
double dis — To store the discount amount
double amount — To store the amount to be paid after discount
Member methods:
ShowRoom() — default constructor to initialize data members
void input() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of purchased items, based on following criteria
Cost Discount (in percentage)
Less than or equal to ₹10000 5%
More than ₹10000 and less than or equal to ₹20000 10%
More than ₹20000 and less than or equal to ₹35000 15%
More than ₹35000 20%
void display() — To display customer 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.
2. Using the switch-case statement, write a menu driven program to do the following:
(a) To generate and print Letters from A to Z and their Unicode
Letters Unicode
A 65
B 66
. .
. .
. .
Z 90
(b) Display the following pattern using iteration (looping) statement:
1
12
123
1234
12345
3. Write a program to input 15 integer elements in an array and sort them in ascending order using the
bubble sort technique.
4. 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
5. Write a program to input a sentence and convert it into uppercase and count and display the total
number of words starting with a letter 'A'.
Example:
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY
ARE EVER CHANGING.
Sample Output: Total number of words starting with letter 'A' = 4
6. A tech number has even number of digits. If the number is split in two equal halves, then the square
of sum of these halves is equal to the number itself. Write a program to generate and print all four
digits tech numbers.
Example:
Consider the number 3025
Square of sum of the halves of 3025 = (30 + 25)2
= (55)2
= 3025 is a tech number.

2022:
1. Define a class to perform binary search on a list of integers given below, to search for an element
input by the user, if it is found display the element along with its position, otherwise display the
message "Search element not found".
2, 5, 7, 10, 15, 20, 29, 30, 46, 50
2. Define a class to declare a character array of size ten. Accept the characters into the array and display
the characters with highest and lowest ASCII (American Standard Code for Information Interchange)
value.
EXAMPLE :
INPUT:
'R', 'z', 'q', 'A', 'N', 'p', 'm', 'U', 'Q', 'F'
OUTPUT :
Character with highest ASCII value = z
Character with lowest ASCII value = A
3. Define a class to declare an array of size twenty of double datatype, accept the elements into the
array and perform the following :
Calculate and print the product of all the elements.
Print the square of each element of the array.
4. Define a class to accept a string, and print the characters with the uppercase and lowercase reversed,
but all the other characters should remain the same as before.
EXAMPLE:
INPUT : WelCoMe_2022
OUTPUT : wELcOmE_2022
5. Define a class to declare an array to accept and store ten words. Display only those words which
begin with the letter 'A' or 'a' and also end with the letter 'A' or 'a'.
EXAMPLE :
Input : Hari, Anita, Akash, Amrita, Alina, Devi Rishab, John, Farha, AMITHA
Output: Anita
Amrita
Alina
AMITHA
6. Define a class to accept two strings of same length and form a new word in such a way that, the first
character of the first word is followed by the first character of the second word and so on.
Example :
Input string 1 – BALL
Input string 2 – WORD
OUTPUT : BWAOLRLD
2023:
1. Design a class with the following specifications:
Class name: Student
Member variables:
name — name of student
age — age of student
mks — marks obtained
stream — stream allocated
(Declare the variables using appropriate data types)
Member methods:
void accept() — Accept name, age and marks using methods of Scanner class.
void allocation() — Allocate the stream as per following criteria:
mks stream
>= 300 Science and Computer
>= 200 and < 300 Commerce and Computer
>= 75 and < 200 Arts and Animation
< 75 Try Again
void print() – Display student name, age, mks and stream allocated.
Call all the above methods in main method using an object.
2. Define a class to accept 10 characters from a user. Using bubble sort technique arrange them in
ascending order. Display the sorted array and original array.
3. 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.
4. Define a class to accept a String and print the number of digits, alphabets and special characters in
the string.
Example:
S = "KAPILDEV@83"
Output:
Number of digits – 2
Number of Alphabets – 8
Number of Special characters – 1
5. Define a class to accept values into an array of double data type of size 20. Accept a double value
from user and search in the array using linear search method. If value is found display message
"Found" with its position where it is present in the array. Otherwise display message "not found".
6. Define a class to accept values in integer array of size 10. Find sum of one digit number and sum of
two digit numbers entered. Display them separately.
Example:
Input: a[ ] = {2, 12, 4, 9, 18, 25, 3, 32, 20, 1}
Output:
Sum of one digit numbers : 2 + 4 + 9 + 3 + 1 = 19
Sum of two digit numbers : 12 + 18 + 25 + 32 + 20 = 107

2024 Specimen:
1. Define a class called with the following specifications:
Class name: Eshop
Member variables:
String name: name of the item purchased
double price: Price of the item purchased
Member methods:
void accept(): Accept the name and the price of the item using the methods of Scanner class.
void calculate(): To calculate the net amount to be paid by a customer, based on the following
criteria:
Price Discount
1000 – 25000 5.0%
25001 – 57000 7.5 %
57001 – 100000 10.0%
More than 100000 15.0 %
void display(): To display the name of the item and the net amount to be paid.
Write the main method to create an object and call the above methods.
2. Define a class to accept values in integer array of size 10. Sort them in an ascending order using
selection sort technique. Display the sorted array.
3. Define a class to accept a string and convert it into uppercase. Count and display the number of
vowels in it.
Input: robotics
Output: ROBOTICS
Number of vowels: 3
4. Define a class to accept values into a 3 × 3 array and check if it is a special array. An array is a
special array if the sum of the even elements = sum of the odd elements.
Example:
A[ ][ ]={{ 4 ,5, 6}, { 5 ,3, 2}, { 4, 2, 5}};
Sum of even elements = 4 + 6 + 2 + 4 + 2 = 18
Sum of odd elements = 5 + 5 + 3 + 5 = 18
5. Define a class to accept a 3 digit number and check whether it is a duck number or not.
Note: A number is a duck number if it has zero in it.
Example 1:
Input: 2083
Output: Invalid
Example 2:
Input: 103
Output: Duck number
6. 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