Finish the class Matrix.h:
class Matrix
{
public:
Matrix(); //default constructor
~Matrix(); //destructor
Matrix(const Matrix &); //copy constror
Matrix(int row, int col);
Matrix operator+(const Matrix &)const; //overload operator“+”
Matrix& operator=(const Matrix &); //overload operator“=”
Matrix transpose()const; //matrix transposition
void display()const; //display the data
private:
int row; //row
int col; //column
int** mat; //to save the matrix
};
//main.cpp
#include <iostream>
#include"Matrix.h"
using namespace std;
int main() {
int row, col;
cout << "input the row and the col for Matrix a, b" <<
endl;
cin >> row >> col;
Matrix a(row, col), b(row, col), c(a), d;
cout << endl << "Matrix a:" << endl;
a.display();
cout << endl << "Matrix b:" << endl;
b.display();
c = a + b;
cout << endl << "Matrix c = Matrix a + Matrix b :"
<< endl;
c.display();
cout << endl << "Matrix a transpose to Matrix d:"
<< endl;
d = a.transpose();
d.display();
return 0;
}
Matrix.h
#include<iostream>
using namespace std;
class Matrix
{
private:
int row;
int col;
int **mat;
public:
Matrix();
~Matrix();
Matrix(const Matrix &);
Matrix(int row,int col);
Matrix operator + (const Matrix
&)const;
Matrix& operator = (const
Matrix &);
Matrix
Transpose() const;
void display()
const;
void input()
const;
};
//default constructor it assign 10 to row and column
Matrix :: Matrix()
{
row=10;
col=10;
int i;
//allocate memory for row
mat=new int*[10];
//alocate memory for columns
for(int i=0;i<10;i++)
{
mat[i]=new int[10];
}
}
//Destructor
Matrix :: ~Matrix()
{
delete mat;
}
//parameterized constructors
Matrix :: Matrix (const Matrix &m)
{
int i,j;
//assign row and column
this->row = m.row;
this->col = m.col;
//allocate memory for row
mat=new int*[row];
//alocate memory for columns
for( i=0;i<row;i++)
{
mat[i]=new int[col];
}
}
//parameterized constructor
Matrix :: Matrix(int r,int c)
{
row=r;
col=c;
//allocate memory for row
mat=new int*[row];
int i;
//alocate memory for columns
for(int i=0;i<row;i++)
{
mat[i]=new int[col];
}
}
//input method
void Matrix :: input()const
{
int i,j;
cout<<endl<<"Enter"<<row*col<<"
elements";
for(i=0;i<row;i++)
for(j=0;j<col;j++)
cin>>mat[i][j];
}
//display method
void Matrix :: display()const
{
int i,j;
cout<<endl<<"Matrix elements :
\n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
cout<<" "<<mat[i][j];
cout<<endl;
}
}
//operator overloading add two matrices
Matrix Matrix :: operator + (const Matrix &m)const
{
int i,j;
Matrix obj;
obj.row=m.row;
obj.col=m.col;
for(i=0;i<m.row;i++)
for(j=0;j<m.col;j++)
obj.mat[i][j] = mat[i][j] + m.mat[i][j];
return obj;
}
//assign a matrix to other
Matrix& Matrix :: operator = (const Matrix &m)
{
int i,j;
row=m.row;
col=m.col;
for(i=0;i<row;i++)
for(j=0;j<col;j++)
mat[i][j] = m.mat[i][j];
return *this;
}
//transpose a matrix
Matrix Matrix :: Transpose() const
{
int i,j;
Matrix obj;
obj.row=row;
obj.col=col;
for(i=0;i<row;i++)
for(j=0;j<col;j++)
obj.mat[i][j]=mat[j][i];
return obj;
}
main.cpp
#include<iostream>
#include "matrix.h"
using namespace std;
int main() {
int row, col;
cout << "input the row and the col for Matrix a, b" <<
endl;
cin >> row >> col;
Matrix a(row, col), b(row, col),c(a), d;
cout << endl << "Matrix a:" << endl;
a.input();
a.display();
cout << endl << "Matrix b:" << endl;
b.input();
b.display();
c = a+b;
cout << endl << "Matrix c = Matrix a + Matrix b :"
<< endl;
c.display();
cout << endl << "Matrix a transpose to Matrix d:"
<< endl;
d = a.Transpose();
d.display();
return 0;
}
OUTPUT

