-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_matrix.cpp
More file actions
49 lines (42 loc) · 1.24 KB
/
test_matrix.cpp
File metadata and controls
49 lines (42 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include "matrix.h"
using namespace std;
int main()
{
try
{
std::cout << std::endl;
CMatrix A1(2,5,1.0); //Create matrix A1 = [ 1.0 0.0 0.0 0.0 0.0
// 0.0 1.0 0.0 0.0 0.0 ]
std::cout << A1 << std::endl;
CMatrix A2(5,3,0.0,6.3); //Create matrix A1 = [ 0.0 6.3 6.3
// 6.3 0.0 6.3
// 6.3 6.3 0.0
// 6.3 6.3 6.3
// 6.3 6.3 6.3 ]
std::cout << A2 << std::endl;
CMatrix S = A1 * A2; //Multiply A1 by A2
cout << S << endl;
fstream f1;
f1.open("matrix.dat", fstream::in);
CMatrix B(f1); //Read the matrix data from file matrix.dat
f1.close(); //First two values in this file specify the matrix dimensions
cout << B << endl;
S = B; //Assign B to S
S[0][0] = 1.4; //Modify S
cout << "S[0][0]=" << S[0][0] << endl; //Verify S
cout << "B[0][0]=" << B[0][0] << endl; //Verify B
}
catch(IndexOutOfRange&)
{
std::cout << "Index Out of Range" << std::endl;
}
catch(WrongDim&)
{
std::cout << "Wrong Matrix Dimensions" << std::endl;
}
catch(std::bad_alloc)
{
std::cout << "Out of Memory" << std::endl;
}
}