Program List
Program List
Program List
Write a program to accept an integer array of maximum 9 elements and sort the
array using standard Insertion Sort Algorithm in Descending order.
2. Write a program to Accept a 5 Digit number from the user and rearrange the
digits to display the highest possible number. Repetition of digits is allowed.
3. Write a program to Add two binary Numbers bit by bit, using standard Binary
Addition rules.
9. A Goldbach number is a positive even integer that can be expressed as the sum of
two odd primes.
Note: All even integer numbers greater than 4 are Goldbach numbers. Example:
6=3+3
10 = 3 + 7
10 = 5 + 5
Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs,
i.e.
3 and 7, 5 and 5.
Write a program to accept an even integer 'N' where N > 9 and N < 50. Find all the
odd prime pairs whose sum is equal to the number 'N'.
10. Write a program to declare a matrix a[][] of order (m × n) where 'm' is the number
of rows and 'n' is the number of columns such that the values of both 'm' and 'n'
must be greater than 2 and less than 10. Allow the user to input integers into this
matrix. Perform the following tasks on the matrix:
• Display the original matrix.
• Sort each row of the matrix in ascending order using any standard sorting
technique. Display the changed matrix after sorting each row.
12. Design a program to accept a day number (between 1 and 366), year (in 4 digits)
from the user to generate and display the corresponding date. Also, accept 'N' (1
<= N <= 100) from the user to compute and display the future date corresponding
to 'N' days after the generated date. Display an error message if the value of the
day number, year and N are not within the limit or not according to the condition
specified.
13. Write a program to declare a single-dimensional array a[] and a square matrix
b[][] of size N, where N > 2 and N < 10. Allow the user to input positive integers
into the single dimensional array.
Perform the following tasks on the matrix:
• Sort the elements of the single-dimensional array in ascending order using any
standard sorting technique and display the sorted elements.
• Fill the square matrix b[][] in the following format:
If the array a[] = {5, 2, 8, 1} then, after sorting a[] = {1, 2, 5, 8}. Then, the matrix
b[][] would fill as below:
1258
1251
1212
1125
• Display the filled matrix in the above format.
14. The reverse of the word HELP would be LEH (omitting the last alphabet) and by
concatenating both, the new palindrome word is HELPLEH. Thus, the word HELP
becomes HELPLEH.
Note: The words which end with repeated alphabets, for example ABB would
become ABBA and not ABBBA and XAZZZ becomes XAZZZAX. [Palindrome word:
Spells same from either side. Example: DAD, MADAM etc.]
Display the original sentence along with the converted sentence.
16. Write a program to declare a matrix A[][] of order (M x N) where 'M' is the
number of rows and 'N' is the number of columns such that the value of 'M' must
be greater than 0 and less than 10 and the value of 'N' must be greater than 2 and
less than 6. Allow the user to input digits (0 - 7) only at each location, such that
each row represents an octal number. Example:
2 3 1 (Decimal equivalent of 1st row = 153 i.e. 2x82 + 3x81 + 1x80)
4 0 5 (Decimal equivalent of 2nd row = 261 i.e. 4x82 + 0x81 + 5x80)
1 5 6 (Decimal equivalent of 3rd row = 110 i.e. 1x82 + 5x81 + 6x80)
17. Write a program to accept a sentence which may be terminated by either '.', '?' or
'!' only. The words are to be separated by a single blank space and are in UPPER
CASE.
Perform the following tasks:
• Check for the validity of the accepted sentence only for the terminating character.
• Arrange the words in ascending order of their length. If two or more words have
the same length, then sort them alphabetically.
Display the original sentence along with the converted sentence.
18. Write a menu driven program which provides the user with a menu of options to
implement any of the following: -
1. Factorial of a Number
2. Nth Fibonacci Number
3. Sum of First N natural numbers
4. Sum of Natural numbers within a given range
5. Power (a^b)
6. Factors of a number
7. Prime Number Check
The following should be implemented using recursion with a separate Recursive
function for each of them.
19. An interface Shape is defined with a method area() which returns the area of the
implementing shape.
Create the classes Circle and Rectangle which implement the interface Shape.
These classes have attributes which reflect their dimensions (radius for a circle,
height and width for a rectangle) which are set by their constructors.
The details of the members of the interface and both the classes are given below:
Interface name: Shape
Member functions/methods:
double area(): returns the area of the implementing shape
Class name: Circle
Data members/instance variables:
radius: to store radius of the circle in decimal
Member functions/methods:
Circle(int r): parameterized constructor to initialize radius = r
double area(): to calculate area of the circle [area of a circle is 3.14*radius*radius]
Class name: Rectangle
Data members/instance variables:
length: to store length of the rectangle in decimal breadth:
to store breadth of the rectangle in decimal Member
functions / methods:
Rectangle(int l, int b): parameterized constructor to initialize length=l, breadth=b
double area(): to calculate area of the rectangle [ area of a rectangle is
length*breadth]
Assume that the Interface Shape has been defined. Using the concept of
inheritance, specify the classes Circle and Rectangle giving details of their
constructors and double area( ), respectively.
20. A superclass Record contains names and marks of the students in two different
single dimensional arrays. Define a subclass Highest to display the names of the
students obtaining the highest mark
The details of the members of both classes are given below:
Class name: Record
Data member/instance variable:
N[] : array to store names
M[]: array to store marks
Size: to store the number of students Member
functions/methods:
Record(int cap): parameterized constructor to initialize the data member Size=cap
Void readarray() : to enter elements in both the arrays void display(): displays the
array elements
Class name: Highest
Data member/instance variable:
Ind: to store the index
Member functions/methods:
Highest(…): parameterized constructor to initialize the data members of both the
classes
Void find(): finds the index of the student obtaining the highest mark and assign it
to ‘ind’
Void display(): displays the array elements along with the names and marks of the
students who have obtained the highest mark.
Assume that the superclass Record has been defined. Using the concept of
inheritance, specify the class Highest giving the details of the constructor(…), void
find() and void display().
Assume that the superclass Product has been defined. Using the concept of
inheritance, specify the class Sales giving the details of the constructor (…), void
compute() ) and void show().
23. A superclass Bank has been defined to store the details of a customer. Define a
sub-class Account that enables transactions for the customer with the bank. The
details of both the classes are given below:
Class name: Bank
Data members/instance variables:
Name: stores the name of the customer
Accno: stores the account number P:
stores the principal amount in decimals
Member functions/methods:
Bank(….): parameterized constructor to assign values to the instance variables
Void display (): displays the details of the customer
Using the concept of Inheritance; specify the class Account giving details of the
constructor(…), void deposit(), void withdraw() and void display().
24. A line on a plane can be represented by coordinates of the two-end points p1 and
p2 as p1 (x1, y1) and p2 (x2, y2).
A superclass Plane is defined to represent a line and a subclass Circle to find the
length of the radius and the area of the circle by using the required data members
of the superclass.
Some of the members of both classes are given below:
Class name: Plane
Data members/instance variables:
x1: to store the x-coordinate of the first endpoint y1:
to store the y-coordinate of the first endpoint
Member functions/methods:
Plane (int nx, int ny): parameterized constructor to assign the data members
x1=nx and y1=ny
void show(): to display the coordinates
Specify the class Plane giving details of the constructor and void show() Using the
concept of inheritance, specify the class Circle giving details of the constructor,
void findRadius(), void find Area() and voidShow().
25. A superclass Stock has been defined to store the details of the stock of a retail
store. Define a subclass Purchase to store the details of the items purchased with
the new rate and updates the stock. Some of the members of the classes are
given below:
Class name: Stock
Data members/instance variables: item: to
store the name of the item qt: to store the
quantity of an item in stock rate: to store the
unit price of an item amt: to store the net
value of the item in stock Member functions:
Stock (…): parameterized constructor to assign values to the data members void
display(): to display the stock details