Finish the class Matrix.h: class Matrix { public: Matrix(); //default constructor ~Matrix(); //destructor Matrix(const Matrix &);...
Finish the class Matrix.h: class Matrix { public: Matrix(); //default constructor ~Matrix(); //destructor Matrix(const Matrix &); //copy constror Matrix(int row, int col); Matrix operator+(const Matrix &)const; //overload operator“+” Matrix& operator=(const Matrix &); //overload operator“=” Matrix transpose()const; //matrix transposition void display()const; //display the data private: int row; //row int col; //column int** mat; //to save the matrix }; //main.cpp #include <iostream> #include"Matrix.h" using namespace std; int main() { int row, col; cout << "input the row and the col for Matrix...
LW: Class Constructors Objectives Write a default constructor for a class. Note that this constructor is used to build the object anytime an argument is not provided when it is defined. Write a parameterized constructor that takes arguments that are used to initialize the class’s member variables Labwork Download the code associated with this lab: ColorConstructor.zip Main.cpp Color.h Color.cpp Compile and run the code. The first line of output of the program should display nonsensical integers for the values of...
need help..... sudoku.h class sudoku { public: sudoku(); //default constructor //Postcondition: grid is initialized to 0 sudoku(int g[][9]); //constructor //Postcondition: grid = g void initializeSudokuGrid(); //Function to prompt the user to specify the numbers of the //partially filled grid. //Postcondition: grid is initialized to the numbers // specified by the user. void initializeSudokuGrid(int g[][9]); //Function to initialize grid to g //Postcondition: grid = g; void printSudokuGrid(); //Function to print the sudoku grid. bool solveSudoku(); //Funtion to solve the sudoku problem....
NEED ASAP PLEASE HELP
Task:
---------------------------------------------------------------------------------------------------------------------------------
Tasks to complete:
----------------------------------------------------------------------------------------------------------------------------------------
given code:
-----------------------------------------------------------------------------------------------------------------------------------------------
main.cpp
#include <iostream>
#include <iomanip>
#include "fractionType.h"
using namespace std;
int main()
{
fractionType num1(5, 6);
fractionType num2;
fractionType num3;
cout << fixed;
cout << showpoint;
cout << setprecision(2);
cout << "Num1 = " << num1 << endl;
cout << "Num2 = " << num2 << endl;
cout << "Enter the fraction in the form a / b: ";
cin >> num2;
cout << endl;
cout <<...
C++ CODE: The matrix class consists of two files: matrix.h and matrix.cpp. The class has the following definition: matrix -size:int -mat:int** ---------------- +matrix(file:string) +~matrix() +operator +(add:matrix*):matrix & +operator-(sub:matrix*):matrix & +friend operator<<(out:ostream &, t:const matrix&):ostream & +displayRow(r:int):void The class variables are as follows: • size: the number of rows and columns in a square matrix • mat: the integer matrix that contains the numeric matrix itself. The methods have the following behaviour: 2 • matrix(file:string): The default constructor. It receives the...
Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator: prints "Move assignment" and endl in addition...
Task:
Tasks to complete:
------------------------------------------------------------------------------------------------------------------------------------------
given code:
------------------------------------------------------------------------------------------------------------------------------------------
main.cpp
#include
#include "rectangleType.h"
using namespace std;
// part e
int main()
{
rectangleType rectangle1(10, 5);
rectangleType rectangle2(8, 7);
rectangleType rectangle3;
rectangleType rectangle4;
cout << "rectangle1: " << rectangle1 <<
endl;
cout << "rectangle2: " << rectangle2 <<
endl;
rectangle3 = rectangle1 + rectangle2;
cout << "rectangle3: " << rectangle3 << endl;
rectangle4 = rectangle1 * rectangle2;
cout << "rectangle4: " << rectangle4 << endl;
if (rectangle1 > rectangle2)
cout << "Area...
class Simple_String { int length; char *c_ptr; public: Simple_String(const char *cstr_ = ""); // Default/custom constructor Simple_String(const Simple_String &original); // Copy constructor Simple_String & operator= (const Simple_String &rhs); // Assignment operator ~Simple_String(); // Destructor /* … */ }; What is the default constructor, copy constructor, assignment operator, and destructor?
Requirements: Finish all the functions which have been declared inside the hpp file. Details: string toString(void) const Return a visible list using '->' to show the linked relation which is a string like: 1->2->3->4->5->NULL void insert(int position, const int& data) Add an element at the given position: example0: 1->3->4->5->NULL instert(1, 2); 1->2->3->4->5->NULL example1: NULL insert(0, 1) 1->NULL void list::erase(int position) Erase the element at the given position 1->2->3->4->5->NULL erase(0) 2->3->4->5->NULL //main.cpp #include <iostream> #include <string> #include "SimpleList.hpp" using std::cin; using...
13.21 Lab: Rational class This question has been asked here before, but every answer I have tested did not work, and I don't understand why, so I'm not able to understand how to do it correctly. I need to build the Rational.cpp file that will work with the main.cpp and Rational.h files as they are written. Rational Numbers It may come as a bit of a surprise when the C++ floating-point types (float, double), fail to capture a particular value...