0% found this document useful (0 votes)
25 views2 pages

CSCI 1300 ASSIGNMENT 2 - SECTION 4 Sem 2 1920

The document provides instructions for an assignment to write a C++ program that multiplies two matrices and calculates the determinant of the resulting matrix. It defines two sample matrices P and Q and shows how they are multiplied. It outlines the required functions and functionality: 1) Get user input to populate matrices P and Q, 2) Multiply matrices P and Q using pointers and display result, 3) Calculate determinant of result matrix PQ using pointers and display value.

Uploaded by

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

CSCI 1300 ASSIGNMENT 2 - SECTION 4 Sem 2 1920

The document provides instructions for an assignment to write a C++ program that multiplies two matrices and calculates the determinant of the resulting matrix. It defines two sample matrices P and Q and shows how they are multiplied. It outlines the required functions and functionality: 1) Get user input to populate matrices P and Q, 2) Multiply matrices P and Q using pointers and display result, 3) Calculate determinant of result matrix PQ using pointers and display value.

Uploaded by

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

Department of Computer Science, KICT 02 JULY 2020

ELEMENTS OF PROGRAMMING (CSC 1100), Sem 2 19/20


ASSIGNMENT 2: INDIVIDUAL/PAIR PROGRAMMING (Section 4)
DUE DATE: FRI, 17 JULY 2020 (11.59 PM)

QUESTION 2 (MATRIX MANIPULATION)


A matrix is an array of numbers of size m by n (i.e., m x n). When we multiply 2 matrices, we multiply
the matching numbers, then sum them up. Multiplying a matrix of size m x n with another matrix of size
n x q will result in a matrix of size m x q. An example is shown in Figure 2:

𝑝 𝑞 𝑝𝑎 + 𝑞𝑑 𝑝𝑏 + 𝑞𝑒 𝑝𝑐 + 𝑞𝑓
𝑠 ] x [𝑎 𝑏 𝑐
[𝑟 ] = [ 𝑟𝑎 + 𝑠𝑑 𝑟𝑏 + 𝑠𝑒 𝑟𝑐 + 𝑠𝑓 ]
𝑡 𝑢 𝑑 𝑒 𝑓
𝑡𝑎 + 𝑢𝑑 𝑡𝑏 + 𝑢𝑒 𝑡𝑐 + 𝑢𝑓
Matrix 3 x 2 Matrix 2 x 3 Matrix 3 x 3

Figure 1: Multiplication of Matrix 3 x 2 and 2 x 3

The determinant of a matrix represented by two vertical lines on either side |A| is a special number
that can be calculated from a square matrix. Figure 2 shows an example of how a determinant for matrix
A is calculated :

Matrix A = [ 𝑎 𝑏 ]
𝑐 𝑑
| A | = ad - bc
𝑎 𝑏 𝑐
Matrix B = [ 𝑑 𝑒 𝑓 ]
𝑔 ℎ 𝑖

| B | = a (ei - hf) – b (di - gf) + c(dh - ge)


Figure 2: Determinant of Matrix 2 x 2 and 3 x 3

Write a C++ program that multiplies 2 matrices and return the determinant of the multiplied matrix.
Your program shall include the following:

a) Define two 2 dimensional arrays, P and Q that each represents a matrix of size 3 x 2 and a matrix
of size 2 x 3. Request the user to enter the values for the 2 arrays using advanced pointer
notations (refer to your slides for the list of array pointer notations).

b) Create a function named multMatrix() that passes as arguments, the values of array P and Q,
multiplies them and store the results in a new matrix PQ. Use pointer notations to multiply your
arrays. Display your multiplied arrays.

c) Create a function named findDeterm() that passes as argument, the values of array PQ and return
its determinant from the function. Use advanced pointer notations to perform your calculation.
Display your result in main().

The basic program and function stubs are given below as a guideline.
1
Department of Computer Science, KICT 02 JULY 2020

#include <iostream>
using namespace std;

//declare rows and columns sizes


//declare all empty arrays here as global

void multMatrix(); //complete your prototype


int findDeterm();//complete your prototype

int main()
{

//get user input for array values using nested loop


//call multMatrix() : pass arrays to multiply
//call findDeterm(): pass multiplied 2d array
//display result of findDeterm
}

void multMatrix()//pass 2 arrays


{
//create if-else condition in nested loop to determine index position
//multiply arrays
//display array
}

int findDeterm()//pass 2d array {


//more codes here
return determinant;
}

Sample Output :

Enter values for array P:


-9 14
1 -5
3 7

Enter values for array Q:


1 2 3
4 5 6

Matrix P x Q is :
| 33 38 57 |
| -14 -18 -27 |
| 24 34 51 |

|PQ| or the determinant of PQ is : 2464

1 -2 8

You might also like