You are on page 1of 3

Sri Sivasubramaniya Nadar College of Engineering

III SEM BME


Academic Year: 2021-22
Implementing matrices with necessary constructors, destructor, and operator overloading
Date: 08-12-2021
Expt. No.: 19
Aim:
To write a C++ program to implement the complex number class using necessary operator overloading.
Algorithm:
1. Start program
2. Declare and define a class ‘matrix’ with 2 int type variables [‘m’, ‘n’] and 1 in type array [‘matarray’]
…of size [100][100]. This class contains one default constructor which gets the values for the number of
…rows and columns of the matrix from the user and stores them in ‘m’ and ‘n’ respectively and then …
prompts the user to enter the value for the ‘i’ th row and ‘j’th column element which is then stored in the …
[i][j] position of ‘matarray’. Another constructor viz. a copy constructor for this class takes a ‘matrix’ …
type reference and assigns the values of ‘m’, ‘n’ and the ‘matarray’ elements of the newly created …
object of ‘matrix’ class using this copy constructor as the values of ‘m’, ‘n’ and the ‘matarray’ elements
…in the ‘matrix’ object passed as argument to this copy constructor. Then it also contains a void return
…type function ‘display()’ which displays the elements of the ‘matrix’ object as in a matrix i.e., in the …
form of rows and columns. Then, the class also contains a unary overloaded operator ‘=’ which takes …
one ‘matrix’ object as an argument. This function then creates a ‘matrix’ type object ‘mat’ whose …
values of ‘m’, ‘n’ and the ‘matarray’ elements are assigned as the values of ‘m’, ‘n’ and the ‘matarray’
…elements of the ‘matrix’ object passed as argument
3. Then, create a matrix type pointer ‘m1’ using the ‘new’ operator and then enter the required values. …
Then display the ‘matarray’ elements of ‘m1’ using the ‘->’ operator. Then, using the overloaded ‘=’ …
operator, assign a new ‘matrix’ object ‘m2’ to have the value of the pointer ‘m1’ and then display the
…‘matarray’ elements of ‘m2’. Then, using the copy constructor, instantiate another ‘matrix’ object ‘m3’
…by passing ‘m1’ as the argument and then display the elements in ‘m3’
4. End program

Name of the Student: Abishek P.S.


Register Number: 203003003
Sri Sivasubramaniya Nadar College of Engineering
III SEM BME
Academic Year: 2021-22
Program:

Name of the Student: Abishek P.S.


Register Number: 203003003
Sri Sivasubramaniya Nadar College of Engineering
III SEM BME
Academic Year: 2021-22
Sample Input and Output:

Result:
The C++ program is successfully executed after compilation.

Name of the Student: Abishek P.S.


Register Number: 203003003

You might also like