-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (53 loc) · 2.1 KB
/
Copy pathmain.cpp
File metadata and controls
57 lines (53 loc) · 2.1 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
50
51
52
53
54
55
56
57
//
// Created by rhythm on 24/06/20.
//
#include <iostream>
#include <Matrix.h>
#include <Vector.h>
#include <memory>
void testMatrix() {
std::vector<std::vector<int>> data1, data2;
for (int i = 0; i < 3; i++) {
std::vector<int> temp1, temp2;
for (int j = 0; j < 3; j++) {
temp1.emplace_back(i+j);
temp2.emplace_back(i*j);
}
data1.emplace_back(temp1);
data2.emplace_back(temp2);
}
int data3[] = {1, 2, 3};
std::cout << "Test Matrix\n========================================================" << std::endl;
std::shared_ptr<Matrix<int>> m1 = std::make_shared<Matrix<int>>(data1);
std::cout << "Matrix1: " << std::endl << *m1 << std::endl;
std::shared_ptr<Matrix<int>> m2 = std::make_shared<Matrix<int>>(data2);
std::cout << "Matrix2: " << std::endl << *m2 << std::endl;
std::cout << "Sum: " << std::endl << *m1 + *m2 << std::endl;
std::cout << "Scalar Product: " << std::endl << *m1 * 6 << std::endl;
std::cout << "Matrix Product: " << std::endl << *m1 * *m2 << std::endl;
std::shared_ptr<Vector<int>> v1 = std::make_shared<Vector<int>>(3, data3);
std::cout << "Vector Product: " << std::endl << *m1 * *v1 << std::endl;
m1->at(0, 0) = 8;
m1->at(1, 1) = 18;
m1->at(2, 2) = 28;
std::cout << "Update Matrix1: " << std::endl << *m1;
}
void testVector() {
int data1[] = {1, 2, 3};
int data2[] = {8, 9, 15};
std::cout << "Test Vector\n========================================================" << std::endl;
std::shared_ptr<Vector<int>> v1 = std::make_shared<Vector<int>>(3, data1);
std::cout << "Vector1: " << *v1 << std::endl;
std::shared_ptr<Vector<int>> v2 = std::make_shared<Vector<int>>(3, data2);
std::cout << "Vector2: " << *v2 << std::endl;
std::cout << "Sum: " << *v1 + *v2 << std::endl;
std::cout << "Scalar Product: " << *v1 * 6 << std::endl;
if (v1->getSize() < 4)
std::cout << "Cross Product: " << v1->cross(*v2) << std::endl;
std::cout << "Dot Product: " << v1->dot(*v2) << std::endl;
}
int main() {
testMatrix();
testVector();
return 0;
}