Computer Project
Computer Project
Acknowledgement
Secondly I would also like to thank my parents and friends who helped me
a lot in fi nalizing this project within the limited time frame.
Computer Project
Name:
Class:
Index
Question 1
A Circular Prime is a prime number that remains prime under cyclic shifts of its digits.
When the leftmost digit is removed and replaced at the end of the remaining string of
digits, the generated number is still prime. The process is repeated until the original
number is reached again.
A number is said to be prime if it has only two factors 1 and itself.
Example:
131
311
113
Hence, 131 is a circular prime.
Test your program with the sample data and some random data:
Example 1
INPUT :N = 197
OUTPUT:
197
971
719
197 IS A CIRCULAR PRIME
Example 2
INPUT :N = 1193
OUTPUT:
1193
1931
9311
f3119
1193 IS A CIRCULAR PRIME
Example 3
INPUT :N = 29
OUTPUT:
29
92
29 IS NOT A CIRCULAR PRIME
Question 2
Write a program to declare a square matrix A[][] of order (M x M) where ‘M’ must be
greater than 3 and less than 10. Allow the user to input positive integers into this matrix.
Perform the following tasks on the matrix:
1. Sort the non-boundary elements in ascending order using any standard sorting
technique and rearrange them in the matrix.
2. Calculate the sum of both the diagonals.
3
3. Display the original matrix, rearranged matrix and only the diagonal elements of
the rearranged matrix.
Test your program with the sample data and some random data:
Example 1
INPUT :M = 4
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
OUTPUT:
ORIGINAL MATRIX
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
REARRANGED MATRIX
9 2 1 5
8 3 6 4
15 8 13 11
7 12 23 8
DIAGONAL ELEMENTS
9 5
3 6
8 13
7 8
Question 3
Write a program to accept a sentence which may be terminated by either '.', '?' or '!' only.
The words may be separated by more than one blank space and are in UPPER CASE.
Perform the following tasks:
1. Find the number of words beginning and ending with a vowel.
2. Place the words which begin and end with a vowel at the beginning, followed by
the remaining words as they occur in the sentence.
Test your program with the sample data and some random data:
Example 1
Example 2
3
Question 4
Given two positive numbers M and N, such that M is between 100 and 10000 and N is
less than 100. Find the smallest integer that is greater than M and whose digits add up
to N. For example, if M=100 and N=11, then the smallest integer greater than 100
whose digits add up to 11 is 119.
Write a program to accept the numbers M and N from the user and print the smallest
required number whose sum of all its digits is equal to N. Also, print the total number of
digits present in the required number. The program should check for the validity of the
inputs and display an appropriate message for an invalid input.
Test your program with the sample data and some random data:
Example 1
INPUT :
M = 100
N = 11
OUTPUT :
The required number = 119
Total number of digits = 3
Example 2
INPUT :
M = 1500
N = 25
OUTPUT :
The required number = 1699
Total number of digits = 4
Example 3
INPUT :
M = 99
N = 11
OUTPUT :
INVALID INPUT
Example 4
INPUT :
M = 112
N = 130
OUTPUT :
INVALID INPUT
Question 5
3
Write a program to declare a square matrix A[][] of order M×M where ‘M’ is the number
of rows and the number of rows and the number of columns, such that M must be
greater than 2 and less 10. Accept the value M as user input. Display an appropriate
message for an invalid input. Allow the user to input integers into the matrix. Perform
the following tasks:
1. Display the original matrix.
2. Rotate the matrix 90ᵒ clockwise as shown below:
Original matrix Rotated matrix
1 2 3 7 4 1
4 5 6 8 5 2
7 8 9 9 6 3
3. Find the sum of the elements of the four corners of the matrix.
Example 1
INPUT :
M=3
OUTPUT :
ORIGINAL MATRIX
OUTPUT :
ORIGINAL MATRIX
Question 6
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. Print an error message if the
input does not terminate with ‘.’ Or ‘?’. You can assume that no word in the sentence
exceeds 15 characters, so that you get a proper formatted output.
Perform the following tasks:
1. Convert the first letter of each word to uppercase.
2. Find the number of vowels and consonants in each word and display them with
proper headings along with the words.
Test your program with the following inputs.
Example 1
INPUT: Intelligence plus character is education.
OUTPUT:
Intelligence Plus Character Is Education
WORD VOWELS CONSONANTS
Intelligence 5 7
Plus 1 3
Character 3 6
Is 1 1
Education 5 4
Example 2
INPUT: God is great.
OUTPUT:
God Is Great
WORDS VOWELS CONSONANTS
3
God 1 2
Is 1 1
Great 2 3
Example 3
INPUT: All the best!
OUTPUT:
Invalid Input.
Question 7
A composite Magic number is a positive integer which is composite as well as a magic
number.
Composite number: A composite number is a number which has more than two factors.
For example: 10 Factors are: 1,2,5,10
Magic number: A Magic number is a number in which the eventual sum of the digit d is
equal to 1. For example: 28 = 2+8=10= 1+0=1
Accept two positive integers m and n, where m is less than n as user input. Display the
number of composite magic integers that are in the range between m and n (both
inclusive) and output them along with frequency, in the format specified below:
Example 1:
INPUT:
m = 10
n = 100
OUTPUT:
THE COMPOSITE MAGIC INTEGERS ARE:
10, 28, 46, 55, 64, 82, 91, 100
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 8
Example 2:
INPUT:
m = 1200
n = 1300
OUTPUT:
THE COMPOSITE MAGIC INTEGERS ARE:
1207, 1216, 1225, 1234, 1243, 1252, 1261, 1270, 1288
FREQUENCY OF COMPOSITE MAGIC INTEGERS IS: 9
Example 3:
INPUT:
m = 120
n = 99
OUTPUT:
INVALID INPUT
Question 8
3
Write a program to declare a square matrix A[][] of order MXM where M is an positive
integer and represents row and column. M should be greater than 2 and less than
10.Accept the value of M from user. Display an appropriate message for invalid input.
Perform the following task:
1. Display the original matrix
2. Check if the given matrix is symmetric or not. If the element of the ith row and jth
column is same as element of the jth row and ith column.
3. Find the sum of the left and right diagonal of the matrix and display them
Example 1
INPUT : M=3
1 2 3
2 4 5
3 5 6
OUTPUT :
ORIGINAL MATRIX
1 2 3
2 4 5
3 5 6
THE GIVEN MATRIX IS SYMMETRIC
The sum of the left diagonal = 11
The sum of the right diagonal = 10
Example 2
INPUT : M=4
7 8 9 2
4 5 6 3
8 5 3 1
7 6 4 2
OUTPUT :
ORIGINAL MATRIX
7 8 9 2
4 5 6 3
8 5 3 1
7 6 4 2
THE GIVEN MATRIX IS NOT SYMMETRIC
The sum of the left diagonal = 17
The sum of the right diagonal = 20
Example 3
INPUT : M = 22
OUTPUT : THE MATRIX SIZE IS OUT OF RANGE
Question 9
3
Write a program to accept a sentence which may be terminated by either '.', '?', or '!' only.
Any other character may be ignored. The words may be separated by more than one
blank space and are in UPPER CASE.
Perform the following tasks.
1. Accept the sentence and reduce all the extra blank space between two words to a
single blank space.
2. Accept a word from the user which is part of the sentence along with its position
number and delete the word and display the sentence.
Test your program with the sample data and some random data.
Example 1
INPUT: A MORNING WALK IS A IS BLESSING FOR THE WHOLE DAY.
WORD TO BE DELETED: IS
WORD POSITION IN THE SENTENCE: 6
OUTPUT: A MORNING WALK IS A BLESSING FOR THE WHOLE DAY.
Example 2
INPUT: AS YOU SOW, SO SO YOU REAP.
WORD TO BE DELETED: SO
WORD POSITION IN THE SENTENCE: 4
OUTPUT: AS YOU SOW, SO YOU REAP.
Example 3
INPUT: STUDY WELL ##
OUTPUT: INVALID INPUT
Question 10
An ISBN ( International Standard Book Number) is a ten digit code which uniquely
identifies a book. The first nine digits represent the Group, Publisher and Title of the
book and the last digit is used to check whether ISBN is correct or not.
Each of the first nine digits of the code can take a value between 0 and 9. Sometimes it
is necessary to make the last digit equal to ten; this is done by writing the last digit of
the code as X. To verify an ISBN, calculate 10 times the first digit, plus 9 times the
second digit, plus 8 times the third and so on until we add 1 time the last digit. If the
final number leaves no remainder when divided by 11, the code is a valid ISBN.
For example:
1. 02011003311 = 10 x 0 + 9 x 2 + 8 x 0 + 7 x 1 + 6 x 1 + 5 x 0 + 4 x 3 + 3 x 3 +
2 x 1 + 1 x 1 = 55 Since 55 leaves no remainder when divisible by 11, hence it is a
valid ISBN.
2. 007462542X = 10 x 0 + 9 x 0 + 8 x 7 + 7 x 4 + 6 x 6 + 5 x 2 + 4 x 5 + 3 x 4 + 2
x 2 + 1 x 10 = 176 Since 176 leaves no remainder when divided by 11, hence it is a
valid ISBN.
3. 0112112425 = 10 x 0 + 9 x 1 + 8 x 1 + 7 x 2 + 6 x 1 + 5 x 1 + 4 x 1 + 3 x 4 + 2
x 2 + 1 x 5 = 71 Since 71 leaves no remainder when divided by 11, hence it is not a
valid ISBN.
3
Design a program to accept a ten digit code from the user. For an invalid inout, display
an appropriate message. Verify the code for its validity in the format specified below:
Test your program with sample data and some random data.
Example 1
INPUT CODE: 0201530821
OUTPUT : SUM = 99
LEAVES NO REMAINDER – VALID ISBN CODE
Example 2
INPUT CODE: 035680324
OUTPUT : INVALID INPUT
Example 3
INPUT CODE: 0231428031
OUTPUT : SUM = 122
LEAVES REMAINDER – INVALID ISBN CODE
Question 11
Write a program to declare a square matrix A[][] of order (M X M) where 'M' is the
number of rows and the number of columns such that M must be greater than 2 and less
than 20. Allow the user to input integers into this matrix. Display appropriate error
message for an invalid input. Perform the following tasks:
1. Display the input matrix.
2. Create a mirror image of the inputted matrix.
3. Display the mirror image matrix.
Test your program for the following data and some random data:
Example 1
INPUT : M = 3
4 16 12
8 2 14
4 1 3
OUTPUT :
ORIGINAL MATRIX
4 16 12
8 2 14
4 1 3
MIRROR IMAGE MATRIX
12 16 4
14 2 8
3 1 6
Example 2
INPUT : M = 22
OUTPUT : SIZE OUT OF RANGE
3
Question 12
A palindrome is a word that may be read the same way in either direction. Accept a
sentence in UPPER CASE which is terminated by either ".", "?", or "!". Each word of the
sentence is separated by a single blank space.
Perform the following tasks:
1. Display the count of palindromic words in the sentence.
2. Display the palindromic words in the sentence.
Example of palindromic words:
MADAM, ARORA, NOON
Test your program with the sample data and some random data:
Example 1
INPUT : MOM AND DAD ARE COMING AT NOON.
OUTPUT : MOM DAD NOON
NUMBER OF PALINDROMIC WORDS : 3
Example 2
INPUT : NITIN ARORA USES LIRIL SOAP.
OUTPUT : NITIN ARORA LIRIL
NUMBER OF PALINDROMIC WORDS : 3
Example 3
INPUT : HOW ARE YOU?
OUTPUT : NO PALINDROMIC WORDS
3
Question 13
A prime palindrome integer is a positive integer (without leading zeros) which is prime as
well as a palindrome. Given two positive integers m and n, where m < n, write a program
to determine how many prime-palindrome integers are there in the range between m and
n (both inclusive) and output them.
The input contains two positive integers m and n where m < 3000 and n < 3000. Display
the number of prime palindrome integers in the specified range along with their values in
the format specified below:
Test your program with the sample data and some random data:
Example 1
INPUT:
m=100
n = 1000
OUTPUT:
THE PRIME PALINDROME INTEGERS ARE:
101, 131, 151, 181, 191, 313, 353, 373, 383, 727, 757, 787, 797, 919, 929
FREQUENCY OF PRIME PALINDROME INTEGERS : 15
Example 2
INPUT:
m = 100
n = 5000
OUTPUT: OUT OF RANGE
Question 14
Write a program to accept a sentence as input. The words in the string are to be
separated by a blank. Each word must be in upper case. The sentence is terminated by
either '.','!' or '?'. Perform the following tasks:
1. Obtain the length of the sentence (measured in words)
2. Arrange the sentence in alphabetical order of the words.
Test your program with the sample data and some random data:
Example 1:
INPUT: NECESSITY IS THE MOTHER OF INVENTION.
OUTPUT:
Length: 6
Rearranged Sentence:
INVENTION IS MOTHER NECESSITY OF THE
Example 2:
INPUT: BE GOOD TO OTHERS.
OUTPUT:
Length: 4
Rearranged Sentence: BE GOOD OTHERS TO
3
Question 15
Write a program to declare a matrix A [][] of order (MXN) where 'M' is the number of
rows and 'N' is the number of columns such that both M and N must be greater than 2
and less than 20. Allow the user to input integers into this matrix.
Perform the following tasks on the matrix:
1. Display the input matrix
2. Find the maximum and minimum value in the matrix and display them along with
their position.
3. Sort the elements of the matrix in ascending order using any standard sorting
technique and rearrange them in the matrix.
Output the rearranged matrix.
Example 1
INPUT:
M=3
N=4
Entered values: 8,7,9,3,-2,0,4,5,1,3,6,-4
OUTPUT:
Original matrix:
8 7 9 3
-2 0 4 5
1 3 6 -4
Largest Number: 9
Row: 0
Column: 2
Smallest Number: -4
Row=2
Column=3
Rearranged matrix:
-4 -2 0 1
3 3 4 5
6 7 8 9
Question 16
Write a program to input a natural number less than 1000 and display it in words. Test
your program on the sample data and some random data.
Sample input and output of the program
Examples
Input: 29
Output: TWENTY NINE
Input: 17001
Output: OUT OF RANGE
Input: 119
3
Question 17
Encryption is a technique of coding messages to maintain their secrecy. A String array of
size 'n' where 'n' is greater than 1 and less than 10, stores single sentences (each
sentence ends with a full stop) in each row of the array.
Write a program to accept the size of the array.
Display an appropriate message if the size is not satisfying the given condition.
Define a string array of the inputted size and fill it with sentences row-wise. Change the
sentence of the odd rows with an encryption of two characters ahead of the original
character.
Also change the sentence of the even rows by storing the sentence in reverse order.
Display the encrypted sentences as per the sample data given below.
Test your program on the sample data and some random data.
Example 1
INPUT: n = 4
IT IS CLOUDY.
IT MAY RAIN.
THE WEATHER IS FINE.
IT IS COOL.
OUTPUT:
KV KU ENQWFA.
RAIN MAY IT.
VJG YGCVJGT KU HKPG.
COOL IS IT.
Question 18
Design a program which accepts your date of birth in dd mm yyyy format. Check
whether the date entered is valid or not.
If it is valid, display "VALID DATE", also compute and display the day number of the year
for the date of birth. If it is invalid, display "INVALID DATE" and then terminate the
program.
Testing of the program
Example 1
INPUT: Enter your date of birth in dd mm yyyy format
05
01
2010
OUTPUT: VALID DATE
3
5
Example 2
INPUT: Enter your date of birth in dd mm yyyy format
03
04
2010
OUTPUT: VALID DATE
93
Example 3
INPUT: Enter your date of birth in dd mm yyyy format
34
06
2010
OUTPUT: INVALID DATE
Question 19
A bank intends to design a program to display the denomination of an input amount,
upto 5 digits. The available denomination with the bank are of rupees
1000,500,100,50,20,10,5,2 and 1.
Design a program to accept the amount from the user and display the break-up in
descending order of denominations. (i.e. preference should be given to the highest
denomination available) along with the total number of notes. [Note: only the
denomination used should be displayed]. Also print the amount in words according to
the digits.
Example 1
INPUT: 14836
OUTPUT: ONE FOUR EIGHT THREE SIX
DENOMINATION:
1000 X 14 =14000
500 X 1 =500
100 X 3 =300
50 X 1 =50
5 X 1 =5
1 X 1 =1
Example 2
INPUT: 235001
OUTPUT: INVALID AMOUNT
Question 20
Given the two positive integers p and q, where p < q. Write a program to determine how
many kaprekar numbers are there in the range between 'p' and 'q'(both inclusive) and
output them.About 'kaprekar' number:
3
A positive whole number 'n' that has 'd' number of digits is squared and split into 2
pieces, a right hand piece that has 'd' digits and a left hand piece that has remaining 'd' or
'd-1' digits. If sum of the pieces is equal to the number then it's a kaprekar number.
Example 1
INPUT:
p=1
q=1000
OUTPUT:
THE KAPREKAR NUMBERS ARE:
1,9,45,55,99,297,999
FREQUENCY OF KAPREKAR NUMBERS IS:8
Question 21
Input a paragraph containing 'n' number of sentences where (1<=n<=4). The words are
to be separated with single blank space and are in upper case. A sentence may be
terminated either with a full stop (.) or question mark (?).
Perform the following:
1. Enter the number of sentences, if it exceeds the limit show a message.
2. Find the number of words in the paragraph
3. Display the words in ascending order with frequency.
Example 1
INPUT: Enter number of sentences: 1
Enter sentences:
TO BE OR NOT TO BE.
OUTPUT:
Total number of words: 6
WORD FREQUENCY
OR 1
NOT 1
TO 2
BE 2
Example 2
INPUT: Enter number of sentences: 3
Enter sentences:
THIS IS A STRING PROGRAM. IS THIS EASY? YES, IT IS.
OUTPUT:
Total number of words: 11
WORD FREQUENCY
A 1
STRING 1
PROGRAM 1
3
EASY 1
YES 1
IT 1
THIS 2
IS 3
Question 22
A class Employee contains employee details and another class Salary calculates the
employee’s net salary. The details of the two classes are given below.
Class name – Employee
Data Members-:
empno - to store employee no
empname - to store employee name
empdesign – to store designation
Member Functions-:
Employee( ) - default contructor
Employee(---) - parameterized constructor
void display( ) – to display data members with proper message
Display the details of the class Employee and the net salary
Specify the class Employee giving the details of the functions using the concept of
inheritance and also specify the class in which object is created and functions are called
in the main function
Question 23
Data Members-:
n - to store the number
Member Functions-:
Prime(int) - constructor to initialize n
void check( ) - to check if the no is prime or not by calling a function isPrime(int)
boolean isPrime(int) - returns true/false for prime using recursive technique
Question 24
Design a class Stack-:
Data Members-:
int arr[ ] – size 50
int size – store no of elements
int top
Member Functions-:
Stack(int s) – to initialize the size by s and top by -1
void pushvalues(int v) – to fill the stack if it is empty otherwise display message –
“overflow”
int popvalues() – to delete value from the stack and return it, if possible
otherwise display – “underflow” and return -999
void display()
Question 25
Design a class SQ
Data Members-:
int arr[ ] – max size 100
int size – store the capacity of arr
int front
int rear
Member Functions-:
SQ(int s) – to initialize the size and front and rear by -1
void addrear(int v) – to add value at rear if possible otherwise display “Queue full
at the rear end… OVERFLOW”
int deletefront() – to delete value from front if possible otherwise display “Queue
empty…UNDERFLOW”
void display() – display elements of the queue
NOTE : you can replace the last 4 questions by any 4 questions of your choice.