Matrix PYQ questions
Matrix PYQ questions
2025:
Design a class Colsum to check if the sum of elements in each corresponding column of two
matrices is equal or not. Assume that the two matrices have the same dimensions.
Class name: Colsum
Data members/instance variables:
mat[][] : to store the integer array elements
m : to store the number of rows
n : to store the number of columns
Member functions/methods:
Colsum(int mm, int nn) : parameterised constructor to initialise the data members mmm and
n = nn
void readArray() : to accept the elements into the array
boolean check(Colsum A, Colsum B) : to check if the sum of elements in each column of the
objects A and B is equal and return true otherwise, return false
void print() : to display the array elements
Specify the class Colsum giving details of the constructor(int, int), void readArray(), boolean
check(Colsum, Colsum), and void print(). Define the main() function to create objects and
call the functions accordingly to enable the task.
2024:
Class InSort contains an array of integers which sorts the elements in a particular order. Some
of the members of the class are given below.
Class name: InSort
Data members/instance variables:
arr[]: stores the array elements
size: stores the number of elements in the array
Methods/Member functions:
InSort(int s): constructor to initialise size = s
void getArray(): accepts the array elements
void insertionSort(): sorts the elements of the array in descending order using the Insertion
Sort technique
double find(): calculates and returns the average of all the odd numbers in the array
void display(): displays the elements of the array in a sorted order along with the average of
all the odd numbers in the array by invoking the function find() with an appropriate message
Specify the class InsSort giving details of the constructor(), void getArray(), Void
insertionSort(), double find() and void display(). Define a main() function to create an object
and call all the functions accordingly to enable the task.
2023:
A class Trans is defined to find the transpose of a square matrix. A transpose of a matrix is
obtained by interchanging the elements of the rows and columns.
Some of the members of the class are given below:
Class name: Trans
Data members/instance variable:
arr[][]: to store integers in the matrix
m: integer to store the size of the matrix
Methods/Member functions:
Trans(int mm): parameterised constructor to initialise the data member m = mm
void fillarray(): to enter integer elements in the matrix
void transpose(): to create the transpose of the given matrix
void display(): displays the original matrix and the transport matrix by invoking the method
transpose()
Specify the class Trans giving details of the constructor(), void fillarray(), void transpose()
and void display() Define a main() function to create an object and call the functions
accordingly to enable the task.
2020:
Design a class BinSearch to search for a particular value in an array. Some of the members of
the class are given below:
Class name: BinSearch
Data members/instance variables:
arr[]: to store integer elements
n:integer to store the size of the array
Member functions/methods:
BinSearch(int nn): parameterised constructor to initialize n=nn
void fillarray(): to enter elements in the array
void sort(): sorts the array elements in ascending order using any stan-dard sorting technique
int bin_search(int I,int u,int v): searches for the value 'v' using binary search and recur-sive
technique and returns its location if found otherwise returns 1
Define the class BinSearch giving details of the constructor(), void fillarray(), void sort() and
int bin_search(int, int, int). Define the main() function to create an object and call the
functions accordingly to enable the task.
2019:
Design a class MatRev to reverse each element of a matrix.
Class name: MatRev
Data members/instance variables:
Arr[][]: to store integer elements
m: to store the number of rows
n: to store the number of columns
Member functions/Methods:
MatRev(int mm,int nn): Parametrised constructor to initialise the data members
MatRev(int mm,int nn): Parametrised constructor to initialise the data members m=mm and
n=nn
Void fillarray(): to enter elements in the array
Int reverse(int x): returns the reverse of the number x
Void revMat(MatRev P): reverses each element of the array of the parametrised object and
stores it in the array of the current object
Void show(): displays the array elements in matrix form
Define the class MatRev giving details of the constructor(), void fillarray(), int reverse(int),
void revMat(MatRey) and void show(). Define the main() function to create objects and call
the functions accordingly to enable the task.
2018:
Two matrices are said to be equal if they have the same dimensions and their corresponding
elements are equal. Design a class EqMat to check if two matrices are equal or not. Assume
that the two matrices have the same dimensions.
Class name: EqMat
Data members/instance variables:
A[][]: to store integer elements
M: to store number of rows
N: to store number of columns
Member functions/methods:
EqMat(int mm,int nn): parametrised constructor to initialise the data members m=mm and
n=nn
Void readarray(): to enter elements in the array
Int check(EqMat P, EqMat Q): checks if theparametrised objects P and Q are equal and
returns 1 if true, otherwise returns 0
Void print(): displays the array elements
Define the class EqMat giving details of the constructor(), void readarray(), int check(EqMat
P, EqMat Q) and void print(). Define the main() function to create objects and call the
functions accordingly to enable the task.
2017:
A class Shift contains a two dimensional integer array of order(m*n) where the maximum
values of both m and n is 5. Design the class Shift to shuffle the matrix(i.e., the first row
becomes the last, the second row becomes the first and so on).
Class name: Shift
Data members/instance variables:
Mat[][]: stores the array elements
M: integer to store the number of rows
n: to store the number of columns
Member functions/methods:
Shift(int mm, int nn): parametrised constructor to initialise m=mm and n=nn
Void input(): enters the elements of the array
Void cyclic(Shift P): enables the matrix of the object P to shift each row upwards in a cyclic
manner and store the resultant matrix in the current object
Void display(): displays the matrix elements
Specify the class Shift giving details of the constructor(), void input(), void cyclic(shift), and
void dislay(). Define the main() function to create an object and call the methods accordingly
to enable the task oof shifting the array elements
2015:
A class Admission contains the admission numbers of 100 students.
Class name: Admission
Data members/instance variables:
Adno[]: integer array to store admission numbers
Member functions/methods:
Admission(): constructor to initialize the array elements
Void fillArray(): to accept the elements of the array in ascending order
Int binSearch(int I,int u,int v): to search for a particular admission number(v) using binary
search and recursice technique and returns 1 if found otherwise returns -1
Specify the class Admission giving details of the constructor, void fillArray(), and int
binSearch(int,int,int). Define the main() function to create an object and call the functions
accordingly to enable the task.
2014:
A class Mixer has been defined to merge two sorted integer arrays in ascending order.
Class name: Mixer
Data members/instance variables:
Int arr[]: to store the elements of an array
Int n: to store the size of the array
Member functions/methods:
Mixer(int nn): constructor to assign n=nn
Void accept(): to accept the elements of the array in ascending order without any duplicates
Min(Mixer A): to merge the current object array elements with the parametrized array
elements and return the resultant object
Void display(): to display the elements of the array
Specify the class Mixer giving details of the constructor(int), void accept(), Mixer
mix(Mixer), and void display(). Define the main() function to create an object and call the
function accordingly to enable the task