Please answer CLEARLY and LEGIBLE. Also include code for program. 1. Write a C++
ID: 3730083 • Letter: P
Question
Please answer CLEARLY and LEGIBLE. Also include code for program. 1. 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_MatrixO; 3) member function Transpose_MatrixO; and 4) Display_MatrixO. In the main function, do as follows: Declare object Matrix_A Declare object Matrix_B; . Call friend Transpose_MatrixO to find transpose of Matrix_A and store the result in Matix B Call Matrix-A·Display-Matrix() . 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
As per chegg policy we are supposed to answer first complete question. So request you to post other questions separately. Also you need to provide the code to be modified for other questions.
Given below is the code for the question 1.
Matrix.h
-------
#ifndef Matrix_h
#define Matrix_h
class Matrix
{
private:
static const int MAX_SIZE = 10;
int rows, columns;
int data[MAX_SIZE][MAX_SIZE];
public:
Matrix(int r, int c);
void Display_Matrix();
void Read_Matrix();
friend void Transpose_Matrix(Matrix &a, Matrix &b);
};
void Transpose_Matrix(Matrix &a, Matrix &b);
#endif /* Matrix_h */
Matrix.cpp
---------
#include "Matrix.h"
#include <iostream>
using namespace std;
Matrix::Matrix(int r, int c)
{
rows = r;
columns = c;
for(int i = 0; i < r; i ++)
for(int j = 0; j < c; j++)
data[i][j] = 0;
}
void Transpose_Matrix(Matrix &a, Matrix &b)
{
for(int i = 0; i < a.rows; i++)
for(int j = 0; j < a.columns; j++)
{
b.data[j][i] = a.data[i][j];
}
b.rows = a.columns;
b.columns = a.rows;
}
void Matrix::Display_Matrix()
{
for(int i = 0; i < rows; i++)
{
cout << endl;
for(int j = 0; j < columns; j++)
cout << " " << data[i][j];
}
cout << endl;
}
void Matrix::Read_Matrix()
{
cout << "Enter the values of " << rows << "x" << columns << " matrix" << endl;
for(int i = 0; i < rows; i++)
for(int j = 0; j < columns; j++)
cin >> data[i][j];
}
Main.cpp
--------
#include <iostream>
#include "Matrix.h"
using namespace std;
int main()
{
Matrix Matrix_A(3,3), Matrix_B(3,3);
Matrix_A.Read_Matrix();
Transpose_Matrix(Matrix_A, Matrix_B);
cout << "The original matrix A is " << endl;
Matrix_A.Display_Matrix();
cout << "The transposed matrix B is " << endl;
Matrix_B.Display_Matrix();
return 0;
}
-------
output
--------
Enter the values of 3x3 matrix
1 2 3
4 5 6
7 8 9
The original matrix A is
1 2 3
4 5 6
7 8 9
The transposed matrix B is
1 4 7
2 5 8
3 6 9
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.