A2 AssignmentMatrices

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

National University of Computer and Emerging Sciences, Lahore Campus

Course Name: Object Oriented Programming Course Code: CS 1004


Program: BS (Data Science) Semester: Spring 2023
Total Marks: 100 Weight 5%
Assigned: 29/ 03/ 2023 03/ 04/ 2023
Section: A, B 06/ 04/ 2023
Due 10/ 04/ 2023
Instructions:
You can either work independently OR in a group of at most two students of same gender to complete this
assignment.

Discussion with your class fellows is encouraged but plagiarism in all forms (copy someone’s code or sharing
your code with others) is strictly prohibited and will result in non-positive (negative) marks.

Vectors and Matrices


This assignment is about implementing a new classes to represent a 2D matrix. A 2D matrix is a
rectangular array of numbers arranged in M rows and N columns. Some examples matrices are shown
below and are commonly used to represent transformation of vectors, system of equations, graphs
images, computation graphs and many other interesting objects.
Example Matrices

3 x 4 Matrix 3 x 3 Matrix

For the matrices used in algebra, several binary operations (i.e. operations involving two matrices) are
defined on the set of all possible matrices with each binary operations combining two matrices to form
a new matrix. Some well-known binary operations defined on the set of all matrices are listed below.
List of Binary Operations Defined on Matrices
Plus, Minus, Multiply, Divide (Matrix (+\-\*\ /) Matrix, Matrix (+\-\*\ /) = Matrix ) where
division can be point by point division or some other definition of division

Assignment operation (Matrix = Matrix)

Add/subtract/multiply/divide a constant with a Matrix ( Matrix (+\-\*\ /) C, and C (+\-\*\ /) Matrix)


where C is a constant

Department of Computer Science Page 1


Several unary operations can also be applied on matrices where a unary operation generates a new
matrix from a given input matrix. Several unary operations defined on matrices are listed below
List of Unary Operations Defined on Matrices
Transpose of a matrix, Trace of a square matrix, power of a matrix (point by point power) and
Apply a function to each element of the matrix point by point (study about function pointers and see
if you can come up with a generic implementation)

For this assignment you must design a hierarchy of two classes named dynamic2DArray and Matrix
respectively.
The dynamic2DArray class will be used to create a 2D array of real numbers having M rows and N
columns with M and N being non-negative integers representing the size of the matrix. At minimum,
you must provide the following functionality for this class.
I/O from an I/O stream by overloading the stream operations and I/O from a file

Changing size of the array

Safe access of any element of the array by specifying index. Make sure that user is allowed to use
any index (positive or negative value) with -1 representing the last valid index -2 the second last …
The Matrix class will inherit the functionality of dynamic2DArray class and extend it by providing
all the binary and unary operations defined in the lists of binary and unary operations defined above.

You are also required to provide a program (main function) that will allow the user to demonstrate
each of the function created in the two classes. It might be a good idea to create a menu for the user
to test your functionality.
You will submit the assignment in three parts

Part i) dynamic2DArray class on or before Monday, April 3 2023 [1 Mark]


Part ii) dynamic2DArray + Matrix with operators overloaded on or before Friday, April 7 2023 [1 Mark]
Part iii) Complete Implementation on or before Friday, April 14 2023 [3 Marks]

Note: Don’t forget to provide deep copy constructor wherever necessary.

Department of Computer Science Page 2

You might also like