Class - 11 - Practical Project Work
Class - 11 - Practical Project Work
Computer Science
Practical Programs
Q.1. Write a recursive function that computes the sum of all numbers from 1 to n where n is given as
parameter. Use the function name as void int sum(int n).
Q.2. Write a program to input a string. Check and print whether it is a palindrome or not. Use a
recursive function that returns a string after reversing the characters of the given string. A string
is said to be a palindrome if it appears to be same after reversing the characters.
Example: LEVEL
It is a palindrome word.
Q.3. Write a program by using recursive function that finds and prints the tokens present in the given
string.
Hint: Use String Tokenizer to display all the tokens of the string.
Sample Input:
Enter a String: Understanding Computer Science
Sample Output:
Understanding
Computer
Science
Q.4. Write a program to input a number. Use a recursive function that finds and displays the factors
of the number.
Example:
Input: 24
Output: The factors are:
2, 2, 2, 3
Q.5. 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.)
Test your program with the following data and some random data:
Example 1
INPUT:
N = 726
OUTPUT:
48 * 15 = 720
6*1=6
Remaining boxes = 0
Total number of boxes = 726
Total number of cartons = 16
Q.6 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).
Test your program for the following data and some random data:
Example 1
INPUT:
N=3
Team 1: Emus
Team 2: Road Rols
Team 3: Coyote
OUTPUT:
E R C
m o o
u a y
s d o
t
R e
o
l
s
Q.7. 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.
Test your program with the following data and some random data:
Example 1
INPUT:
DAY NUMBER: 255
YEAR: 2018
DATE AFTER (N DAYS): 22
OUTPUT:
DATE: 12TH SEPTEMBER, 2018
DATE AFTER 22 DAYS: 4TH OCTOBER, 2018
Example 2
INPUT:
DAY NUMBER: 360
YEAR: 2018
DATE AFTER (N DAYS): 45
OUTPUT:
DATE: 26TH DECEMBER, 2018
DATE AFTER 45 DAYS: 9TH FEBRUARY, 2019
Q.8. 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.
Test your program for the following data and some random data:
Example 1
INPUT:
N=3
ENTER ELEMENTS OF SINGLE DIMENSIONAL ARRAY: 3 1 7
OUTPUT:
SORTED ARRAY: 1 3 7
FILLED MATRIX
137
131
113
Q.9. 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 uppercase.
Perform the following tasks:
(a) Check for the validity of the accepted sentence.
(b) Convert the non-palindrome words of the sentence into palindrome words by
concatenating the word by its reverse (excluding the last character).
Example:
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.]
(c) Display the original sentence along with the converted sentence.
Test your program for the following data and some random data:
Example 1
INPUT:
THE BIRD IS FLYING.
OUTPUT:
THE BIRD IS FLYING.
THEHT BIRDRIB ISI FLYINGNIYLF
Q.10. 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:
1 4 4 100