Please answer each CLEARLY and LEGIBLE Write a C++ program to declare a class ca
ID: 3735408 • Letter: P
Question
Please answer each CLEARLY and LEGIBLE Write a C++ program to declare a class called Matrix. The private data of the class are row, column, and matrix. The member functions are as follows: 1) member function constructor Matrix to initialize the content of the matrix to zero; 2) a function friend Read_Matrix; 3) member function Transpose_MatrixO; and 4) Display_MatrixO. In the main function, do as follows: 1. Declare object Matrix_A; Declare object Matrix_B; Call friend Transpose_Matrix to find transpose of Matrix_A and store the result in Matix B .Call Matrix_A.Display_MatrixO Call Matrix_B.Display_MatrixO 2. Modify the class bank program to add a static variable counter type of integer as a private data. 3. Modify Program 18h by changing the class name to Shape instead of Rectangle. Add a member 4. Modify Program 18c and write the definition of the overloaded operator+O function inline. Modify the constructor function BankO to increment the counter when an object is created. Test your program for ten objects. Modify the display function to display the counter variable Height type of double as private data. Initialize Height to Zero in the ShapeO constructor. In the main program declare object Cube type of Shape. Compute volume and display it.Explanation / Answer
First part code:
#include<iostream>
using namespace std;
class MATRIX
{
public: int a[50][50];
int row,col;
public: MATRIX(int x,int y)
{
row=x;
col=y;
//initialize matrix content to 0
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
a[i][j]=0;
}
}
}
void Read_Matrix();
void Display_Matrix();
MATRIX Transpose_Matrix(int a[][50], int m , int n);
};
void MATRIX::Read_Matrix()
{
cout<<"Enter elements of matrix: ";
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++) cin>>a[i][j];
}
}
void MATRIX::Display_Matrix()
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
cout<<a[i][j]<<" ";
cout<<" ";
}
}
MATRIX MATRIX::Transpose_Matrix(int a[][50],int m, int n)
{
MATRIX b(n,m);
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{b.a[j][i]=a[i][j];
//cout<<a[i][j];
}
}
return b;
}
int main()
{
int m,n;
cout<<"Enter order of A matrix:";
cin>>m>>n;
MATRIX Matrix_A(m,n), Matrix_B(m,n);
Matrix_A.Read_Matrix();
Matrix_B=Matrix_A.Transpose_Matrix(Matrix_A.a,m,n);
cout<<"Matrix A is… ";
Matrix_A.Display_Matrix();
cout<<"Matrix B is… ";
Matrix_B.Display_Matrix();
return 0;
}
//// code ends
2. As you have not specified details of Bank class; explaining only the changes:
class bank{
//add
static int counter;
public : bank()
{
counter ++;
}
In display method, add---
cout<< counter;
}
3. As asked, change the class name to Shape
class Shape{
double Height;
public: Shape()
{
Height = 0;
}
void volume()
{
cout<<( this.Length * this.Breadth * this.Height);
}
}
In main method:: do.....
Shape Cube();
Cube.volume();
}