Program List

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

1.

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.

4. Accept a paragraph with N number of sentences (2<=N<=6). Reform each


sentence based on the descending order of the length of words. If 2 or more
words have the same length, they can appear in order of appearance. A sentence
is valid if and only if it ends in a ‘.’, ‘?’ or ‘!’

5. Write a program to find a 9-digit number that is divisible by 9. On removing the


last digit, number should be divisible by 8. This continues till last digit is divisible
by
1. Display the frequency of all such numbers.

6. A company manufactures packing cartons in four sizes, i.e., cartons to


accommodate 6 boxes, 12 boxes, 24 boxes and 48 boxes. Design a program to
accept the number of boxes to be packed (N) by the user (maximum up to 1000
boxes) and display the break-up of the cartons used in descending order of
capacity (i.e. preference should be given to the highest capacity available, and if
boxes left are less than 6, an extra carton of capacity 6 should be used.)

7. The result of a quiz competition is to be prepared as follows:


The quiz has five questions with four multiple choices (A, B, C, D), with each
question carrying 1 mark for the correct answer. Design a program to accept the
number of participants N such that N must be greater than 3 and less than 11.
Create a double-dimensional array of size (Nx5) to store the answers of each
participant row-wise. Calculate the marks for each participant by matching the
correct answer stored in a single- dimensional array of size 5. Display the scores
for each participant and also the participant(s) having the highest score.
Example: If the value of N = 4, then the array would be:
Q1 Q2 Q3 Q4 Q5
Participant 1 A B B C A
Participant 2 D A D C B
Participant 3 A A B A C
Participant 4 D C C A B
Key to the question: D C C B A
Note: Array entries are line fed (i.e., one entry per line)

8. Caesar Cipher is an encryption technique which is implemented as ROT13 ('rotate


by 13 places'). It is a simple letter substitution cipher that replaces a letter with
the letter 13 places after it in the alphabets, with the other characters remaining
unchanged.
A/a B/b C/c D/d E/e F/f G/g H/h I/i J/j K/k L/l M/m
↕↕↕↕↕↕↕↕↕↕↕↕↕
N/n O/o P/p Q/q R/r S/s T/t U/u V/v W/w X/x Y/y Z/z
Write a program to accept a plain text of length L, where L must be greater than 3
and less than 100. Encrypt the text if valid as per the Caesar Cipher.

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.

11. The names of the teams participating in a competition should be displayed on a


banner vertically, to accommodate as many teams as possible in a single banner.
Design a program to accept the names of N teams, where 2 < N < 9 and display
them in vertical order, side by side with a horizontal tab (i.e. eight spaces).

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.

15. A Prime-Adam integer is a positive integer (without leading zeros) which is a


prime as well as an Adam number.
Prime number: A number which has only two factors, i.e. 1 and the number itself.
Example: 2, 3, 5, 7 ... etc.
Adam number: The square of a number and the square of its reverse are reverse
to each other.
Example: If n = 13 and reverse of 'n' = 31, then, (13)2 = 169
(31)2 = 961 which is reverse of 169 thus 13, is an Adam number.
Accept two positive integers m and n, where m is less than n as user input.
Display all Prime-Adam integers that are in the range between m and n (both
inclusive) and output them along with the frequency

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)

Perform the following tasks on the matrix:


• Display the original matrix.
• Calculate the decimal equivalent for each row and display as per the format given
below.

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().

21. A superclass Number is defined to calculate the factorial of a number. Define a


subclass Series to find the sum of the series S = 1! + 2! + 3! + 4! +…+ n!
The details of the members of both classes are given below:
Class name: Number
Data member/instance variable: N:
to store an integer number
Member functions/methods:
Number(int nn): parameterized constructor to initialize the data member n=nn
Int factorial(int a): returns factorial of a number (factorial of n = 1 × 2 × 3 × .. × n)
Void display()
Class name: Series
Data member/instance variable:
Sum: to store the sum of the series
Member functions/methods:
Series(…) : parameterized constructor to initialize the data members of both the
classes
Void calsum(): calculates the sum of the given series
Void display(): displays the data members of both the classes
Assume that the superclass Number has been defined. Using the concept of
inheritance, specify the class Series giving the details of the constructor(…), void
calsum() and void display().
22. A superclass Product has been defined to store the details of a product sold by a
wholesaler to a retailer. Define a subclass Sales to compute the total amount paid
by the retailer with or without fine along with service tax.
Some of the members of both classes are given below:
Class name: Product
Data members/instance variables:
Name: stores the name of the product
Code: integer to store the product code
Amount: stores the total sale amount of the product (in decimals) Member
functions/methods:
Product (String n, int c, double p): parameterized constructor to assign data
members: name = n, code = c and amount = p
Void show(): displays the details of the data members

Class name: Sales


Data members/instance variables:
Day: stores number of days taken to pay the sale amount
Tax: to store the sen ice tax (in decimals) Totamt:
to store the total amount (in decimals) Member
functions/methods:
Sales(….): parameterized constructor to assign values to data members of both
the classes
Void compute(): calculates the service tax @ 12.4% of the actual sale amount
Calculates the fine @ 2.5% of the actual sale amount only if the amount paid by
the retailer to the wholesaler exceeds 30 days calculates the total amount paid by
the retailer as (actual sale amount + service tax + fine)
Void show (): displays the data members of the superclass and the total amount

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

Class name: Account


Data member/instance variable:
Amt: stores the transaction amount in decimals Member
functions/methods:
Account(…): parameterized constructor to assign values to the instance variables
of both the classes
Void deposit(): accepts the amount and updates the principal as p=p+amt
Void withdraw(): accepts the amount and updates the principal as p=p-amt If
the withdrawal amount is more than the principal amount, then display the
message “INSUFFICIENT BALANCE”.
If the principal amount after withdrawal is less than 500, then a penalty is
imposed by using the formula. P=p-(500-p)/10
Void display(): displays the details of the customer Assume that the superclass
Bank has been defined.

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

Class name: Circle


Data members /instance variables:
x2: to store the x-coordinate of the second endpoint y2:
to store the y-coordinate of the second endpoint
radius: double variable to store the radius of the circle
area: double variable to store the area of the circle
Member functions/methods:
Circle(…): parameterized constructor to assign values to data members of both
the classes void findRadius(): to calculate the length of the radius using the
formula: ((x2−x1)2+(y2−y1)2−−−−−−−−−−−−−−−−−−−√)/2 assuming that x1, x2,
y1, y2 are the coordinates of the two ends of the diameter of a circle
voidfindArea(): to find the area of a circle using the formula: πr2. The value of
pi(π) is 22/7 or 3.14 void show(): to display both the coordinates along with
the length of the radius and area of the circle

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

Class name: Purchase


Data members/instance variables:
Pqty: to store the purchased quantity
Prate: to store the unit price of the purchased item Member
functions/ methods:
Purchase(…): parameterized constructor to assign values to the data members of
both classes
Void update (): to update stock by adding the previous quantity by the purchased
quantity and replace the rate of the item if there is a difference in the purchase
rate. Also, update the current stock value as (quantity * unit price)
Void display(): to display the stock details before and after updating.
Specify the class Stock, giving details of the constructor() and void display(). Using
the concept of inheritance, specify the class Purchase, giving details of the
constructor(), void update() and Void display().

You might also like