Cs201 Assignment no 2 Solution file Fall 2022
#include<iostream>
using namespace std;
#define ROW 2
#define COL 2
class MatrixProperty{
private:
int matrix[ROW][COL];
public:
MatrixProperty();
MatrixProperty(int array[][COL]);
void setMatrix(int array[][COL]);
const MatrixProperty operator + (const MatrixProperty& _matrix)const;
void display(MatrixProperty& _matrix);
const friend MatrixProperty Transpose(MatrixProperty& _matrix){
MatrixProperty result;
for(int i=0; i<ROW;i++){
for(int j=0; j<COL;j++){
result.matrix[j][i] = _matrix.matrix[i][j];
}
}
return result;
}
};
MatrixProperty::MatrixProperty(){
for(int i=0; i<ROW;i++){
for(int j=0; j<COL;j++){
this->matrix[i][j] = 0;
}
}
}
MatrixProperty::MatrixProperty(int array[][COL]){
for(int i=0; i<ROW;i++){
for(int j=0; j<COL;j++){
this->matrix[i][j] = array[i][j];
}
}
}
Click Below to Get CCNA Course In Urdu:
CCNA Course in Urdu Lab 1 Part 1 Cisco Internetworking Operating System (IOS) ClickHere
CCNA Course in Urdu Lab 1 Part 2 Cisco Internetworking Operating System (IOS) ClickHere
CCNA Course in Urdu Lab 1 Part 3 Cisco Internetworking Operating System (IOS) ClickHere
Cs201 Assignment no 2 Solution file Fall 2022
const MatrixProperty MatrixProperty:: operator + (const MatrixProperty& _matrix)const{
MatrixProperty sumOfMatrix;
for(int i=0; i<ROW;i++){
for(int j=0; j<COL;j++){
sumOfMatrix.matrix[i][j] = this->matrix[i][j] + _matrix.matrix[i][j];
}
}
return sumOfMatrix;
}
void MatrixProperty::display(MatrixProperty& _matrix){
for(int i=0; i<ROW;i++){
for(int j=0; j<COL;j++){
cout<<_matrix.matrix[i][j]<<" ";
}
cout<<endl;
}
}
int main(){
int a[ROW][COL] = {{1,2},{3,4}};
int b[ROW][COL] = {{5,7},{6,2}};
MatrixProperty instance_A(a),instance_B(b),sum_of_matrix;
cout<<"Matrix A"<<endl;
instance_A.display(instance_A);
cout<<"Matrix B"<<endl;
instance_B.display(instance_B);
sum_of_matrix = instance_A + instance_B;
cout<<"Sum of Matrix A and B"<<endl;
sum_of_matrix.display(sum_of_matrix);
cout<<"Transpose of Matrix (A+B)"<<endl;
sum_of_matrix = Transpose(sum_of_matrix);
sum_of_matrix.display(sum_of_matrix);
return 0;
}