Question: #ifndef MATRIX _ T _ #define MATRIX _ T _ #include using std::cerr; #include / / for asset macro template Matrix::Matrix ( RowType loRow, RowType

#ifndef MATRIX
_
T
_
#define MATRIX
_
T
_
#include
using std::cerr;
#include
/
/
for asset macro
template
Matrix::Matrix
(
RowType loRow, RowType hiRow,ColType loCol, ColType hiCol
)
{
arrayData
=
new Array
_
V
*
>
(
loRow
,
hiRow
)
;
for
(
RowType i
=
loRow; i
<
=
hiRow; i
+
+
)
(
*
arrayData
)
[
i
]
=
new Array
_
V
(
loCol
,
hiCol
)
;
assert
(
arrayData
!
=
0
)
;
loRowIndex
=
loRow;
hiRowIndex
=
hiRow;
loColIndex
=
loCol;
hiColIndex
=
hiCol;
}
template
Matrix::Matrix
(
const Matrix & initMatrix
)
{
loRowIndex
=
initMatrix.loRowIndex;
hiRowIndex
=
initMatrix.hiRowIndex;
loColIndex
=
initMatrix.loColIndex;
hiColIndex
=
initMatrix.hiColIndex;
arrayData
=
new Array
_
V
*
>
(
initMatrix
.
loRowIndex, initMatrix.hiRowIndex
)
;
assert
(
arrayData
!
=
0
)
;
for
(
RowType i
=
loRowIndex; i
<
=
hiRowIndex; i
+
+
)
{
(
*
arrayData
)
[
i
]
=
new Array
_
V
(
loColIndex
,
hiColIndex
)
;
(
*
arrayData
)
[
i
]
=
(
*
initMatrix
.
arrayData
)
[
i
]
;
}
}
template
void Matrix::operator
=
(
const Matrix & initMatrix
)
{
for
(
RowType i
=
loRowIndex; i
<
=
hiRowIndex; i
+
+
)
{
delete
(
*
arrayData
)
[
i
]
;
}
delete
(
arrayData
)
;
loRowIndex
=
initMatrix.loRowIndex;
hiRowIndex
=
initMatrix.hiRowIndex;
loColIndex
=
initMatrix.loColIndex;
hiColIndex
=
initMatrix.hiColIndex;
arrayData
=
new Array
_
V
*
>
(
initMatrix
.
loRowIndex, initMatrix.hiRowIndex
)
;
assert
(
arrayData
!
=
0
)
;
for
(
int i
=
loRowIndex; i
<
=
hiRowIndex; i
+
+
)
{
(
*
arrayData
)
[
i
]
=
new Array
_
V
(
loColIndex
,
hiColIndex
)
;
(
*
arrayData
)
[
i
]
=
(
*
initMatrix
.
arrayData
)
[
i
]
;
}
}
template
Matrix::~Matrix
(
)
{
}
template
bool Matrix::outOfRange
(
RowType row
)
{
if
(
(
row
<
loRowIndex
)
|
|
(
row
>
hiRowIndex
)
)
{
cerr
<
<
"Row Index"
<
<
row
<
<
"
out of range";
return
(
true
)
;
}
else
return
(
false
)
;
}
template
Array
_
V & Matrix::operator
[
]
(
RowType row
)
{
assert
(
!
outOfRange
(
row
)
)
;
return
(
*
(
*
arrayData
)
[
row
]
)
;
}
template
RowType Matrix::getLoRowIndex
(
)
{
return loRowIndex;
}
template
RowType Matrix::getHiRowIndex
(
)
{
return hiRowIndex;
}
template
ColType Matrix::getLoColIndex
(
)
{
return loColIndex;
}
template
ColType Matrix::getHiColIndex
(
)
{
return hiColIndex;
}
template
void Matrix::setLoRowIndex
(
RowType rowLo
)
{
loRowIndex
=
rowLo;
}
template
void Matrix::setHiRowIndex
(
RowType rowHi
)
{
hiRowIndex
=
rowHi;
}
template
void Matrix::setLoColIndex
(
ColType colLo
)
{
loColIndex
=
colLo;
}
template
void Matrix::setHiColIndex
(
ColType colHi
)
{
hiColIndex
=
colHi;
}
#endif
string getFileName
(
)
{
string fName;
\
\
ADD SOME CODE TO GET FILE NAME OF MATRIX DATA FROM
.
TXT FILE
return fName;
}
void openFile
(
string nameOf, ifstream& in
)
{
in
.
open
(
nameOf
.
c
_
str
(
)
,
ios::in
)
;
/
/
convert nameOf to c
-
string; try to open
if
(
!
in
)
/
/
file and test for unsuccessful opening
{
cerr
<
<
"
ERROR:
"
<
<
nameOf
<
<
endl
<
<
endl;
exit
(
0
)
;
}
//ADD CODE FOR OPEN FILE FROM .TXT FILE
}
Write C++code to read and display 2D matrix from .txt file using this matrix class function and also provide main .cpp drive.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!