Skip to content

Commit 2722f47

Browse files
committed
last
1 parent 821d0f2 commit 2722f47

3 files changed

Lines changed: 90 additions & 1 deletion

File tree

.github/workflows/build-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Build C++ project # c++ 컴파일
3535
run: |
3636
mkdir -p assignment_4/output_cpp
37-
g++ -I /usr/include/eigen3 assignment_4/c++/*.cpp -o assignment_4/output_cpp/cpp_program
37+
g++ -I /usr/include/eigen3 assignment_4/c++/main.cpp -o assignment_4/output_cpp/cpp_program
3838
chmod +x assignment_4/output_cpp/cpp_program
3939
4040
- name: Build C# project

assignment_4/c++/main.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <iostream>
2+
#include <memory>
3+
#include <string>
4+
#include <Eigen/Dense>
5+
6+
#include "adapter.cpp"
7+
#include "decorator.cpp"
8+
#include "facade.cpp"
9+
#include "factory.cpp"
10+
#include "methodchain.cpp"
11+
12+
using namespace std;
13+
14+
int main() {
15+
cout << "Adapter\n";
16+
ExternalClass ext;
17+
Adapter adapter(&ext);
18+
cout << adapter.fetch() << endl;
19+
20+
cout << "\nDecorator\n";
21+
Coffee* coffee = new SugarDecorator(new MilkDecorator(new BasicCoffee()));
22+
cout << "총 커피 가격: " << coffee->cost() << endl;
23+
delete coffee;
24+
25+
cout << "\nFacade\n";
26+
Computer computer;
27+
computer.boot();
28+
29+
cout << "\nFactory Method\n";
30+
auto dog = AnimalFactory::createAnimal("dog");
31+
auto cat = AnimalFactory::createAnimal("cat");
32+
cout << "Dog: " << dog->speak() << endl;
33+
cout << "Cat: " << cat->speak() << endl;
34+
35+
cout << "\nMethod Chaining\n";
36+
Calculator calc;
37+
double result = calc.add(10).subtract(2).multiply(3).divide(4).getResult();
38+
cout << "계산 결과: " << result << endl;
39+
40+
cout << "\nEigen Matrix\n";
41+
Eigen::Matrix<float, 3, 2> A;
42+
A << 1, 2,
43+
3, 4,
44+
5, 6;
45+
46+
Eigen::Matrix<float, 2, 3> B;
47+
B << 7, 8, 9,
48+
10, 11, 12;
49+
50+
Eigen::Matrix<float, 3, 3> C = A * B;
51+
cout << "A * B =\n" << C << endl;
52+
53+
return 0;
54+
}

assignment_4/c++/methodchain.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
3+
class Calculator {
4+
private:
5+
double result;
6+
7+
public:
8+
Calculator() : result(0) {}
9+
10+
Calculator& add(double value) {
11+
result += value;
12+
return *this;
13+
}
14+
15+
Calculator& subtract(double value) {
16+
result -= value;
17+
return *this;
18+
}
19+
20+
Calculator& multiply(double value) {
21+
result *= value;
22+
return *this;
23+
}
24+
25+
Calculator& divide(double value) {
26+
if (value != 0) {
27+
result /= value;
28+
}
29+
return *this;
30+
}
31+
32+
double getResult() const {
33+
return result;
34+
}
35+
};

0 commit comments

Comments
 (0)