You are on page 1of 3

Assignment No.

2 Total Marks: 20
Semester: Fall 2023 Due Date: Jan
CS201P – Introduction to Programming (Practical) 11, 2024

Instructions
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit if:

o Assignment is submitted after due date.


o Submitted assignment does not open or file is corrupt.
o Assignment is copied (From internet/students).

Software allowed to develop Assignment

- Dev C++

Objectives:
To enable students to understand and practice the concepts of:
 Arrays
 Pointers and its arithmetic.
 Function and passing arrays or pointers as arguments to a function.

Assignment Submission Instructions

You are required to submit only .cpp file on the assignments interface of CS201P at VU-LMS.
Assignment submitted in any other format will not be accepted and will be graded
zero marks. So, check your solution file format before submission.
For any query related to assignment, please contact cs201p@vu.edu.pk.

Copyright © Virtual University of Pakistan


Problem Statement:
Use two matrices A and B of 2-by-2 order. Multiply matrix B with 2. Add Matrix A and 2*B.
Display the matrices A, 2*B, and A+2*B.

For all matrices A=[ aij ] of order m x n. where i =1…m and j =1…n

kA=[ kaij ] where k is a scalar.


Means…the scalar k will be multiplied to each and every element of matrix A.

You have to write a program in C++ which will perform the tasks mentioned in the problem statement.
For this purpose take:

 Two multi-dimensional arrays named A and B of integer datatype of dimension 2 x 2.

 A function MatrixInitializer () which should initialize the passed matrix (array) to 0.

 A function AddMatrix () which should take two matrices (arrays) and add them.

 A function MultMatrixByScalar () which should take an integer and a matrix (array) and multiply them.

 A function DisplayMatrix () which should display the passed matrix (array).

In the main () function, you should:

 Take two 2-dimensional arrays of order 2 x 2 and initialize them as follows:


 A must be {1,2,3,4}
 B must be {1,0,0,1}

 Compute 2*B…by calling function MultMatrixByScalar ().

 Add the TWO matrices A and the resultant matrix (2*B) using function AddMatrix.

 Call DisplayMatrix () function to display:

 matrices A and B.
 2*B matrix.
 the Final resultant matrix [A + 2*B].

Copyright © Virtual University of Pakistan


Note: You may use pointers to pass the array arguments to all functions and do pointer arithmetic.

Hint:
 Two matrices are added by adding their corresponding elements.
 A scalar K can be multiplied with a matrix as:

Kx [ ac bd ]=[ KK ac KK db]
For consistency of the assignment, please only use the above given matrices (arrays).

Note: Marks will be deducted if the given arrays are not used.

Sample Screenshot of Output:

Good Luck!

Lectures Covered: This assignment covers Lecture(of CS201) # 10-18.


Deadline: The deadline to submit your assignment solution is Jan 11, 2024. Your assignment must be
submitted within the due date through VU-LMS. No assignment will be accepted through email after the due date.

Copyright © Virtual University of Pakistan

You might also like