-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11-27_CPP_Test.cpp
More file actions
88 lines (70 loc) · 1.49 KB
/
11-27_CPP_Test.cpp
File metadata and controls
88 lines (70 loc) · 1.49 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// 12191706 김정진
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
class Shape {
public:
explicit Shape(const string& n, double w, double h) {
name = n; width = w; height = h;
}
virtual double CalculateArea() const = 0;
string getName() const{
return name;
}
~Shape() {};
protected:
string name;
double width;
double height;
};
class Rect : public Shape {
public:
explicit Rect(const string& n, double w, double h)
: Shape(n,w,h){ }
virtual double CalculateArea() const override {
return width * height;
}
~Rect() {};
};
class Triangle : public Shape {
public:
explicit Triangle(const string& n, double w, double h)
: Shape(n, w, h) { }
virtual double CalculateArea() const override {
return (width * height)/ 2;
}
~Triangle() {};
};
void swap(int& a, int& b) {
int c;
int& ref = c;
ref = a;
a = b;
b = ref;
return;
}
int main() {
ofstream Test("Test.txt", ios::out);
{
vector<Shape*>shapes{
new Rect("노트북", 40, 25),
new Triangle("토스트", 20, 12)
};
if (!Test) {
cerr << "File could not be opened" << endl;
exit(EXIT_FAILURE);
}
for (Shape* shapePtr : shapes) {
string namesave = shapePtr->getName();
double areasave = shapePtr->CalculateArea();
Test << namesave << " 의 넓이는 " << showpoint << areasave << endl;
}
}
int a = 10; int b = 20;
Test << setw(17) << "원래 a, b는 " << a << " " << b << endl;
swap(a, b);
Test << setw(17) << "바뀐 a, b는 " << a << " " << b << endl;
}