Computer Practical Assignment Questions:
1. Write a program to input a sentence which ends with(?)or(!)or(.). Reverse each word and
form a new sentence . Count and display the number of words which starts and ends with
the same character.
Example:” Malayalam is taught in school ?”
Output: The number of words starts and ends with the same character is 2.
2. Class name: Arrange
Data members:
str : to store the string
new _ str: to store the resultant string
Int len: to store the length of this string
Member methods:
Arrange (String s): constructor to assign values to the data members
void manipulate(): arrange the strength in the given order so that all the digits should be first
followed by the revolvers and then consonant.
Input: HELLO123;
Output: ;123EOHLL
void display(): to display the original and the resultant string.
Write a main method to call the functions and create the object.
3. Design of class sword which will arrange a number of elements and find a frequency of
elements in the given array.
Class name: sort
Data members:
B[]: to store the integer elements
f: to store the frequency
n: the store the size of the array
Member methods:
Sort( int x): parameterized constructor to assign n=x and allocate memory of the array input
the elements.
void arrange(): to arrange the element in ascending order using bubbles sort technique.
void display (): to display the frequency in the format given below:
2,3,3,5,9,9,10
2-1 3-2 5-1 9-2 10-1
Specify the class sort with all details of data members and member methods. Write the main
function, create an object and call the methods accordingly to complete.
4. Class name: cypher
Data members
cypher(): default constructor to assign default value to the data members
void accept(): to accept a string
String encrypt(): Converse the string to upper case and converse it to cypher code
void display(): to display the result
Write the main method.
Example:
ABCDEFGH I J K LM
NOPQRSTUVWXYZ
Sample : C O M P U T E R
PBZ CHGRE
5. Class name: Distance
Data members:
double km, m
Member methods:
Distance (): to assign default values
void display (): to accept the value of km and m from the user.
Distance calculate (Distance A, distance B): this function will be adding the distance and
return the value.
void display (): to display the input distance and the resultant distance.
void main(): to create the object and call the functions respectively.
6. Write a program to input a two dimensional array of size m*n where 3<=m<=10 ,
3<=n<=10. Perform the following tasks:
I. Display the elements in matrix form
II. Display the sum of diagonal elements
III. Display the prime and composite numbers and their sum appropriately.
7. Write a program to take an array of size m*n. Find the greatest number in each row and
display the numbers and their sum.
8. A class adder has been defined to add any two times . The details of the class is as
follow:
Class name: adder
Data members:
a[]: integer array to hold two elements- hours and minutes.
Member methods:
adder(): to assign 0 to the array element
void readtime(): to enter the array elements as hours and minutes
void displaytime(): to display the array elements as hours and minutes with an appropriate
message
void addtime(adder x, adder y): to add the time of two parameterized objects x and y and
store the sum in the current object
Specify the class with all details and use the main method to create the object and call the
functions accordingly.
9. Class target has been defined to merge two arrays one contains prime numbers and other
contains composite numbers only. The description of the class is given below:
Class name: Target
Data members:
Int prm[]: to store the prime number
Int com[]: to store the composite number
Int n: to store the size of each array
Member function:
Target (int n): perimeter is constructed to assign n=nn
boolean prime( int x): return true if prime otherwise false
void accept1(): accept the prime numbers only in array by method invoking the method
void accept2(): accept the composite numbers only in the array com by invoking the method
void mix ( target A, target B): merge and display all prime members followed by composite
numbers according to the parameterized object
Specify the class target with all the details of data members and member methods write a
method to create the object and call the functions accordingly
10. Class name: time
Data members:
hr: to store hours
min: to store minutes
Member methods:
Time(): used to assign default values
Time(int hr1,int min1): to assign data members
Time calculate (Time A,Time B): to calculate the sum of two times
void display(): to display 3 different times
void main(): to create the object and call respectively
11. Money is a unit that has two parts rupees and paise where 100 paise=1 rupee. Design a
class named money whose details areas follow:
Class name: Money
Data members:
Int rs: to store the value rupees
Int ps: to store the value of paise
Money(int rs1,int ps1): parameterized constructor to initialize the detail members
void inshow(): to show the member data as (Rs 819.75)
Money fnadd(Money m1, Money m2): add m1 and m2 and store the result in the
corresponding member data and return it
Specify the class giving the details of the above remember data and member method. Also
the main method to create the object and call the other methods accordingly to enable the
task of adding two units of money.