0% found this document useful (0 votes)
37 views4 pages

5.3 - Assignment 2 - Matrix

This document describes an assignment to write a C++ program that performs various matrix operations by implementing several functions: InputMatrix() to read matrices from a file, OutputMatrix() to display matrices, AddMatrix() to add matrices, TransposeMatrix() to calculate the transpose, IsSymmetric() to check for symmetry, and InterchangeRows() to swap rows. The program should follow the sample run shown, taking input only from the provided InputFile.txt and not prompting the user.

Uploaded by

anas bilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views4 pages

5.3 - Assignment 2 - Matrix

This document describes an assignment to write a C++ program that performs various matrix operations by implementing several functions: InputMatrix() to read matrices from a file, OutputMatrix() to display matrices, AddMatrix() to add matrices, TransposeMatrix() to calculate the transpose, IsSymmetric() to check for symmetry, and InterchangeRows() to swap rows. The program should follow the sample run shown, taking input only from the provided InputFile.txt and not prompting the user.

Uploaded by

anas bilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Object Oriented Programming (BCS-2C, BCS-2D & BCS-2E) – Spring 2023

Assignment 2
Write a program that takes two matrices from user and performs following operations:
- Matrix Addition
- Transpose of a matrix
- Checks if a matrix is symmetric or not
- Interchange rows of a matrix

You are supposed to implement following functions:


1. Int** InputMatrix( ifstream& fin, int& rows, int& cols)
Description: This function will take size of matrix from file, create a matrix dynamically,
take matrix elements from file and return the matrix created. Subscript operator and
Integer iterators are not allowed to traverse the matrix.
Note: Data of Input File is given in the end of this file.
2. Void OutputMatrix(int** matrix, cont int& ROWS, const int& COLS)
Description: Displays the matrix in proper format. Subscript operator and Integer
iterators are not allowed to traverse the matrix.
3. Int** AddMatrix(int** matrixA, int** matrixB, const int& ROWS, const int& COLS)
Description: This function takes two matrices as parameters, adds them and saves the
result in a newly created matrix R and returns the result. Subscript operator and Integer
iterators are not allowed to traverse the matrix.
4. int** TransposeMatrix(int** matrix, const int& ROWS, const int& COLS)
Decription: This function takes a matrix A, takes transpose of matrix A, saves the result
in a newly created matrix and returns the result. Subscript operator is not allowed.
Integer Iterators and offset notation ARE ALLOWED.
5. Bool IsSymmetric(int** matrix, const int& ROWS, const int& COLS)
Description: This function takes a matrix as parameter with its size information and
returns true if the matrix is symmetric and false otherwise. Call Transpose Matrix and
compare both matricec, if matrix is equal to its transpose, it is symmetric. Subscript
operator is not allowed. Integer Iterators and offset notation IS ALLOWED.
6. Void InterchangeRows(int** matrix, const int& ROWS, const int& COLS )
Description: This function takes two row numbers and calls following function to
actually interchange the rows.
7. Void InterchangeRows( int*& row1, int*& row2 )//Swap
Description: This function interchanges two rows. You are NOT ALLOWED to iterate
through rows and swap their values. Think of simple solution.

Important Notes:
- You cannot change the prototypes of the functions.
- You can use subscript operator to allocate and deallocate the memory.
- Your program should follow the exact sequence of Sample Run given below.
- Goto instruction is not allowed in your program.
- Submit only one running cpp file having all the functionality. DO NOT submit
compressed files. Submit your data file as well to avoid any file related issues during
evaluation.
- DO NOT take any input from user, we are taking input from file only.
- Violation of any of the above instructions may result in ZERO credit or marks deduction.

Sample Run (with sample inputs):


Matrix A =
1 2 3
4 5 6
7 8 9

Matrix B =
2 5 8
5 6 9
8 9 10

Matrix C =
2 3 4
5 6 7

A+B=
3 7 11
9 11 15
15 17 19

A+C =
Addition not possible.

Transpose of A =
1 4 7
2 5 8
3 6 9

Transpose of C =
2 5
3 6
4 7
Matrix A is NOT Symmetric

Matrix B is Symmetric

Interchanging Rows of Matrix A:


row1: 1 //Hard code this number
row2: 3 //Hard code this number

After Interchanging Rows Matrix A=


7 8 9
4 5 6
1 2 3

Note: These are only sample inputs. Your assignment may be evaluated on any value supported
by data type.

InputFile.txt (Create a file InputFile.txt and paste following data in the file. Name of the file in
your code should be “InputFile.txt”, it will be evaluated accordingly.) Submit your data file in
assignment submission with your only one running cpp file.
//Format of data is given below
//Line1: Rows Cols
//Line2: <matrix[0][0]> <matrix[0][1]> <matrix[0][2]>...
//Line3: <matrix[1][0]> <matrix[1][1]> <matrix[1][2]>...
//Line4: Next Row and so on

//Matrix A
33
123
456
789

//Matrix B
33
258
569
8 9 10

//Matrix C
23
234
567

Input.txt
33
123
456
789
33
258
569
8 9 10
23
234
567

You might also like